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

View File

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