Added value hints for cli

This commit is contained in:
Nathan Fisher 2023-03-28 21:27:40 -04:00
parent efe77b97d8
commit 4b7f5afa56
2 changed files with 7 additions and 6 deletions

View File

@ -17,6 +17,8 @@ use {
},
};
static TEMPLATE: &str = "[ {prefix} ] {wide_bar}{pos:>5.cyan}/{len:5.green}{msg:>30}";
fn main() -> Result<(), Box<dyn Error>> {
let matches = cli().get_matches();
match matches.subcommand() {
@ -70,10 +72,7 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
let (sender, receiver) = mpsc::channel();
let len = creator.len();
let pb = ProgressBar::new(len as u64);
pb.set_style(
ProgressStyle::with_template("[ {prefix} ] {wide_bar}{pos:>5.cyan}/{len:5.green}{msg:>30}")
.unwrap(),
);
pb.set_style(ProgressStyle::with_template(TEMPLATE).unwrap());
pb.set_prefix("Adding files");
pb.println(format!(
"Creating package {}-{}_{}.tar.zst",
@ -85,7 +84,7 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
Message::MemberAdded(s) => {
pb.set_message(s.split('/').last().unwrap().to_string());
pb.inc(1);
},
}
Message::Success(_s) => {
pb.inc(1);
pb.finish_and_clear();
@ -103,7 +102,7 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
Ok(_) => {
println!("Package created successfully");
Ok(())
},
}
Err(e) => Err(io::Error::new(ErrorKind::Other, format!("{e:?}")).into()),
}
}

View File

@ -24,6 +24,7 @@ fn create() -> Command {
.args([
Arg::new("directory")
.help("the directory where the files are located")
.value_hint(ValueHint::DirPath)
.required(true)
.num_args(1),
Arg::new("output")
@ -37,6 +38,7 @@ fn create() -> Command {
.help("path to the package specs file in `ron` format")
.short('s')
.long("specs")
.value_hint(ValueHint::FilePath)
.conflicts_with_all(["name", "package-version", "release", "dependencies"])
.num_args(1),
Arg::new("name")