diff options
author | Michael Gattozzi <mgattozzi@gmail.com> | 2019-11-26 11:08:11 -0500 |
---|---|---|
committer | Michael Gattozzi <mgattozzi@gmail.com> | 2019-11-26 11:08:11 -0500 |
commit | b8635f6a4f2429382fafdbdd1e0b8bb1f8b7b296 (patch) | |
tree | 6e59b73f2189c45a4e6000dd5fc619f2da085113 /src | |
parent | bcea608cb4ab1c234f37a6095833f1e916777495 (diff) |
Create dev-suite tool to orchestrate tooling
The dev-suite tool acts simmilar to rustup in that it's responsible for
keeping the tools up to date, installing the tools, and managing itself.
It also includes an init command to run all the various tools init
commands all at once. Of course we want what tools people use to be
configurable. dev-suite uses dialouger in order to provide a nice text
based menu for things like selecting what tools to use etc. Certain
functions are stubbed out for now, but they will be expanded over time.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7869f4d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,83 @@ +use anyhow::{ + format_err, + Result, +}; +use dialoguer::{ + theme::ColorfulTheme, + Checkboxes, +}; +use shared::find_root; +use std::process::Command; +use which::which; + +#[derive(structopt::StructOpt)] +enum Args { + /// Download and install all of dev-suite + Install, + /// Update all of dev-suite + Update, + /// Initialize the repo to use dev-suite and it's tools + Init, +} + +#[paw::main] +fn main(args: Args) { + if let Err(e) = match args { + Args::Init => init(), + Args::Update => unimplemented!(), + Args::Install => unimplemented!(), + } { + eprintln!("{}", e); + std::process::exit(1); + } +} + +fn init() -> Result<()> { + // Make sure we're in a valid git repo + find_root()?; + let checkboxes = &["hooked - Managed git hooks", "ticket - In repo tickets"]; + let defaults = &[true, true]; + let selections = Checkboxes::with_theme(&ColorfulTheme::default()) + .with_prompt("Which tools do you want to enable? (defaults to all)") + .items(&checkboxes[..]) + .defaults(&defaults[..]) + .interact()? + .into_iter() + .map(|s| match s { + 0 => Tools::Hooked, + 1 => Tools::Ticket, + _ => unreachable!(), + }) + .collect::<Vec<Tools>>(); + + if selections.is_empty() { + println!("Nothing selected. dev-suite not enabled in this repository."); + } else { + for selection in selections { + match selection { + Tools::Hooked => { + which("hooked") + .map(drop) + .map_err(|_| format_err!( + "It looks like hooked is not on your $PATH. Did you run 'ds install'?" + ))?; + Command::new("hooked").arg("init").spawn()?.wait()?; + } + Tools::Ticket => { + which("ticket") + .map(drop) + .map_err(|_| format_err!( + "It looks like ticket is not on your $PATH. Did you run 'ds install'?" + ))?; + Command::new("ticket").arg("init").spawn()?.wait()?; + } + } + } + } + Ok(()) +} + +enum Tools { + Hooked, + Ticket, +} |