From f8a3b4d8d2b452f09e86f282ec0bd87dc57e71e8 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 20 May 2019 19:51:16 +0530 Subject: add cli --- src/main.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e0b8f41..cee0c21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,24 @@ mod prompt_char; mod vcs; mod venv; +use clap::{Arg, App}; + fn main() { - println!("{}", pista()); + let matches = App::new("Pista") + .version(env!("CARGO_PKG_VERSION")) + .author(env!("CARGO_PKG_AUTHORS")) + .about(env!("CARGO_PKG_DESCRIPTION")) + .arg(Arg::with_name("minimal") + .short("m") + .long("minimal") + .help("use minimal variant") + ) + .get_matches(); + if matches.is_present("minimal") { + println!("{}", pista_minimal()); + } else { + println!("{}", pista()); + } } fn pista() -> String { @@ -23,13 +39,18 @@ fn pista() -> String { fn pista_minimal() -> String { let cwd = cwd::cwd(); - let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); + let vcs_tuple = vcs::vcs_status(); + let mut vcs_component = String::new(); + if let Some((branch, status)) = vcs_tuple { + vcs_component = format!(" [{} {}] ", branch, status); + } else { + vcs_component.push(' '); + } let venv = venv::get_name(); let prompt_char = prompt_char::get_char(); - format!("{cwd} {branch}{status}{venv}{pchar}", + format!("{cwd}{vcs}{venv}{pchar} ", cwd=cwd, - branch=branch, - status=status, + vcs=vcs_component, venv=venv, pchar=prompt_char ) -- cgit v1.2.3