summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-10-04 22:30:46 +0900
committerGitHub <noreply@github.com>2019-10-04 22:30:46 +0900
commit05210b9510b797f7738d5b2d51e8a6877f2d5283 (patch)
tree7399401dba9373f61035dbbd055f4137cd20f705 /src/main.rs
parente90a3768da7882db092b38d141cf8e19fabbee56 (diff)
refactor: Go from Rust workspaces to a package with nested packages (#480)
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 000000000..488555d1e
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,137 @@
+#[macro_use]
+extern crate clap;
+
+mod config;
+mod configs;
+mod context;
+mod init;
+mod module;
+mod modules;
+mod print;
+mod segment;
+mod utils;
+
+use crate::module::ALL_MODULES;
+use clap::{App, AppSettings, Arg, SubCommand};
+
+fn main() {
+ pretty_env_logger::init();
+
+ let status_code_arg = Arg::with_name("status_code")
+ .short("s")
+ .long("status")
+ .value_name("STATUS_CODE")
+ .help("The status code of the previously run command")
+ .takes_value(true);
+
+ let path_arg = Arg::with_name("path")
+ .short("p")
+ .long("path")
+ .value_name("PATH")
+ .help("The path that the prompt should render for")
+ .takes_value(true);
+
+ let shell_arg = Arg::with_name("shell")
+ .value_name("SHELL")
+ .help(
+ "The name of the currently running shell\nCurrently supported options: bash, zsh, fish",
+ )
+ .required(true);
+
+ let cmd_duration_arg = Arg::with_name("cmd_duration")
+ .short("d")
+ .long("cmd-duration")
+ .value_name("CMD_DURATION")
+ .help("The execution duration of the last command, in seconds")
+ .takes_value(true);
+
+ let keymap_arg = Arg::with_name("keymap")
+ .short("k")
+ .long("keymap")
+ .value_name("KEYMAP")
+ // fish/zsh only
+ .help("The keymap of fish/zsh")
+ .takes_value(true);
+
+ let jobs_arg = Arg::with_name("jobs")
+ .short("j")
+ .long("jobs")
+ .value_name("JOBS")
+ .help("The number of currently running jobs")
+ .takes_value(true);
+
+ let init_scripts_arg = Arg::with_name("print_full_init")
+ .long("print-full-init")
+ .help("Print the main initialization script (as opposed to the init stub)");
+
+ let matches = App::new("starship")
+ .about("The cross-shell prompt for astronauts. ☄🌌️")
+ // pull the version number from Cargo.toml
+ .version(crate_version!())
+ // pull the authors from Cargo.toml
+ .author(crate_authors!())
+ .after_help("https://github.com/starship/starship")
+ .setting(AppSettings::SubcommandRequiredElseHelp)
+ .subcommand(
+ SubCommand::with_name("init")
+ .about("Prints the shell function used to execute starship")
+ .arg(&shell_arg)
+ .arg(&init_scripts_arg),
+ )
+ .subcommand(
+ SubCommand::with_name("prompt")
+ .about("Prints the full starship prompt")
+ .arg(&status_code_arg)
+ .arg(&path_arg)
+ .arg(&cmd_duration_arg)
+ .arg(&keymap_arg)
+ .arg(&jobs_arg),
+ )
+ .subcommand(
+ SubCommand::with_name("module")
+ .about("Prints a specific prompt module")
+ .arg(
+ Arg::with_name("name")
+ .help("The name of the module to be printed")
+ .required(true)
+ .required_unless("list"),
+ )
+ .arg(
+ Arg::with_name("list")
+ .short("l")
+ .long("list")
+ .help("List out all supported modules"),
+ )
+ .arg(&status_code_arg)
+ .arg(&path_arg)
+ .arg(&cmd_duration_arg)
+ .arg(&keymap_arg)
+ .arg(&jobs_arg),
+ )
+ .get_matches();
+
+ match matches.subcommand() {
+ ("init", Some(sub_m)) => {
+ let shell_name = sub_m.value_of("shell").expect("Shell name missing.");
+ if sub_m.is_present("print_full_init") {
+ init::init_main(shell_name).expect("can't init_main");
+ } else {
+ init::init_stub(shell_name).expect("can't init_stub");
+ }
+ }
+ ("prompt", Some(sub_m)) => print::prompt(sub_m.clone()),
+ ("module", Some(sub_m)) => {
+ if sub_m.is_present("list") {
+ println!("Supported modules list");
+ println!("----------------------");
+ for modules in ALL_MODULES {
+ println!("{}", modules);
+ }
+ }
+ if let Some(module_name) = sub_m.value_of("name") {
+ print::module(module_name, sub_m.clone());
+ }
+ }
+ _ => {}
+ }
+}