Skip to content

Commit

Permalink
feat: Rename bin argument to executable
Browse files Browse the repository at this point in the history
  • Loading branch information
juanibiapina committed May 22, 2024
1 parent ad53e0f commit ca43518
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ The entry point in `bin/awesomecli` can then be:
```
#!/usr/bin/env bash
sub --name awesomecli --bin "${BASH_SOURCE[0]}" --relative ".." -- "$@"
sub --name awesomecli --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@"
```

The `--name` argument tells `sub` the name of the CLI. This is used when
printing help information.

The `--bin` argument tells `sub` where the binary entry point is located.
The `--executable` argument tells `sub` where the CLI entry point is located.
Usually this will just be `${BASH_SOURCE[0]}`. The `--relative` argument tells
`sub` how to find the root of the CLI starting from the binary entry point.
`sub` how to find the root of the CLI starting from the CLI entry point.
These two are separate arguments for cross platform compatibility. `sub` will
canonalize the bin path before merging with the relative path and then canonalize
again.
Expand Down
2 changes: 1 addition & 1 deletion integration/fixtures/commands/bin/main
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

$SUB_BIN --color never --name main --bin "${BASH_SOURCE[0]}" --relative ".." -- "$@"
$SUB_BIN --color never --name main --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@"
2 changes: 1 addition & 1 deletion integration/fixtures/completions/bin/main
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

$SUB_BIN --color never --name main --bin "${BASH_SOURCE[0]}" --relative ".." -- "$@"
$SUB_BIN --color never --name main --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@"
2 changes: 1 addition & 1 deletion integration/fixtures/project/bin/main
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

$SUB_BIN --color never --name main --bin "${BASH_SOURCE[0]}" --relative ".." -- "$@"
$SUB_BIN --color never --name main --executable "${BASH_SOURCE[0]}" --relative ".." -- "$@"
4 changes: 2 additions & 2 deletions integration/sub.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ PROJECT_DIR="$SUB_TEST_DIR/project"
assert_output "main: libexec directory not found in root"
}

@test "sub: reject --bin and --absolute given together" {
@test "sub: reject --executable and --absolute given together" {
fixture "project"

run $SUB_BIN --name main --bin "$PROJECT_DIR" --absolute "$PROJECT_DIR"
run $SUB_BIN --name main --executable "$PROJECT_DIR" --absolute "$PROJECT_DIR"
assert_failure
}

Expand Down
24 changes: 12 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ fn init_sub_cli() -> Command {
Arg::new("name")
.long("name")
.required(true)
.help("Sets the CLI name. Used in help and error messages."),
.help("Sets the CLI name - used in help and error messages"),
)
.arg(
Arg::new("bin")
.long("bin")
Arg::new("executable")
.long("executable")
.value_parser(value_parser!(PathBuf))
.help("Sets the path of the CLI binary. Only use in combination with --relative."),
.help("Sets the path of the CLI executable; only use in combination with --relative"),
)
.arg(
Arg::new("relative")
.long("relative")
.value_parser(value_parser!(PathBuf))
.help("Sets how to find the root directory based on the location of the bin. Only use in combination with --bin."),
.help("Sets how to find the root directory based on the location of the executable; Only use in combination with --executable"),
)
.arg(
Arg::new("absolute")
Expand All @@ -197,8 +197,8 @@ fn init_sub_cli() -> Command {
.help("Validate that the CLI is correctly configured"),
)
.group(
ArgGroup::new("bin_and_relative")
.args(["bin", "relative"])
ArgGroup::new("executable_and_relative")
.args(["executable", "relative"])
.multiple(true)
.conflicts_with("absolute"),
)
Expand Down Expand Up @@ -305,18 +305,18 @@ fn parse_sub_cli_args() -> SubCliArgs {
Some(path) => path.clone(),
None => {
let mut path = args
.get_one::<PathBuf>("bin")
.expect("Either `bin` or `absolute` is required")
.get_one::<PathBuf>("executable")
.expect("Either `executable` or `absolute` is required")
.canonicalize()
.expect("Invalid `bin` path")
.expect("Invalid `executable` path")
.clone();

path.pop(); // remove bin name
path.pop(); // remove executable name

let relative = args.get_one::<PathBuf>("relative").expect("Missing `relative` argument");
path.push(relative);

path.canonicalize().expect("Invalid `bin` or `relative` arguments")
path.canonicalize().expect("Invalid `executable` or `relative` arguments")
}
},
}
Expand Down

0 comments on commit ca43518

Please sign in to comment.