From 437b70d51bac03cf70e6257c44922886176f6acb Mon Sep 17 00:00:00 2001 From: Tao <79176764+yeetfield@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:14:56 -0600 Subject: [PATCH] Add info subcommand (#36) --- rozy/src/app.rs | 12 ++++++++++ rozy/src/main.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/rozy/src/app.rs b/rozy/src/app.rs index 86ef2b6..54ab0ef 100644 --- a/rozy/src/app.rs +++ b/rozy/src/app.rs @@ -221,6 +221,18 @@ impl PartialEq for App { impl Eq for App {} +impl std::fmt::Display for App { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!( + f, + "{} {}: {}", + self.name, + self.version, + self.installer.describe() + ) + } +} + #[cfg(test)] mod tests { use serde_yaml::Mapping; diff --git a/rozy/src/main.rs b/rozy/src/main.rs index 1efb1c5..9ed25fb 100644 --- a/rozy/src/main.rs +++ b/rozy/src/main.rs @@ -300,7 +300,58 @@ fn list() -> Result<()> { let config = config::load_config(None)?; let apps = get_apps(&config)?; for app in apps.iter() { - eprintln!("{}", app.name); + println!("{}", app.name); + } + + Ok(()) +} + +fn show_path_warning() -> Result<()> { + let ozy_bin_dir = files::get_ozy_bin_dir()?.to_str().unwrap().to_owned(); + + println!("{:-<1$}", "", 80); + println!("Please ensure '{}' is on your path", ozy_bin_dir); + println!("bash shell users:"); + println!( + " bash$ echo -e '# ozy support\\nexport PATH={}:$PATH' >> ~/.bashrc", + ozy_bin_dir + ); + println!(" then restart your shell sessions"); + println!("zsh shell users:"); + println!(" zsh$ # path+=({})\\nexport PATH", ozy_bin_dir); + println!("fish shell users: "); + println!( + " fish$ set --universal fish_user_paths {} $fish_user_paths", + ozy_bin_dir + ); + println!("{:-<1$}", "", 80); + + Ok(()) +} + +fn info() -> Result<()> { + let is_path_ok = check_path(&files::get_ozy_bin_dir()?)?; + if !is_path_ok { + show_path_warning()?; + } + + let user_config = config::get_ozy_user_conf()?; + let team_url = match user_config.get("url") { + Some(v) => v.as_str().unwrap(), + None => "(unset)", + }; + println!("Team URL: {}", team_url); + + let config = config::load_config(None)?; + let team_config_name = match config.get("name") { + Some(v) => v.as_str().unwrap(), + None => "(unset)", + }; + println!("Team config name: {}", team_config_name); + + let apps = get_apps(&config)?; + for app in apps.iter() { + println!(" {}", app); } Ok(()) @@ -357,6 +408,9 @@ install: #[clap(about = "Initialise and install ozy, with configuration from the given URL")] Init { url: String }, + #[clap(about = "Print information about the installation and configuration")] + Info, + #[clap(about = "List all the managed apps")] List, @@ -404,6 +458,7 @@ fn main() -> Result<(), Error> { Commands::Init { url } => init(&exe_path, url), Commands::Install { app_names } => install(app_names), Commands::InstallAll => install_all(), + Commands::Info => info(), Commands::List => list(), Commands::MakefileConfig { makefile_var,