Skip to content

Commit

Permalink
Merge pull request #3642 from mulkieran/specify-types-in-parser
Browse files Browse the repository at this point in the history
Specify PathBuf type for blockdevs in parser
  • Loading branch information
mulkieran authored Jul 23, 2024
2 parents 855ae23 + 5648d20 commit 96d94c4
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/bin/stratis-min/stratis-min.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{error::Error, path::PathBuf};

use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command};
use clap::{Arg, ArgAction, ArgGroup, Command};
use serde_json::{json, Map, Value};

use stratisd::{
Expand Down Expand Up @@ -56,6 +56,7 @@ fn parse_args() -> Command {
.arg(
Arg::new("blockdevs")
.action(ArgAction::Append)
.value_parser(clap::value_parser!(PathBuf))
.required(true),
)
.arg(Arg::new("key_desc").long("key-desc").num_args(1))
Expand Down Expand Up @@ -86,6 +87,7 @@ fn parse_args() -> Command {
.arg(
Arg::new("blockdevs")
.action(ArgAction::Append)
.value_parser(clap::value_parser!(PathBuf))
.required(true),
),
Command::new("rename")
Expand All @@ -96,13 +98,15 @@ fn parse_args() -> Command {
.arg(
Arg::new("blockdevs")
.action(ArgAction::Append)
.value_parser(clap::value_parser!(PathBuf))
.required(true),
),
Command::new("add-cache")
.arg(Arg::new("name").required(true))
.arg(
Arg::new("blockdevs")
.action(ArgAction::Append)
.value_parser(clap::value_parser!(PathBuf))
.required(true),
),
Command::new("destroy").arg(Arg::new("name").required(true)),
Expand Down Expand Up @@ -195,13 +199,6 @@ fn parse_args() -> Command {
])
}

fn get_paths_from_args(args: &ArgMatches) -> Vec<PathBuf> {
args.get_many::<String>("blockdevs")
.expect("required")
.map(PathBuf::from)
.collect::<Vec<_>>()
}

fn main() -> Result<(), String> {
fn main_box() -> Result<(), Box<dyn Error>> {
let cmd = parse_args();
Expand Down Expand Up @@ -261,7 +258,6 @@ fn main() -> Result<(), String> {
pool::pool_stop(id)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("create") {
let paths = get_paths_from_args(args);
let key_description = match args.get_one::<String>("key_desc").map(|s| s.to_owned())
{
Some(string) => Some(KeyDescription::try_from(string)?),
Expand Down Expand Up @@ -294,18 +290,23 @@ fn main() -> Result<(), String> {
};
pool::pool_create(
args.get_one::<String>("name").expect("required").to_owned(),
paths,
args.get_many::<PathBuf>("blockdevs")
.expect("required")
.cloned()
.collect::<Vec<_>>(),
EncryptionInfo::from_options((key_description, clevis_info)),
)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("destroy") {
pool::pool_destroy(args.get_one::<String>("name").expect("required").to_owned())?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("init-cache") {
let paths = get_paths_from_args(args);
pool::pool_init_cache(
args.get_one::<String>("name").expect("required").to_owned(),
paths,
args.get_many::<PathBuf>("blockdevs")
.expect("required")
.cloned()
.collect::<Vec<_>>(),
)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("rename") {
Expand All @@ -319,17 +320,21 @@ fn main() -> Result<(), String> {
)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("add-data") {
let paths = get_paths_from_args(args);
pool::pool_add_data(
args.get_one::<String>("name").expect("required").to_owned(),
paths,
args.get_many::<PathBuf>("blockdevs")
.expect("required")
.cloned()
.collect::<Vec<_>>(),
)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("add-cache") {
let paths = get_paths_from_args(args);
pool::pool_add_cache(
args.get_one::<String>("name").expect("required").to_owned(),
paths,
args.get_many::<PathBuf>("blockdevs")
.expect("required")
.cloned()
.collect::<Vec<_>>(),
)?;
Ok(())
} else if let Some(args) = subcommand.subcommand_matches("is-encrypted") {
Expand Down

0 comments on commit 96d94c4

Please sign in to comment.