Skip to content

Commit

Permalink
feat: support --argc-shell-path (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Feb 15, 2024
1 parent fbe3e17 commit 080f746
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Here are some value notation that will affect the shell completion.

## Build

Generate a single standalone bash script without argc dependency.
Build a single standalone bash script without argc dependency.

```
argc --argc-build <SCRIPT> [OUTPATH]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/argc/completions/completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# @option --argc-eval~ <FILE> <ARGS> Use `eval "$(argc --argc-eval "$0" "$@")"`
# @option --argc-create~ <TASKS> Create a boilerplate argcfile
# @option --argc-build <FILE> [OUTPATH] Build standalone bash script without depending on argc
# @option --argc-build <FILE> [OUTPATH] Build bash script without argc dependency
# @option --argc-completions~[`_choice_completion`] <SHELL> <CMDS> Generate shell completion scripts
# @option --argc-compgen~[`_choice_compgen`] <SHELL> <FILE> <ARGS> Dynamically generating completion candidates
# @option --argc-export <FILE> Export command line definitions as json
# @option --argc-parallel~ <FILE> <ARGS> Execute argc functions in parallel
# @flag --argc-script-path Print current argcfile path
# @flag --argc-shell-path Print current shell path
# @flag --argc-help Print help information
# @flag --argc-version Print version information

Expand Down
9 changes: 7 additions & 2 deletions src/bin/argc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ fn run() -> Result<i32> {
"--argc-script-path" => {
let (_, script_file) =
get_script_path(true).ok_or_else(|| anyhow!("Argcfile not found."))?;
print!("{}", script_file.display());
println!("{}", script_file.display());
}
"--argc-shell-path" => {
let shell = get_shell_path()?;
println!("{}", shell.display());
}
"--argc-help" => {
println!("{}", get_argc_help())
Expand Down Expand Up @@ -252,12 +256,13 @@ fn get_argc_help() -> String {
USAGE:
argc --argc-eval <SCRIPT> [ARGS]... Use `eval "$(argc --argc-eval "$0" "$@")"`
argc --argc-create [TASKS]... Create a boilerplate argcfile
argc --argc-build <SCRIPT> [OUTPATH] Build standalone bash script without depending on argc
argc --argc-build <SCRIPT> [OUTPATH] Build bash script without argc dependency
argc --argc-completions <SHELL> [CMDS]... Generate shell completion scripts
argc --argc-compgen <SHELL> <SCRIPT> <ARGS>... Dynamically generating completion candidates
argc --argc-export <SCRIPT> Export command line definitions as json
argc --argc-parallel <SCRIPT> <ARGS>... Execute argc functions in parallel
argc --argc-script-path Print current argcfile path
argc --argc-shell-path Print current shell path
argc --argc-help Print help information
argc --argc-version Print version information
"###
Expand Down
4 changes: 2 additions & 2 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl<'a, 'b> Matcher<'a, 'b> {
}
match *name {
Some(name) => {
missing_flag_options.remove(name);
missing_flag_options.swap_remove(name);
flag_option_map.entry(name).or_insert(vec![]).push(i);
}
None => return Some(MatchError::UnknownArgument(level, key.to_string())),
Expand Down Expand Up @@ -898,7 +898,7 @@ pub(crate) type CompItem = (String, String, bool, CompColor);
fn find_subcommand<'a>(
cmd: &'a Command,
arg: &str,
positional_args: &Vec<&str>,
positional_args: &[&str],
) -> Option<&'a Command> {
cmd.find_subcommand(arg).and_then(|v| {
if positional_args.is_empty() {
Expand Down
10 changes: 10 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ fn script_path() {
.success();
}

#[test]
fn shell_path() {
Command::cargo_bin("argc")
.unwrap()
.arg("--argc-shell-path")
.assert()
.stdout(predicates::str::contains("bash"))
.success();
}

#[test]
fn run_argcfile() {
let tmpdir = tmpdir_argcfiles();
Expand Down

0 comments on commit 080f746

Please sign in to comment.