Skip to content

Commit c83ede8

Browse files
committed
fixup! feat(cli): Enable dynamic completions
1 parent 7573a13 commit c83ede8

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [unreleased]
2+
3+
### Features
4+
5+
- *(cli)* Enable dynamic completions
6+
17
## [0.8.3] - 2024-07-22
28

39
### Bug Fixes

src/bin/git-warp-time.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: © 2021 Caleb Maclennan <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4-
use clap::CommandFactory;
4+
use clap::{CommandFactory, Parser};
55

66
use git_warp_time::cli::Cli;
77
use git_warp_time::FileSet;
@@ -40,31 +40,33 @@ type Result<T, E = Error> = std::result::Result<T, E>;
4040

4141
fn main() -> Result<()> {
4242
let version = option_env!("VERGEN_GIT_DESCRIBE").unwrap_or_else(|| env!("CARGO_PKG_VERSION"));
43-
let mut app = Cli::command().version(version);
44-
let matches = app.clone().get_matches();
43+
let app = Cli::command().version(version);
44+
let cli = Cli::parse();
45+
let matches = app.get_matches();
4546
let positionals = matches.get_many::<String>("paths");
4647
let repo = get_repo().context(NoRepositorySnafu)?;
4748
let mut opts = git_warp_time::Options::new()
4849
.dirty(matches.get_flag("dirty"))
4950
.ignored(matches.get_flag("ignored"))
5051
.ignore_older(matches.get_flag("ignore_older"))
5152
.verbose(!matches.get_flag("quiet"));
52-
if let Some(completions) =
53-
matches.get_one::<clap_complete::dynamic::CompleteCommand>("complete")
54-
{
55-
completions.complete(&mut app);
56-
}
57-
if matches.contains_id("paths") {
58-
let mut paths: FileSet = FileSet::new();
59-
for path in positionals.context(UnableToFormPathSnafu)? {
60-
if !Path::new(path).exists() {
61-
return PathNotFoundSnafu { path: path.clone() }.fail();
53+
//if let Some(completions) =
54+
// matches.get_one::<clap_complete::dynamic::CompleteCommand>("complete")
55+
if let Some(completions) = cli.complete {
56+
completions.complete(&mut Cli::command());
57+
} else {
58+
if matches.contains_id("paths") {
59+
let mut paths: FileSet = FileSet::new();
60+
for path in positionals.context(UnableToFormPathSnafu)? {
61+
if !Path::new(path).exists() {
62+
return PathNotFoundSnafu { path: path.clone() }.fail();
63+
}
64+
let path = resolve_repo_path(&repo, path).context(CouldNotAccessRepositorySnafu)?;
65+
paths.insert(path);
6266
}
63-
let path = resolve_repo_path(&repo, path).context(CouldNotAccessRepositorySnafu)?;
64-
paths.insert(path);
67+
opts = opts.paths(Some(paths));
6568
}
66-
opts = opts.paths(Some(paths));
69+
reset_mtimes(repo, opts).context(UnableToResetMTimeSnafu)?;
6770
}
68-
reset_mtimes(repo, opts).context(UnableToResetMTimeSnafu)?;
6971
Ok(())
7072
}

src/cli.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use clap_complete::dynamic::{ArgValueCompleter, CompleteCommand, CompletionCandi
1111
pub struct Cli {
1212
/// generate completions
1313
#[command(subcommand)]
14-
complete: Option<CompleteCommand>,
14+
pub complete: Option<CompleteCommand>,
1515

1616
/// Include files tracked by Git but modifications in the working tee
1717
#[clap(short, long)]
@@ -29,14 +29,11 @@ pub struct Cli {
2929
#[clap(short, long)]
3030
pub quiet: bool,
3131

32-
/// Test
32+
/// Optional list of paths to operate on instead of default which is all files tracked by Git
33+
//#[clap(value_hint = clap::ValueHint::FilePath)]
3334
#[clap(add = ArgValueCompleter::new(|| { vec![
3435
CompletionCandidate::new("foo"),
3536
CompletionCandidate::new("bar"),
3637
CompletionCandidate::new("baz")] }))]
37-
pub bag: String,
38-
39-
/// Optional list of paths to operate on instead of default which is all files tracked by Git
40-
#[clap(value_hint = clap::ValueHint::FilePath)]
4138
pub paths: Vec<String>,
4239
}

0 commit comments

Comments
 (0)