Skip to content

Commit

Permalink
feat: compgen export argc__cmd_fn (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Aug 13, 2023
1 parent e3cbf76 commit 7a02939
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ impl<'a, 'b> Matcher<'a, 'b> {
self.dashes.iter().map(|v| v.to_string()).collect(),
));
}
let last_cmd = self.cmds[self.cmds.len() - 1].1;
if let Some(name) = &last_cmd.name {
output.push(ArgcValue::Single("_cmd_fn".into(), name.to_string()));
}
output
}

Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/integration__param_fn__case1.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OUTPUT
argc_cc=''
argc__args=( prog cmda --cc '' )
argc__index=1
argc__cmd_fn=cmda
argc__positionals=( )
_choice_fn;exit;

Expand All @@ -30,6 +31,7 @@ argc_oa=oa
argc_cc=''
argc__args=( prog cmda -a --oa oa --cc '' )
argc__index=1
argc__cmd_fn=cmda
argc__positionals=( )
_choice_fn;exit;

Expand Down
5 changes: 5 additions & 0 deletions tests/snapshots/integration__param_fn__case2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OUTPUT
argc_val=( '' )
argc__args=( prog cmdl '' )
argc__index=1
argc__cmd_fn=cmdl
argc__positionals=( '' )
_choice_fn '';exit;

Expand All @@ -28,6 +29,7 @@ OUTPUT
argc_val=( v1 )
argc__args=( prog cmdl v1 )
argc__index=1
argc__cmd_fn=cmdl
argc__positionals=( v1 )
_choice_fn v1;exit;

Expand All @@ -38,6 +40,7 @@ OUTPUT
argc_val=( v1 '' )
argc__args=( prog cmdl v1 '' )
argc__index=1
argc__cmd_fn=cmdl
argc__positionals=( v1 '' )
_choice_fn v1 '';exit;

Expand All @@ -48,6 +51,7 @@ OUTPUT
argc_val=( v1 v2 )
argc__args=( prog cmdl v1 v2 )
argc__index=1
argc__cmd_fn=cmdl
argc__positionals=( v1 v2 )
_choice_fn v1 v2;exit;

Expand All @@ -58,6 +62,7 @@ OUTPUT
argc_val=( v1 v2 '' )
argc__args=( prog cmdl v1 v2 '' )
argc__index=1
argc__cmd_fn=cmdl
argc__positionals=( v1 v2 '' )
_choice_fn v1 v2 '';exit;

Expand Down

0 comments on commit 7a02939

Please sign in to comment.