From f8a3b4d8d2b452f09e86f282ec0bd87dc57e71e8 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 20 May 2019 19:51:16 +0530 Subject: add cli --- Cargo.toml | 3 ++- src/main.rs | 31 ++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5469a29..0302432 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "prompt" +name = "pista" version = "0.1.0" authors = ["NerdyPepper "] edition = "2018" @@ -10,3 +10,4 @@ tico = "1.0.0" libc = "0.2.55" colored = "1.8.0" git2 = "0.8.0" +clap = "2.33.0" 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