Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify clap derive definition #221

Merged
merged 4 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
23 changes: 16 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,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
Expand Down Expand Up @@ -121,8 +126,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
Expand Down Expand Up @@ -406,8 +415,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);
Expand Down