foriequal0/git-trim

Manage a man page using a smart way

majecty opened this issue ยท 7 comments

The PR #50 added a man page. We need a method to manage the man page in a smart way.

There are too many methods to create a man page. We need to research them and choose one.

@foriequal0 Can I try this issue?

Since most of the content of the man page has the same content as the help message, I'll try a solution that extracts a man page from a help message.

Let me summarize the possible options:

  1. Generate a man page from a handwritten markup file

    • Pros: easy
    • Cons:
      • There will be duplication. If we add a new command-line argument, we should update the handwritten markup file.
      • Converting tool is a new dependency. Maybe we need Ruby or Python.
  2. Generate a man page using Rust's man crate

    • Pros:
      • easy
      • We need a Rust crate dependency. It is easy to manage.
    • Cons:
      • There will be duplication. If we add a new command-line argument, we should update the handwritten markup file.
  3. Generate a man page from the help message

    3.1. Parse a help text and creates a man page

    • Pros: We can minimize information duplication.
    • Cons:
      • We need to search is there a tool for it. help2man
        seems a solution.
      • There will be hidden constraints to the help message that can be hard to manage.

    3.2 Parse the doc comments of the Args struct

    • Pros:
      • We can use the rust code.
      • Writing a proc macro will be fun.
    • Cons:
      • We need to manage to much accidental code just to create a man page.
  4. Use another CLI option parser library that generates man page automatically.

    • clap does it.
    • Pros: Simple and easy to manage
    • Cons: We need to change all CLI arg parsing code because of the man page.

It seems 4 is viable. structopt uses clap under the hood. You might be able to find a way to convert them to clap object.

A feature that generates a man page will be added in the clap's version 3 which is not available yet. Since I can get a Clap::App object from StructOpt trait, however, I'll try to generate a man page using the Clap::App object.

I've tried to use clap::App to get the arguments' data, and failed.
Clap is not exposing FlagBuilder type, AnyArg type, and etc that are required to extract argument value and help message easily.

Closed by #84