Use split_once instead of split().nth(1)

This commit is contained in:
Felix Schütt
2022-10-13 18:49:39 +02:00
parent 600dc2dfc7
commit a1548ec7ff
2 changed files with 10 additions and 19 deletions

View File

@@ -478,18 +478,14 @@ fn print_packages() -> Result<(), anyhow::Error> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let empty_table = rows.is_empty(); let empty_table = rows.is_empty();
let mut table = Table::init(rows);
table.set_titles(row!["Registry", "Package", "Version", "Commands"]);
table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_format(*format::consts::FORMAT_NO_COLSEP);
if empty_table { if empty_table {
println!("--------------------------------------"); table.add_empty_row();
println!("Registry Package Version Commands ");
println!("======================================");
println!();
} else {
let mut table = Table::init(rows);
table.set_titles(row!["Registry", "Package", "Version", "Commands"]);
table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_format(*format::consts::FORMAT_NO_COLSEP);
let _ = table.printstd();
} }
let _ = table.printstd();
Ok(()) Ok(())
} }

View File

@@ -442,14 +442,9 @@ pub fn get_package_local_dir(
"package name has to be in the format namespace/package: {name:?}" "package name has to be in the format namespace/package: {name:?}"
)); ));
} }
let namespace = name let (namespace, name) = name
.split('/') .split_once('/')
.next() .ok_or(format!("missing namespace / name for {name:?}"))?;
.ok_or(format!("missing namespace for {name:?}"))?;
let name = name
.split('/')
.nth(1)
.ok_or(format!("missing name for {name:?}"))?;
let install_dir = let install_dir =
get_global_install_dir(registry_host).ok_or(format!("no install dir for {name:?}"))?; get_global_install_dir(registry_host).ok_or(format!("no install dir for {name:?}"))?;
Ok(install_dir.join(namespace).join(name).join(version)) Ok(install_dir.join(namespace).join(name).join(version))