Skip to content

Commit bb6493e

Browse files
committed
feat(complete): Offer - as a path option
1 parent 27b348d commit bb6493e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clap_complete/src/engine/custom.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ where
167167
pub struct PathCompleter {
168168
current_dir: Option<std::path::PathBuf>,
169169
filter: Option<Box<dyn Fn(&std::path::Path) -> bool + Send + Sync>>,
170+
stdio: bool,
170171
}
171172

172173
impl PathCompleter {
@@ -175,6 +176,7 @@ impl PathCompleter {
175176
Self {
176177
filter: None,
177178
current_dir: None,
179+
stdio: false,
178180
}
179181
}
180182

@@ -188,6 +190,12 @@ impl PathCompleter {
188190
Self::any().filter(|p| p.is_dir())
189191
}
190192

193+
/// Include stdio (`-`)
194+
pub fn stdio(mut self) -> Self {
195+
self.stdio = true;
196+
self
197+
}
198+
191199
/// Select which paths should be completed
192200
pub fn filter(
193201
mut self,
@@ -218,7 +226,11 @@ impl ValueCompleter for PathCompleter {
218226
current_dir_actual = std::env::current_dir().ok();
219227
current_dir_actual.as_deref()
220228
});
221-
complete_path(current, current_dir, filter)
229+
let mut candidates = complete_path(current, current_dir, filter);
230+
if self.stdio && current.is_empty() {
231+
candidates.push(CompletionCandidate::new("-").help(Some("stdio".into())));
232+
}
233+
candidates
222234
}
223235
}
224236

clap_complete/tests/testsuite/engine.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ fn suggest_value_path_file() {
592592
.long("input")
593593
.short('i')
594594
.add(ArgValueCompleter::new(
595-
PathCompleter::file().current_dir(testdir_path.to_owned()),
595+
PathCompleter::file()
596+
.stdio()
597+
.current_dir(testdir_path.to_owned()),
596598
)),
597599
)
598600
.args_conflicts_with_subcommands(true);
@@ -604,6 +606,7 @@ a_file
604606
b_file
605607
c_dir/
606608
d_dir/
609+
- stdio
607610
"#]],
608611
);
609612

0 commit comments

Comments
 (0)