|
1 | 1 | // SPDX-FileCopyrightText: © 2021 Caleb Maclennan <[email protected]>
|
2 | 2 | // SPDX-License-Identifier: GPL-3.0-only
|
3 | 3 |
|
4 |
| -use clap::CommandFactory; |
| 4 | +use clap::{CommandFactory, Parser}; |
5 | 5 |
|
6 | 6 | use git_warp_time::cli::Cli;
|
7 | 7 | use git_warp_time::FileSet;
|
@@ -40,31 +40,33 @@ type Result<T, E = Error> = std::result::Result<T, E>;
|
40 | 40 |
|
41 | 41 | fn main() -> Result<()> {
|
42 | 42 | 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(); |
45 | 46 | let positionals = matches.get_many::<String>("paths");
|
46 | 47 | let repo = get_repo().context(NoRepositorySnafu)?;
|
47 | 48 | let mut opts = git_warp_time::Options::new()
|
48 | 49 | .dirty(matches.get_flag("dirty"))
|
49 | 50 | .ignored(matches.get_flag("ignored"))
|
50 | 51 | .ignore_older(matches.get_flag("ignore_older"))
|
51 | 52 | .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); |
62 | 66 | }
|
63 |
| - let path = resolve_repo_path(&repo, path).context(CouldNotAccessRepositorySnafu)?; |
64 |
| - paths.insert(path); |
| 67 | + opts = opts.paths(Some(paths)); |
65 | 68 | }
|
66 |
| - opts = opts.paths(Some(paths)); |
| 69 | + reset_mtimes(repo, opts).context(UnableToResetMTimeSnafu)?; |
67 | 70 | }
|
68 |
| - reset_mtimes(repo, opts).context(UnableToResetMTimeSnafu)?; |
69 | 71 | Ok(())
|
70 | 72 | }
|
0 commit comments