From b8635f6a4f2429382fafdbdd1e0b8bb1f8b7b296 Mon Sep 17 00:00:00 2001 From: Michael Gattozzi Date: Tue, 26 Nov 2019 11:08:11 -0500 Subject: 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. --- src/main.rs | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/main.rs (limited to 'src') 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::>(); + + 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, +} -- cgit v1.2.3