summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJan Katins <jasc@gmx.net>2020-09-21 19:06:15 +0200
committerGitHub <noreply@github.com>2020-09-21 19:06:15 +0200
commit6426bbe3e489faa4b3ebefc028f37496b3ca5caa (patch)
tree5e9c9003aab051ba258ae544fc2bf47216157157 /src/main.rs
parentbb324834a515e18ca7a913ad6248cb8049e3ec33 (diff)
feat: Add timings subcommand (#1629)
* feat: Add computational duration to all computed modules This also means that in case we do some computations and these end up empty, we submit an empty module * feat: Add timings subcommand This outputs the timings of all computed modules, sorted by the duration it took to compute the module. Useful for debugging why the prompt takes so long. * feat: Add timings to explain output * fix: Ensure that even empty custom modules get timings * format main.rs * feat: Only show interesting timings * fix(tests): Change tests to look for empty string instead of None * Use proper wording in timings help * Revert "fix(tests): Change tests to look for empty string instead of None" This reverts commit aca5bd1b03c48e1dee1b7ca91d66e2bda2d5a97c. * fix(tests): Returning None in case the module produced an empty string * fix: Ensure that linebreaks (and space) make a module not-empty * Make cargo clippy happy * Make Module.duration a proper Duration * Only return a module if we would report it * Change to cleaner way to return None for empty modules * Avoid unnecessary module creation * Simplify a string comparison * Add timings to trace Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com> Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs163
1 files changed, 83 insertions, 80 deletions
diff --git a/src/main.rs b/src/main.rs
index 27876b9c8..3afcf6b3d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -71,87 +71,89 @@ fn main() {
.long("print-full-init")
.help("Print the main initialization script (as opposed to the init stub)");
- let mut app =
- 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),
- )
- .subcommand(
- SubCommand::with_name("config")
- .alias("configure")
- .about("Edit the starship configuration")
- .arg(
- Arg::with_name("name")
- .help("Configuration key to edit")
- .required(false)
- .requires("value"),
- )
- .arg(Arg::with_name("value").help("Value to place into that key")),
- )
- .subcommand(SubCommand::with_name("bug-report").about(
+ let mut app = 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),
+ )
+ .subcommand(
+ SubCommand::with_name("config")
+ .alias("configure")
+ .about("Edit the starship configuration")
+ .arg(
+ Arg::with_name("name")
+ .help("Configuration key to edit")
+ .required(false)
+ .requires("value"),
+ )
+ .arg(Arg::with_name("value").help("Value to place into that key")),
+ )
+ .subcommand(
+ SubCommand::with_name("bug-report").about(
"Create a pre-populated GitHub issue with information about your configuration",
- ))
- .subcommand(
- SubCommand::with_name("time")
- .about("Prints time in milliseconds")
- .settings(&[AppSettings::Hidden]),
- )
- .subcommand(
- SubCommand::with_name("explain").about("Explains the currently showing modules"),
- )
- .subcommand(
- SubCommand::with_name("completions")
- .about("Generate starship shell completions for your shell to stdout")
- .arg(
- Arg::with_name("shell")
- .takes_value(true)
- .possible_values(&Shell::variants())
- .help("the shell to generate completions for")
- .value_name("SHELL")
- .required(true)
- .env("STARSHIP_SHELL"),
- ),
- );
+ ),
+ )
+ .subcommand(
+ SubCommand::with_name("time")
+ .about("Prints time in milliseconds")
+ .settings(&[AppSettings::Hidden]),
+ )
+ .subcommand(
+ SubCommand::with_name("explain").about("Explains the currently showing modules"),
+ )
+ .subcommand(SubCommand::with_name("timings").about("Prints timings of all active modules"))
+ .subcommand(
+ SubCommand::with_name("completions")
+ .about("Generate starship shell completions for your shell to stdout")
+ .arg(
+ Arg::with_name("shell")
+ .takes_value(true)
+ .possible_values(&Shell::variants())
+ .help("the shell to generate completions for")
+ .value_name("SHELL")
+ .required(true)
+ .env("STARSHIP_SHELL"),
+ ),
+ );
let matches = app.clone().get_matches();
@@ -197,6 +199,7 @@ fn main() {
}
}
("explain", Some(sub_m)) => print::explain(sub_m.clone()),
+ ("timings", Some(sub_m)) => print::timings(sub_m.clone()),
("completions", Some(sub_m)) => {
let shell: Shell = sub_m
.value_of("shell")