diff --git a/install/src/command.rs b/install/src/command.rs index bc4f105a8c..ac53f5fe2b 100644 --- a/install/src/command.rs +++ b/install/src/command.rs @@ -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(()) +} diff --git a/install/src/lib.rs b/install/src/lib.rs index e6f68587a6..32895b6e65 100644 --- a/install/src/lib.rs +++ b/install/src/lib.rs @@ -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!(), } }