Skip to content

Commit ff813c4

Browse files
committed
moss/cli: Convert index to use clap derive structs
Signed-off-by: Rune Morling <ermo@aerynos.com>
1 parent c4df224 commit ff813c4

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

moss/src/cli/index.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@
33
// SPDX-License-Identifier: MPL-2.0
44
use std::path::PathBuf;
55

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+
}
728

829
pub use moss::client::index::Error;
930

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;
2033

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();
2736

28-
moss::client::index(&index_dir, output_dir.as_deref())?;
37+
moss::client::index(&_inputdir.unwrap(), _outputdir.as_deref())?;
2938

3039
Ok(())
3140
}

0 commit comments

Comments
 (0)