diff options
author | NerdyPepper <[email protected]> | 2019-05-20 15:21:16 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-05-20 15:21:16 +0100 |
commit | f8a3b4d8d2b452f09e86f282ec0bd87dc57e71e8 (patch) | |
tree | 68f41537bad3c5bfec3dfbc7d66de6792bdf8189 /src | |
parent | d61e0ff1e192c62085e842ba878cdb10bacd4c9e (diff) |
add cli
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 26 insertions, 5 deletions
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; | |||
3 | mod vcs; | 3 | mod vcs; |
4 | mod venv; | 4 | mod venv; |
5 | 5 | ||
6 | use clap::{Arg, App}; | ||
7 | |||
6 | fn main() { | 8 | fn main() { |
7 | println!("{}", pista()); | 9 | let matches = App::new("Pista") |
10 | .version(env!("CARGO_PKG_VERSION")) | ||
11 | .author(env!("CARGO_PKG_AUTHORS")) | ||
12 | .about(env!("CARGO_PKG_DESCRIPTION")) | ||
13 | .arg(Arg::with_name("minimal") | ||
14 | .short("m") | ||
15 | .long("minimal") | ||
16 | .help("use minimal variant") | ||
17 | ) | ||
18 | .get_matches(); | ||
19 | if matches.is_present("minimal") { | ||
20 | println!("{}", pista_minimal()); | ||
21 | } else { | ||
22 | println!("{}", pista()); | ||
23 | } | ||
8 | } | 24 | } |
9 | 25 | ||
10 | fn pista() -> String { | 26 | fn pista() -> String { |
@@ -23,13 +39,18 @@ fn pista() -> String { | |||
23 | 39 | ||
24 | fn pista_minimal() -> String { | 40 | fn pista_minimal() -> String { |
25 | let cwd = cwd::cwd(); | 41 | let cwd = cwd::cwd(); |
26 | let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); | 42 | let vcs_tuple = vcs::vcs_status(); |
43 | let mut vcs_component = String::new(); | ||
44 | if let Some((branch, status)) = vcs_tuple { | ||
45 | vcs_component = format!(" [{} {}] ", branch, status); | ||
46 | } else { | ||
47 | vcs_component.push(' '); | ||
48 | } | ||
27 | let venv = venv::get_name(); | 49 | let venv = venv::get_name(); |
28 | let prompt_char = prompt_char::get_char(); | 50 | let prompt_char = prompt_char::get_char(); |
29 | format!("{cwd} {branch}{status}{venv}{pchar}", | 51 | format!("{cwd}{vcs}{venv}{pchar} ", |
30 | cwd=cwd, | 52 | cwd=cwd, |
31 | branch=branch, | 53 | vcs=vcs_component, |
32 | status=status, | ||
33 | venv=venv, | 54 | venv=venv, |
34 | pchar=prompt_char | 55 | pchar=prompt_char |
35 | ) | 56 | ) |