feat(solana-install): subcommand to list installed versions (#32823)

This commit is contained in:
Jimii 2023-08-18 22:58:17 +03:00 committed by GitHub
parent f86b6edc4d
commit 285e52bd1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -1283,3 +1283,35 @@ pub fn run(
}
}
}
pub fn list(config_file: &str) -> Result<(), String> {
let config = Config::load(config_file)?;
let entries = fs::read_dir(&config.releases_dir).map_err(|err| {
format!(
"Failed to read install directory, \
double check that your configuration file is correct: {err}"
)
})?;
for entry in entries {
match entry {
Ok(entry) => {
let dir_name = entry.file_name();
let current_version =
load_release_version(&config.active_release_dir().join("version.yml"))?.channel;
let current = if current_version.contains(dir_name.to_string_lossy().as_ref()) {
" (current)"
} else {
""
};
println!("{}{}", dir_name.to_string_lossy(), current);
}
Err(err) => {
eprintln!("error listing installed versions: {err:?}");
}
};
}
Ok(())
}

View File

@ -237,6 +237,7 @@ pub fn main() -> Result<(), String> {
.help("arguments to supply to the program"),
),
)
.subcommand(SubCommand::with_name("list").about("List installed versions of solana cli"))
.get_matches();
let config_file = matches.value_of("config_file").unwrap();
@ -272,6 +273,7 @@ pub fn main() -> Result<(), String> {
command::run(config_file, program_name, program_arguments)
}
("list", Some(_matches)) => command::list(config_file),
_ => unreachable!(),
}
}