summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTilmann Meyer <allescrafterx@gmail.com>2020-09-28 22:38:50 +0200
committerGitHub <noreply@github.com>2020-09-28 16:38:50 -0400
commit22336834109a1659069acdfb1dfeb324206a9fc9 (patch)
treea3071d855ae1129817e000fb77932c1c5608cd6d /src/main.rs
parent3c668e6e6ac0c0ee7dbe2ef69ede1e4a16ec1c9c (diff)
feat: add error messaging (#1576)
This creates a custom logger for the log crate which logs everything to a file (/tmp/starship/session_$STARSHIP_SESSION_KEY.log) and it logs everything above Warn to stderr, but only if the log file does not contain the line that should be logged resulting in an error or warning to be only logged at the first starship invocation after opening the shell.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 3afcf6b3d..46dc86e25 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,7 @@ mod configure;
mod context;
mod formatter;
mod init;
+mod logger;
mod module;
mod modules;
mod print;
@@ -20,9 +21,11 @@ mod test;
use crate::module::ALL_MODULES;
use clap::{App, AppSettings, Arg, Shell, SubCommand};
+use rand::distributions::Alphanumeric;
+use rand::Rng;
fn main() {
- pretty_env_logger::init_custom_env("STARSHIP_LOG");
+ logger::init();
let status_code_arg = Arg::with_name("status_code")
.short("s")
@@ -153,7 +156,8 @@ fn main() {
.required(true)
.env("STARSHIP_SHELL"),
),
- );
+ )
+ .subcommand(SubCommand::with_name("session").about("Generate random session key"));
let matches = app.clone().get_matches();
@@ -209,6 +213,13 @@ fn main() {
app.gen_completions_to("starship", shell, &mut io::stdout().lock());
}
+ ("session", _) => println!(
+ "{}",
+ rand::thread_rng()
+ .sample_iter(&Alphanumeric)
+ .take(16)
+ .collect::<String>()
+ ),
(command, _) => unreachable!("Invalid subcommand: {}", command),
}
}