diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-03-26 00:28:29 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-03-26 00:28:29 -0400 |
commit | 688bc5177951ce01d22395a1aa8ed7d43d23d73e (patch) | |
tree | 9cb40d5a5d60a8c8d4be1fe091c2cab6fc3a35f8 /src | |
parent | 6f19f96053db7475e2376c9dd3179c4dd2264df8 (diff) | |
download | fancy-prompt-688bc5177951ce01d22395a1aa8ed7d43d23d73e.tar.gz fancy-prompt-688bc5177951ce01d22395a1aa8ed7d43d23d73e.zip |
bump deps
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 25 | ||||
-rw-r--r-- | src/data.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/vcs/git.rs | 22 |
4 files changed, 29 insertions, 28 deletions
diff --git a/src/args.rs b/src/args.rs index da1ff19..f0c65d0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -6,32 +6,31 @@ pub struct CommandLineOptions { } pub fn parse() -> CommandLineOptions { - let matches = clap::App::new("fancy-prompt") + let matches = clap::Command::new("fancy-prompt") .about("Prints a fancy prompt") - .author(crate_authors!()) - .version(crate_version!()) + .author(clap::crate_authors!()) + .version(clap::crate_version!()) .arg( - clap::Arg::with_name("prompt-escape") + clap::Arg::new("prompt-escape") .long("prompt-escape") .value_name("SHELL") - .help("Produces escape sequence wrappers for the given shell") - .takes_value(true), + .help( + "Produces escape sequence wrappers for the given shell", + ), ) .arg( - clap::Arg::with_name("error-code") + clap::Arg::new("error-code") .value_name("ERROR_CODE") .help("The error code of the previously run command"), ) .get_matches(); let shell = matches - .value_of("prompt-escape") - .map(colors::ShellType::from_str) + .get_one::<String>("prompt-escape") + .map(|s| colors::ShellType::from_str(&s)) .unwrap_or(colors::ShellType::Unknown); - let error_code = matches - .value_of("error-code") - .map(|code| code.parse().expect("error code must be a u8")) - .unwrap_or(0); + let error_code = + matches.get_one::<u8>("error-code").copied().unwrap_or(0); CommandLineOptions { shell, error_code } } diff --git a/src/data.rs b/src/data.rs index c2ea49e..ae89c9d 100644 --- a/src/data.rs +++ b/src/data.rs @@ -57,7 +57,8 @@ pub fn collect(opts: args::CommandLineOptions) -> PromptData { } fn hostname() -> Option<String> { - if let Some(mut name) = hostname::get_hostname() { + if let Ok(name) = hostname::get() { + let mut name = name.into_string().unwrap(); if let Some(idx) = name.find('.') { name.truncate(idx); } @@ -84,7 +85,7 @@ fn home() -> Option<std::path::PathBuf> { } fn user() -> Option<String> { - users::get_current_username() + users::get_current_username().map(|s| s.into_string().unwrap()) } fn is_root() -> bool { diff --git a/src/main.rs b/src/main.rs index 328dc8a..708c907 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ extern crate chrono; -#[macro_use] extern crate clap; extern crate git2; extern crate hostname; @@ -50,7 +49,9 @@ mod tests { home: Some(std::path::PathBuf::from("/home/doy")), user: Some(String::from("doy")), is_root: false, - time: chrono::Local.ymd(2018, 5, 14).and_hms(17, 35, 45), + time: chrono::Local + .with_ymd_and_hms(2018, 5, 14, 17, 35, 45) + .unwrap(), power_info: power::PowerInfo::new(), vcs_info: None, }; diff --git a/src/vcs/git.rs b/src/vcs/git.rs index b2fd5b2..f4666d1 100644 --- a/src/vcs/git.rs +++ b/src/vcs/git.rs @@ -16,19 +16,19 @@ impl GitInfo { start_talking_about_time!("git"); let mut modified_statuses = git2::Status::empty(); - modified_statuses.insert(git2::STATUS_WT_DELETED); - modified_statuses.insert(git2::STATUS_WT_MODIFIED); - modified_statuses.insert(git2::STATUS_WT_RENAMED); - modified_statuses.insert(git2::STATUS_WT_TYPECHANGE); - modified_statuses.insert(git2::STATUS_CONFLICTED); + modified_statuses.insert(git2::Status::WT_DELETED); + modified_statuses.insert(git2::Status::WT_MODIFIED); + modified_statuses.insert(git2::Status::WT_RENAMED); + modified_statuses.insert(git2::Status::WT_TYPECHANGE); + modified_statuses.insert(git2::Status::CONFLICTED); let mut staged_statuses = git2::Status::empty(); - staged_statuses.insert(git2::STATUS_INDEX_DELETED); - staged_statuses.insert(git2::STATUS_INDEX_MODIFIED); - staged_statuses.insert(git2::STATUS_INDEX_NEW); - staged_statuses.insert(git2::STATUS_INDEX_RENAMED); - staged_statuses.insert(git2::STATUS_INDEX_TYPECHANGE); + staged_statuses.insert(git2::Status::INDEX_DELETED); + staged_statuses.insert(git2::Status::INDEX_MODIFIED); + staged_statuses.insert(git2::Status::INDEX_NEW); + staged_statuses.insert(git2::Status::INDEX_RENAMED); + staged_statuses.insert(git2::Status::INDEX_TYPECHANGE); let mut new_statuses = git2::Status::empty(); - new_statuses.insert(git2::STATUS_WT_NEW); + new_statuses.insert(git2::Status::WT_NEW); talk_about_time!("status bitsets"); let mut status_options = git2::StatusOptions::new(); |