feat: add rest argument completion

This commit is contained in:
nibon7 2022-11-02 11:58:54 +08:00
parent c19fc425d0
commit c6fe49aba5
No known key found for this signature in database
GPG key ID: 281CE465D8EEC03B
2 changed files with 10 additions and 5 deletions

View file

@ -17,7 +17,7 @@
use clap::{
builder::{PossibleValue, StyledStr},
Arg, Command, Id,
Arg, ArgAction, Command, Id,
};
use clap_complete::Generator;
@ -137,10 +137,15 @@ impl ToString for Argument<'_, '_> {
let mut s = String::new();
if self.is_positional() {
s.push_str(format!(" {}", self.get_id()).as_str());
// rest arguments
if matches!(self.arg.get_action(), ArgAction::Append) {
s.push_str(format!(" ...{}", self.get_id()).as_str());
} else {
s.push_str(format!(" {}", self.get_id()).as_str());
if !self.is_required_set() {
s.push('?');
if !self.is_required_set() {
s.push('?');
}
}
self.append_type_and_help(&mut s);

View file

@ -23,7 +23,7 @@ module completions {
# tests other things
export extern "my-app some_cmd" [
--config: string # the other case to test
path?: string
...path: string
--version(-V) # Print version information
]