mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-09 09:49:10 +02:00
Simplify clap derive definition (#221)
- Use `possible_values` - Change `render` field type to `PathBuf` - Add comment about explicit field names
This commit is contained in:
parent
cea3bcdc3f
commit
3beed4ad48
2 changed files with 21 additions and 9 deletions
|
|
@ -13,7 +13,8 @@ ARGS:
|
|||
OPTIONS:
|
||||
-l, --list List all commands in the cache
|
||||
-f, --render <FILE> Render a specific markdown file
|
||||
-o, --os <OS> Override the operating system [linux, osx, sunos, windows]
|
||||
-o, --os <OS> Override the operating system [possible values: linux, osx, sunos,
|
||||
windows]
|
||||
-L, --language <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 <WHEN> Control whether to use color [always, auto, never]
|
||||
--color <WHEN> Control whether to use color [possible values: always, auto, never]
|
||||
-v, --version Print the version
|
||||
-h, --help Print help information
|
||||
|
||||
|
|
|
|||
25
src/main.rs
25
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)]
|
||||
|
|
@ -75,10 +77,15 @@ struct Args {
|
|||
value_name = "FILE",
|
||||
conflicts_with = "command"
|
||||
)]
|
||||
render: Option<String>,
|
||||
render: Option<PathBuf>,
|
||||
|
||||
/// Override the operating system [linux, osx, sunos, windows]
|
||||
#[clap(short = 'o', long = "os", requires = "command")]
|
||||
/// Override the operating system
|
||||
#[clap(
|
||||
short = 'o',
|
||||
long = "os",
|
||||
requires = "command",
|
||||
possible_values = ["linux", "osx", "sunos", "windows"]
|
||||
)]
|
||||
os: Option<OsType>,
|
||||
|
||||
/// Override the language
|
||||
|
|
@ -121,8 +128,12 @@ struct Args {
|
|||
#[clap(long = "seed-config")]
|
||||
seed_config: bool,
|
||||
|
||||
/// Control whether to use color [always, auto, never]
|
||||
#[clap(long = "color", value_name = "WHEN")]
|
||||
/// Control whether to use color
|
||||
#[clap(
|
||||
long = "color",
|
||||
value_name = "WHEN",
|
||||
possible_values = ["always", "auto", "never"]
|
||||
)]
|
||||
color: Option<ColorOptions>,
|
||||
|
||||
/// Print the version
|
||||
|
|
@ -406,8 +417,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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue