|
3 | 3 | // SPDX-License-Identifier: MPL-2.0 |
4 | 4 | use std::path::PathBuf; |
5 | 5 |
|
6 | | -use clap::{ArgMatches, Command, arg, value_parser}; |
| 6 | +use clap::Parser; // {ArgMatches, Command, arg, value_parser}; |
| 7 | + |
| 8 | +#[derive(Debug, Parser)] |
| 9 | +#[command(about = "Index a collection of .stone packages")] |
| 10 | +pub struct Command { |
| 11 | + #[arg( |
| 12 | + short, |
| 13 | + long = "inputdir", |
| 14 | + help = "The directory from which to start the index operation", |
| 15 | + default_value = ".", |
| 16 | + global = false |
| 17 | + )] |
| 18 | + pub inputdir: Option<PathBuf>, |
| 19 | + #[arg( |
| 20 | + short, |
| 21 | + long = "outputdir", |
| 22 | + help = "The directory to which to write the stone.index (defaults to {index_dir})", |
| 23 | + default_value = "{index_dir}", |
| 24 | + global = false |
| 25 | + )] |
| 26 | + pub outputdir: Option<PathBuf>, |
| 27 | +} |
7 | 28 |
|
8 | 29 | pub use moss::client::index::Error; |
9 | 30 |
|
10 | | -pub fn command() -> Command { |
11 | | - Command::new("index") |
12 | | - .visible_alias("ix") |
13 | | - .about("Index a collection of packages") |
14 | | - .arg(arg!(<INDEX_DIR> "directory of index files").value_parser(value_parser!(PathBuf))) |
15 | | - .arg( |
16 | | - arg!(-o --"output-dir" [output_dir] "directory to write the stone.index to (defaults to INDEX_DIR)") |
17 | | - .value_parser(value_parser!(PathBuf)), |
18 | | - ) |
19 | | -} |
| 31 | +pub fn handle(command: Command) -> Result<(), Error> { |
| 32 | + let Command { inputdir, outputdir } = command; |
20 | 33 |
|
21 | | -pub fn handle(args: &ArgMatches) -> Result<(), Error> { |
22 | | - let index_dir = args.get_one::<PathBuf>("INDEX_DIR").unwrap().canonicalize()?; |
23 | | - let output_dir = args |
24 | | - .get_one::<PathBuf>("output-dir") |
25 | | - .map(|dir| dir.canonicalize()) |
26 | | - .transpose()?; |
| 34 | + let _inputdir = command.inputdir.clone(); |
| 35 | + let _outputdir = command.outputdir.clone(); |
27 | 36 |
|
28 | | - moss::client::index(&index_dir, output_dir.as_deref())?; |
| 37 | + moss::client::index(&_inputdir.unwrap(), _outputdir.as_deref())?; |
29 | 38 |
|
30 | 39 | Ok(()) |
31 | 40 | } |
0 commit comments