Skip to content

Commit

Permalink
Add info subcommand (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeetfield authored Jan 25, 2023
1 parent 7c6384a commit 437b70d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
12 changes: 12 additions & 0 deletions rozy/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 56 additions & 1 deletion rozy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 437b70d

Please sign in to comment.