nickgerace / gfold

CLI tool to help keep track of your Git repositories, written in Rust
https://crates.io/crates/gfold
Apache License 2.0
309 stars 20 forks source link

Refactor gfold CLI #262

Open uncenter opened 3 days ago

uncenter commented 3 days ago

This PR refactors some of the CLI related logic. Uses Clap's ValueEnum instead of manually handling the enums as strings as throwing errors and all that - this makes the code more readable, and improves the help text.

Before:

Options:
  -c, --color-mode <COLOR_MODE>      specify color mode (options: ["always", "compatibility", "never"])
  -d, --display-mode <DISPLAY_MODE>  specify display format (options: ["standard", "standard-alphabetical", "json", "classic", "default"])
      --dry-run                      display finalized config options and exit (merged options from an optional config file and command line arguments)
  -i, --ignore-config-file           ignore config file settings
  -h, --help                         Print help
  -V, --version                      Print version

After:

Options:
  -c, --color-mode <COLOR_MODE>
          Possible values:
          - always:        Attempt to display colors as intended (default behavior)
          - compatibility: Display colors using widely-compatible methods at the potential expense of colors being displayed as intended
          - never:         Never display colors

  -d, --display-mode <DISPLAY_MODE>
          Possible values:
          - classic:               Informs the caller to display results in the classic format
          - json:                  Informs the caller to display results in JSON format
          - standard:              Informs the caller to display results in the standard (default) format. All results are sorted alphabetically and then sorted by status
          - standard-alphabetical: Informs the caller to display results in the standard (default) format with a twist: all results are solely sorted alphabetically (i.e. no additional sort by status)

      --dry-run
          display finalized config options and exit (merged options from an optional config file and command line arguments)

  -i, --ignore-config-file
          ignore config file settings

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

We could possibly improve this a little bit further by using #[clap(default...)] (https://docs.rs/clap/latest/clap/_derive/index.html#arg-attributes) and have Clap fancily format the ValueEnum options into showing the defaults, but that gets complicated with the config file. Maybe another time :D


This PR also removes multiple instances of match on boolean values, replacing them with if, and resolves several other Clippy suggestions/fixes.