Skip to content

Commit

Permalink
feat: Make some args global
Browse files Browse the repository at this point in the history
Often when using the CLI, I'll get the argument order wrong:

	```
	# 1. Global arg after subcommand
	limmat get --run --config ~/limmat.toml checkpatch HEAD
	# 2. Subcommand arg before subcommand
	limmat --run get checkpatch HEAD
	```

This produces errors that are IMO rather confusing:

	```
	error: unexpected argument '--config' found

	  tip: to pass '--config' as a value, use '-- --config'
	```

The error message could be improved (e.g. it could say `there is a
global --config argument, did you mean to pass it before the get
subcommand?`), but also there is no risk of ambiguity so in both cases
the app could just _accept_ the incorrect order.

This solves case 1. Case 2 seems like it could be more annoying to
implement and less likely to actually help (I doubt I've actually ever
made that mistake).
  • Loading branch information
bjackman committed Dec 11, 2024
1 parent 6aee149 commit 1ec0d5d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ mod test_utils;
struct Args {
// TODO: Don't require valid utf-8 strings here, OsStrings shoud be fine. But
// https://stackoverflow.com/questions/76341332/clap-default-value-for-pathbuf
#[arg(short, long, default_value_t = {".".to_string()})]
#[arg(short, long, default_value_t = {".".to_string()}, global = true)]
repo: String,
/// Path to TOML config file. Default is $LIMMAT_CONFIG if non-empty,
/// or ./limmat.toml if it exists, or ./.limmat.toml if it exists
#[arg(short, long)]
#[arg(short, long, global = true)]
config: Option<PathBuf>,
/// Directory where results will be stored.
#[arg(long, default_value_t = default_result_db())]
#[arg(long, default_value_t = default_result_db(), global = true)]
result_db: DisplayablePathBuf,
/// Filename prefix for temporary worktrees.
#[arg(long, default_value_t = {"limmat-worktree".to_string()})]
#[arg(long, default_value_t = {"limmat-worktree".to_string()}, global = true)]
worktree_prefix: String,
/// Directory (must exist) to create temporary worktrees in.
#[arg(long, default_value_t = {env::temp_dir().to_string_lossy().into_owned()})]
#[arg(long, default_value_t = {env::temp_dir().to_string_lossy().into_owned()}, global = true)]
worktree_dir: String,
#[command(subcommand)]
command: Command,
Expand Down

0 comments on commit 1ec0d5d

Please sign in to comment.