From 4cf4e68c0d35c1482a46f870022c41a373edda74 Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Mon, 18 Oct 2021 09:38:03 +0200 Subject: [PATCH 1/4] Simplify clap derive definition --- docs/src/usage.txt | 5 +++-- src/main.rs | 47 +++++++++++++++++++++------------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/docs/src/usage.txt b/docs/src/usage.txt index 7e135624..e6776213 100644 --- a/docs/src/usage.txt +++ b/docs/src/usage.txt @@ -13,7 +13,8 @@ ARGS: OPTIONS: -l, --list List all commands in the cache -f, --render Render a specific markdown file - -o, --os Override the operating system [linux, osx, sunos, windows] + -o, --os Override the operating system [possible values: linux, osx, sunos, + windows] -L, --language Override the language -u, --update Update the local cache -c, --clear-cache Clear the local cache @@ -23,7 +24,7 @@ OPTIONS: --show-paths Show file and directory paths used by tealdeer --config-path Show config file path --seed-config Create a basic config - --color Control whether to use color [always, auto, never] + --color Control whether to use color [possible values: always, auto, never] -v, --version Print the version -h, --help Print help information diff --git a/src/main.rs b/src/main.rs index 7b74e646..07e1a2ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,70 +65,65 @@ struct Args { command: Vec, /// List all commands in the cache - #[clap(short = 'l', long = "list")] + #[clap(short, long)] list: bool, /// Render a specific markdown file - #[clap( - short = 'f', - long = "render", - value_name = "FILE", - conflicts_with = "command" - )] - render: Option, - - /// Override the operating system [linux, osx, sunos, windows] - #[clap(short = 'o', long = "os", requires = "command")] + #[clap(short = 'f', long, value_name = "FILE", conflicts_with = "command")] + render: Option, + + /// Override the operating system + #[clap(short, long, requires = "command", possible_values = &["linux", "osx", "sunos", "windows"])] os: Option, /// Override the language - #[clap(short = 'L', long = "language")] + #[clap(short = 'L', long)] language: Option, /// Update the local cache - #[clap(short = 'u', long = "update")] + #[clap(short, long)] update: bool, /// Clear the local cache - #[clap(short = 'c', long = "clear-cache")] + #[clap(short, long)] clear_cache: bool, /// Use a pager to page output - #[clap(short = 'p', long = "pager", requires = "command")] + #[clap(short, long, requires = "command")] pager: bool, /// Display the raw markdown instead of rendering it - #[clap(short = 'r', long = "--raw", requires = "command")] + #[clap(short, long, requires = "command")] raw: bool, /// Deprecated alias of `raw` - #[clap(long = "markdown", short = 'm', requires = "command", hidden = true)] + #[clap(short, long, requires = "command", hidden = true)] markdown: bool, /// Suppress informational messages - #[clap(short = 'q', long = "quiet")] + #[clap(short, long)] quiet: bool, /// Show file and directory paths used by tealdeer - #[clap(long = "show-paths")] + #[clap(long)] show_paths: bool, /// Show config file path - #[clap(long = "config-path")] + #[clap(long)] config_path: bool, /// Create a basic config - #[clap(long = "seed-config")] + #[clap(long)] seed_config: bool, - /// Control whether to use color [always, auto, never] - #[clap(long = "color", value_name = "WHEN")] + /// Control whether to use color + #[clap(long, value_name = "WHEN", possible_values = &["always", "auto", "never"])] color: Option, /// Print the version // Note: We override the version flag because clap uses `-V` by default, // while TLDR specification requires `-v` to be used. - #[clap(short = 'v', long = "version")] + #[clap(short, long)] version: bool, } @@ -406,8 +401,8 @@ fn main() { }; // If a local file was passed in, render it and exit - if let Some(ref file) = args.render { - let path = PageLookupResult::with_page(PathBuf::from(file)); + if let Some(file) = args.render { + let path = PageLookupResult::with_page(file); if let Err(msg) = print_page(&path, args.raw, &config) { eprintln!("{}", msg); process::exit(1); From 7200681a6cedae5d2d2d17b9b2a59af804c45e8d Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Mon, 18 Oct 2021 10:30:13 +0200 Subject: [PATCH 2/4] Revert auto-generated flags --- src/main.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 07e1a2ca..bee6ebcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,65 +65,70 @@ struct Args { command: Vec, /// List all commands in the cache - #[clap(short, long)] + #[clap(short = 'l', long = "list")] list: bool, /// Render a specific markdown file - #[clap(short = 'f', long, value_name = "FILE", conflicts_with = "command")] + #[clap( + short = 'f', + long = "render", + value_name = "FILE", + conflicts_with = "command" + )] render: Option, /// Override the operating system - #[clap(short, long, requires = "command", possible_values = &["linux", "osx", "sunos", "windows"])] + #[clap(short = 'o', long = "os", requires = "command", possible_values = &["linux", "osx", "sunos", "windows"])] os: Option, /// Override the language - #[clap(short = 'L', long)] + #[clap(short = 'L', long = "language")] language: Option, /// Update the local cache - #[clap(short, long)] + #[clap(short = 'u', long = "update")] update: bool, /// Clear the local cache - #[clap(short, long)] + #[clap(short = 'c', long = "clear-cache")] clear_cache: bool, /// Use a pager to page output - #[clap(short, long, requires = "command")] + #[clap(short = 'p', long = "pager", requires = "command")] pager: bool, /// Display the raw markdown instead of rendering it - #[clap(short, long, requires = "command")] + #[clap(short = 'r', long = "--raw", requires = "command")] raw: bool, /// Deprecated alias of `raw` - #[clap(short, long, requires = "command", hidden = true)] + #[clap(long = "markdown", short = 'm', requires = "command", hidden = true)] markdown: bool, /// Suppress informational messages - #[clap(short, long)] + #[clap(short = 'q', long = "quiet")] quiet: bool, /// Show file and directory paths used by tealdeer - #[clap(long)] + #[clap(long = "show-paths")] show_paths: bool, /// Show config file path - #[clap(long)] + #[clap(long = "config-path")] config_path: bool, /// Create a basic config - #[clap(long)] + #[clap(long = "seed-config")] seed_config: bool, /// Control whether to use color - #[clap(long, value_name = "WHEN", possible_values = &["always", "auto", "never"])] + #[clap(long = "color", value_name = "WHEN", possible_values = &["always", "auto", "never"])] color: Option, /// Print the version // Note: We override the version flag because clap uses `-V` by default, // while TLDR specification requires `-v` to be used. - #[clap(short, long)] + #[clap(short = 'v', long = "version")] version: bool, } From 042c6caf8f4d316d3c9647946665b4c70e2047c3 Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Wed, 20 Oct 2021 16:04:56 +0200 Subject: [PATCH 3/4] Reformat clap attributes --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index bee6ebcb..5b60c142 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,12 @@ struct Args { render: Option, /// Override the operating system - #[clap(short = 'o', long = "os", requires = "command", possible_values = &["linux", "osx", "sunos", "windows"])] + #[clap( + short = 'o', + long = "os", + requires = "command", + possible_values = ["linux", "osx", "sunos", "windows"] + )] os: Option, /// Override the language @@ -122,7 +127,11 @@ struct Args { seed_config: bool, /// Control whether to use color - #[clap(long = "color", value_name = "WHEN", possible_values = &["always", "auto", "never"])] + #[clap( + long = "color", + value_name = "WHEN", + possible_values = ["always", "auto", "never"] + )] color: Option, /// Print the version From fe120e9a2bdd6db751851e91cfea25930f3dc062 Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Sun, 24 Oct 2021 23:08:33 +0200 Subject: [PATCH 4/4] Add note about explicit flag names --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 5b60c142..0895fd71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,8 @@ const ARCHIVE_URL: &str = "https://tldr.sh/assets/tldr.zip"; #[cfg(not(target_os = "windows"))] const PAGER_COMMAND: &str = "less -R"; +// Note: flag names are specified explicitly in clap attributes +// to improve readability and allow contributors to grep names like "clear-cache" #[derive(Parser, Debug)] #[clap(about = "A fast TLDR client", author, version)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]