feat(solana-install): subcommand to list installed versions (#32823)
This commit is contained in:
parent
f86b6edc4d
commit
285e52bd1b
|
@ -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(())
|
||||||
|
}
|
||||||
|
|
|
@ -237,6 +237,7 @@ pub fn main() -> Result<(), String> {
|
||||||
.help("arguments to supply to the program"),
|
.help("arguments to supply to the program"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.subcommand(SubCommand::with_name("list").about("List installed versions of solana cli"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let config_file = matches.value_of("config_file").unwrap();
|
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)
|
command::run(config_file, program_name, program_arguments)
|
||||||
}
|
}
|
||||||
|
("list", Some(_matches)) => command::list(config_file),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue