From e70b8148e928ed3c43620971e2372a48980d3fd6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 14:44:23 +0000 Subject: [PATCH 1/5] build(deps): update rust crate toml to 0.5.10 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5b4c42cc..7e8f766f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3043,9 +3043,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "toml" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" dependencies = [ "indexmap", "serde", diff --git a/Cargo.toml b/Cargo.toml index 97b393f37..61168d9d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ starship-battery = { version = "0.7.9", optional = true } strsim = "0.10.0" systemstat = "=0.2.2" terminal_size = "0.2.3" -toml = { version = "0.5.9", features = ["preserve_order"] } +toml = { version = "0.5.10", features = ["preserve_order"] } toml_edit = "0.15.0" unicode-segmentation = "1.10.0" unicode-width = "0.1.10" From 1f7d1e39c6b298ec6d309b894a4ad740f6021ce1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:03:55 +0000 Subject: [PATCH 2/5] build(deps): update rust crate shadow-rs to 0.19.0 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e8f766f1..1bd12c06f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2656,9 +2656,9 @@ dependencies = [ [[package]] name = "shadow-rs" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf8e33626554dd9027d240a3b91d73be43054c0f9ef645cdf0483b6ebe822fa" +checksum = "6c401e795850edb4e9fdde5940f856364f0fbab573e8dea58f6ee5f85fcf471d" dependencies = [ "const_format", "is_debug", diff --git a/Cargo.toml b/Cargo.toml index 61168d9d2..b7ec6870b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ semver = "1.0.14" serde = { version = "1.0.150", features = ["derive"] } serde_json = "1.0.89" sha1 = "0.10.5" -shadow-rs = { version = "0.18.0", default-features = false } +shadow-rs = { version = "0.19.0", default-features = false } # battery is optional (on by default) because the crate doesn't currently build for Termux # see: https://github.com/svartalf/rust-battery/issues/33 starship-battery = { version = "0.7.9", optional = true } @@ -117,7 +117,7 @@ features = [ nix = { version = "0.26.1", default-features = false, features = ["feature", "fs", "user"] } [build-dependencies] -shadow-rs = { version = "0.18.0", default-features = false } +shadow-rs = { version = "0.19.0", default-features = false } dunce = "1.0.3" [target.'cfg(windows)'.build-dependencies] From 220844daa014046bedbc9ce703f8b18fbe267e3c Mon Sep 17 00:00:00 2001 From: Marie Date: Sat, 17 Dec 2022 13:32:40 +0100 Subject: [PATCH 3/5] feat(gradle): add gradle module (#4423) * docs: document gradle module * implement gradle module * gradle-module: add test for wrapper properties case * docs: improve gradle module documentation * fix: fix gradle module wrapper properties test * drop gradle executable strategy * apply suggested stuff * Fix config schema --- .github/config-schema.json | 79 +++++++ .../presets/toml/bracketed-segments.toml | 3 + .../presets/toml/no-runtime-versions.toml | 3 + .../public/presets/toml/pastel-powerline.toml | 5 + .../presets/toml/plain-text-symbols.toml | 3 + docs/config/README.md | 37 +++ src/configs/gradle.rs | 36 +++ src/configs/mod.rs | 3 + src/configs/starship_root.rs | 1 + src/module.rs | 1 + src/modules/gradle.rs | 220 ++++++++++++++++++ src/modules/mod.rs | 3 + 12 files changed, 394 insertions(+) create mode 100644 src/configs/gradle.rs create mode 100644 src/modules/gradle.rs diff --git a/.github/config-schema.json b/.github/config-schema.json index 2cb9bb5f1..404cdd6aa 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -621,6 +621,29 @@ } ] }, + "gradle": { + "default": { + "detect_extensions": [ + "gradle", + "gradle.kts" + ], + "detect_files": [], + "detect_folders": [ + "gradle" + ], + "disabled": false, + "format": "via [$symbol($version )]($style)", + "recursive": false, + "style": "bold bright-cyan", + "symbol": "🅶 ", + "version_format": "v${raw}" + }, + "allOf": [ + { + "$ref": "#/definitions/GradleConfig" + } + ] + }, "guix_shell": { "default": { "disabled": false, @@ -3189,6 +3212,62 @@ }, "additionalProperties": false }, + "GradleConfig": { + "type": "object", + "properties": { + "format": { + "default": "via [$symbol($version )]($style)", + "type": "string" + }, + "version_format": { + "default": "v${raw}", + "type": "string" + }, + "symbol": { + "default": "🅶 ", + "type": "string" + }, + "style": { + "default": "bold bright-cyan", + "type": "string" + }, + "disabled": { + "default": false, + "type": "boolean" + }, + "recursive": { + "default": false, + "type": "boolean" + }, + "detect_extensions": { + "default": [ + "gradle", + "gradle.kts" + ], + "type": "array", + "items": { + "type": "string" + } + }, + "detect_files": { + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "detect_folders": { + "default": [ + "gradle" + ], + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + }, "GuixShellConfig": { "type": "object", "properties": { diff --git a/docs/.vuepress/public/presets/toml/bracketed-segments.toml b/docs/.vuepress/public/presets/toml/bracketed-segments.toml index f871774dd..c86ed0479 100644 --- a/docs/.vuepress/public/presets/toml/bracketed-segments.toml +++ b/docs/.vuepress/public/presets/toml/bracketed-segments.toml @@ -58,6 +58,9 @@ format = '([\[$all_status$ahead_behind\]]($style))' [golang] format = '\[[$symbol($version)]($style)\]' +[gradle] +format = '\[[$symbol($version)]($style)\]' + [guix_shell] format = '\[[$symbol]($style)\]' diff --git a/docs/.vuepress/public/presets/toml/no-runtime-versions.toml b/docs/.vuepress/public/presets/toml/no-runtime-versions.toml index 28ffb7fca..97b6a3ed7 100644 --- a/docs/.vuepress/public/presets/toml/no-runtime-versions.toml +++ b/docs/.vuepress/public/presets/toml/no-runtime-versions.toml @@ -37,6 +37,9 @@ format = 'via [$symbol]($style)' [golang] format = 'via [$symbol]($style)' +[gradle] +format = 'via [$symbol]($style)' + [haxe] format = 'via [$symbol]($style)' diff --git a/docs/.vuepress/public/presets/toml/pastel-powerline.toml b/docs/.vuepress/public/presets/toml/pastel-powerline.toml index 6c240d063..f5cee6ecc 100644 --- a/docs/.vuepress/public/presets/toml/pastel-powerline.toml +++ b/docs/.vuepress/public/presets/toml/pastel-powerline.toml @@ -12,6 +12,7 @@ $c\ $elixir\ $elm\ $golang\ +$gradle\ $haskell\ $java\ $julia\ @@ -97,6 +98,10 @@ symbol = " " style = "bg:#86BBD8" format = '[ $symbol ($version) ]($style)' +[gradle] +style = "bg:#86BBD8" +format = '[ $symbol ($version) ]($style)' + [haskell] symbol = " " style = "bg:#86BBD8" diff --git a/docs/.vuepress/public/presets/toml/plain-text-symbols.toml b/docs/.vuepress/public/presets/toml/plain-text-symbols.toml index bf6591980..1efccd243 100644 --- a/docs/.vuepress/public/presets/toml/plain-text-symbols.toml +++ b/docs/.vuepress/public/presets/toml/plain-text-symbols.toml @@ -64,6 +64,9 @@ symbol = "git " [golang] symbol = "go " +[gradle] +symbol = "gradle " + [guix_shell] symbol = "guix " diff --git a/docs/config/README.md b/docs/config/README.md index 0d4d13ac8..4d1a7161f 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -291,6 +291,7 @@ $helm\ $java\ $julia\ $kotlin\ +$gradle\ $lua\ $nim\ $nodejs\ @@ -1927,6 +1928,42 @@ disabled = true format = 'via [🐂](yellow bold) ' ``` +## Gradle + +The `gradle` module shows the version of the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) +currently used in the project directory. + +By default the module will be shown if any of the following conditions are met: + +- The current directory contains a `gradle/wrapper/gradle-wrapper.properties` directory. +- The current directory contains a file ending with `.gradle` or `.gradle.kts`. + +The `gradle` module is only able to read your Gradle Wrapper version from your config file, we don't execute your wrapper, because of the security concerns. + +### Options + +| Option | Default | Description | +| ------------------- | ------------------------------------ | ------------------------------------------------------------------------- | +| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | +| `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` | +| `symbol` | `"🅶 "` | A format string representing the symbol of Gradle. | +| `detect_extensions` | `["gradle", "gradle.kts"]` | Which extensions should trigger this module. | +| `detect_files` | `[]` | Which filenames should trigger this module. | +| `detect_folders` | `["gradle"]` | Which folders should trigger this module. | +| `style` | `"bold bright-cyan"` | The style for the module. | +| `disabled` | `false` | Disables the `gradle` module. | +| `recursive` | `false` | Enables recursive finding for the `gradle` directory. | + +### Variables + +| Variable | Example | Description | +| -------- | -------- | ------------------------------------ | +| version | `v7.5.1` | The version of `gradle` | +| symbol | | Mirrors the value of option `symbol` | +| style* | | Mirrors the value of option `style` | + +*: This variable can only be used as a part of a style string + ## Haskell The `haskell` module finds the current selected GHC version and/or the selected Stack snapshot. diff --git a/src/configs/gradle.rs b/src/configs/gradle.rs new file mode 100644 index 000000000..5026f83e5 --- /dev/null +++ b/src/configs/gradle.rs @@ -0,0 +1,36 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Deserialize, Serialize)] +#[cfg_attr( + feature = "config-schema", + derive(schemars::JsonSchema), + schemars(deny_unknown_fields) +)] +#[serde(default)] +pub struct GradleConfig<'a> { + pub format: &'a str, + pub version_format: &'a str, + pub symbol: &'a str, + pub style: &'a str, + pub disabled: bool, + pub recursive: bool, + pub detect_extensions: Vec<&'a str>, + pub detect_files: Vec<&'a str>, + pub detect_folders: Vec<&'a str>, +} + +impl<'a> Default for GradleConfig<'a> { + fn default() -> Self { + GradleConfig { + format: "via [$symbol($version )]($style)", + version_format: "v${raw}", + symbol: "🅶 ", + style: "bold bright-cyan", + disabled: false, + recursive: false, + detect_extensions: vec!["gradle", "gradle.kts"], + detect_files: vec![], + detect_folders: vec!["gradle"], + } + } +} diff --git a/src/configs/mod.rs b/src/configs/mod.rs index a7717c3ac..88d1d8d97 100644 --- a/src/configs/mod.rs +++ b/src/configs/mod.rs @@ -33,6 +33,7 @@ pub mod git_metrics; pub mod git_state; pub mod git_status; pub mod go; +pub mod gradle; pub mod guix_shell; pub mod haskell; pub mod haxe; @@ -164,6 +165,8 @@ pub struct FullConfig<'a> { #[serde(borrow)] golang: go::GoConfig<'a>, #[serde(borrow)] + gradle: gradle::GradleConfig<'a>, + #[serde(borrow)] guix_shell: guix_shell::GuixShellConfig<'a>, #[serde(borrow)] haskell: haskell::HaskellConfig<'a>, diff --git a/src/configs/starship_root.rs b/src/configs/starship_root.rs index fd67bc65c..3fdd06f68 100644 --- a/src/configs/starship_root.rs +++ b/src/configs/starship_root.rs @@ -58,6 +58,7 @@ pub const PROMPT_ORDER: &[&str] = &[ "elm", "erlang", "golang", + "gradle", "haskell", "haxe", "helm", diff --git a/src/module.rs b/src/module.rs index f0d1a0e0d..64518afd6 100644 --- a/src/module.rs +++ b/src/module.rs @@ -41,6 +41,7 @@ pub const ALL_MODULES: &[&str] = &[ "git_state", "git_status", "golang", + "gradle", "guix_shell", "haskell", "haxe", diff --git a/src/modules/gradle.rs b/src/modules/gradle.rs new file mode 100644 index 000000000..e19c9a4c9 --- /dev/null +++ b/src/modules/gradle.rs @@ -0,0 +1,220 @@ +use crate::{ + config::ModuleConfig, + configs::gradle::GradleConfig, + context::Context, + formatter::{StringFormatter, VersionFormatter}, + module::Module, + utils, +}; + +pub fn module<'a>(context: &'a Context) -> Option> { + let mut module = context.new_module("gradle"); + let config = GradleConfig::try_load(module.config); + let is_gradle_project = context + .try_begin_scan()? + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) + .is_match(); + + if !is_gradle_project { + return None; + } + + let parsed = StringFormatter::new(config.format).and_then(|formatter| { + formatter + .map_meta(|var, _| match var { + "symbol" => Some(config.symbol), + _ => None, + }) + .map_style(|variable| match variable { + "style" => Some(Ok(config.style)), + _ => None, + }) + .map(|variable| match variable { + "version" => { + let gradle_version = { + let properties = get_wrapper_properties_file(context, config.recursive)?; + parse_gradle_version_from_properties(&properties)? + }; + VersionFormatter::format_module_version( + module.get_name(), + &gradle_version, + config.version_format, + ) + .map(Ok) + } + _ => None, + }) + .parse(None, Some(context)) + }); + + module.set_segments(match parsed { + Ok(segments) => segments, + Err(error) => { + log::warn!("Error in module `gradle`:\n{}", error); + return None; + } + }); + + Some(module) +} + +fn parse_gradle_version_from_properties(wrapper_properties: &str) -> Option { + // example gradle.properties content + /* + distributionBase=GRADLE_USER_HOME + distributionPath=wrapper/dists + distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip + zipStoreBase=GRADLE_USER_HOME + zipStorePath=wrapper/dists + */ + let version = wrapper_properties + .lines() + .find(|line| line.starts_with("distributionUrl="))? + .rsplit_once('/')? + .1 + .strip_prefix("gradle-")? + .split_once('-')? + .0; + Some(version.to_string()) +} + +/// Tries to find the gradle-wrapper.properties file. +fn get_wrapper_properties_file(context: &Context, recursive: bool) -> Option { + let mut properties = None; + if context + .try_begin_scan()? + .set_folders(&["gradle"]) + .is_match() + { + properties = utils::read_file( + &context + .current_dir + .join("gradle/wrapper/gradle-wrapper.properties"), + ) + .ok(); + }; + if recursive && properties.is_none() { + for dir in context.current_dir.ancestors().skip(1) { + properties = + utils::read_file(&dir.join("gradle/wrapper/gradle-wrapper.properties")).ok(); + if properties.is_some() { + break; + } + } + } + properties +} + +#[cfg(test)] +mod tests { + use nu_ansi_term::Color; + + use super::*; + use crate::test::ModuleRenderer; + use std::fs::{self, File}; + use std::io::{self, Write}; + + #[test] + fn folder_without_gradle_files() -> io::Result<()> { + let dir = tempfile::tempdir()?; + + let actual = ModuleRenderer::new("gradle").path(dir.path()).collect(); + + let expected = None; + assert_eq!(expected, actual); + dir.close() + } + + #[test] + fn folder_with_gradle_wrapper_properties() -> io::Result<()> { + let dir = tempfile::tempdir()?; + let properties = dir + .path() + .join("gradle") + .join("wrapper") + .join("gradle-wrapper.properties"); + // create gradle/wrapper/ directories + fs::create_dir_all(properties.parent().unwrap())?; + // create build.gradle file to mark it as a gradle project + File::create(dir.path().join("build.gradle"))?.sync_all()?; + let mut file = File::create(properties)?; + file.write_all( + b"\ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists", + )?; + file.sync_all()?; + + let actual = ModuleRenderer::new("gradle").path(dir.path()).collect(); + + let expected = Some(format!( + "via {}", + Color::LightCyan.bold().paint("🅶 v7.5.1 ") + )); + assert_eq!(expected, actual); + dir.close() + } + + #[test] + fn gradle_wrapper_recursive() -> io::Result<()> { + let dir = tempfile::tempdir()?; + let properties = dir + .path() + .join("gradle") + .join("wrapper") + .join("gradle-wrapper.properties"); + // create gradle/wrapper/ directories + fs::create_dir_all(properties.parent().unwrap())?; + // create build.gradle file to mark it as a gradle project + File::create(dir.path().join("build.gradle"))?.sync_all()?; + let mut file = File::create(properties)?; + file.write_all( + b"\ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists", + )?; + file.sync_all()?; + + let target_dir = dir.path().join("working_dir"); + fs::create_dir(&target_dir)?; + File::create(target_dir.join("build.gradle.kts"))?.sync_all()?; + + let actual = ModuleRenderer::new("gradle") + .config(toml::toml! { + [gradle] + recursive = true + }) + .path(target_dir) + .collect(); + + let expected = Some(format!( + "via {}", + Color::LightCyan.bold().paint("🅶 v7.5.1 ") + )); + assert_eq!(expected, actual); + dir.close() + } + + #[test] + fn test_format_wrapper_properties() { + let input = "\ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists + "; + assert_eq!( + parse_gradle_version_from_properties(input), + Some("7.5.1".to_string()) + ); + } +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 12b7f8ddc..8e463aa55 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -30,6 +30,7 @@ mod git_metrics; mod git_state; mod git_status; mod golang; +mod gradle; mod guix_shell; mod haskell; mod haxe; @@ -129,6 +130,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option> { "git_state" => git_state::module(context), "git_status" => git_status::module(context), "golang" => golang::module(context), + "gradle" => gradle::module(context), "guix_shell" => guix_shell::module(context), "haskell" => haskell::module(context), "haxe" => haxe::module(context), @@ -239,6 +241,7 @@ pub fn description(module: &str) -> &'static str { "git_state" => "The current git operation, and it's progress", "git_status" => "Symbol representing the state of the repo", "golang" => "The currently installed version of Golang", + "gradle" => "The currently installed version of Gradle", "guix_shell" => "The guix-shell environment", "haskell" => "The selected version of the Haskell toolchain", "haxe" => "The currently installed version of Haxe", From aa6c2dd5883d1ac6a48774f39a95ab7ee6f7f7ba Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sat, 17 Dec 2022 18:01:27 +0100 Subject: [PATCH 4/5] chore: fix clippy warnings for rust 1.66 (#4715) chore: fix new clippy lints --- src/bug_report.rs | 2 +- src/configs/os.rs | 2 +- src/init/mod.rs | 7 +++---- src/logger.rs | 2 +- src/main.rs | 4 ++-- src/module.rs | 2 +- src/modules/aws.rs | 5 ++--- src/modules/git_branch.rs | 14 ++++++-------- src/modules/haxe.rs | 14 +++++++------- src/modules/hg_branch.rs | 3 +-- src/modules/kubernetes.rs | 10 ++++------ src/modules/mod.rs | 2 +- src/modules/os.rs | 2 +- src/modules/rust.rs | 4 ++-- src/modules/utils/directory_nix.rs | 8 +++++--- src/utils.rs | 8 ++++---- 16 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/bug_report.rs b/src/bug_report.rs index 9d819e4be..39df1691f 100644 --- a/src/bug_report.rs +++ b/src/bug_report.rs @@ -38,7 +38,7 @@ pub fn create() { if input.trim().to_lowercase() == "y" { let link = make_github_issue_link(&issue_body); if let Err(e) = open::that(&link) { - println!("Failed to open issue report in your browser: {}", e); + println!("Failed to open issue report in your browser: {e}"); println!("Please copy the above report and open an issue manually, or try opening the following link:\n{link}"); } } else { diff --git a/src/configs/os.rs b/src/configs/os.rs index 73c84aba9..b42d8f96f 100644 --- a/src/configs/os.rs +++ b/src/configs/os.rs @@ -18,7 +18,7 @@ pub struct OSConfig<'a> { impl<'a> OSConfig<'a> { pub fn get_symbol(&self, key: &Type) -> Option<&'a str> { - self.symbols.get(key).cloned() + self.symbols.get(key).copied() } } diff --git a/src/init/mod.rs b/src/init/mod.rs index 4289727e7..514398936 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -183,7 +183,7 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { "cmd" => print_script(CMDEXE_INIT, &StarshipPath::init()?.sprint_cmdexe()?), _ => { eprintln!( - "{0} is not yet supported by starship.\n\ + "{shell_basename} is not yet supported by starship.\n\ For the time being, we support the following shells:\n\ * bash\n\ * elvish\n\ @@ -197,9 +197,8 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> { * cmd\n\ \n\ Please open an issue in the starship repo if you would like to \ - see support for {0}:\n\ - https://github.com/starship/starship/issues/new\n", - shell_basename + see support for {shell_basename}:\n\ + https://github.com/starship/starship/issues/new\n" ) } }; diff --git a/src/logger.rs b/src/logger.rs index 6a9b80627..ca0c21be1 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -133,6 +133,6 @@ impl log::Log for StarshipLogger { } pub fn init() { - log::set_boxed_logger(Box::new(StarshipLogger::default())).unwrap(); + log::set_boxed_logger(Box::::default()).unwrap(); log::set_max_level(LevelFilter::Trace); } diff --git a/src/main.rs b/src/main.rs index 80830f985..69bff9cfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -184,7 +184,7 @@ fn main() { println!("Supported modules list"); println!("----------------------"); for modules in ALL_MODULES { - println!("{}", modules); + println!("{modules}"); } } if let Some(module_name) = name { @@ -198,7 +198,7 @@ fn main() { configure::update_configuration(&name, &value) } } else if let Err(reason) = configure::edit_configuration(None) { - eprintln!("Could not edit configuration: {}", reason); + eprintln!("Could not edit configuration: {reason}"); std::process::exit(1); } } diff --git a/src/module.rs b/src/module.rs index 64518afd6..a2b2f1b28 100644 --- a/src/module.rs +++ b/src/module.rs @@ -211,7 +211,7 @@ where } } - if let Segment::LineTerm = segment { + if matches!(segment, Segment::LineTerm) { break; } } diff --git a/src/modules/aws.rs b/src/modules/aws.rs index eb9566e1d..014f6b779 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -682,9 +682,8 @@ credential_process = /opt/bin/awscreds-retriever "[astronauts] aws_access_key_id=dummy aws_secret_access_key=dummy -{}={} -", - key, expiration_date +{key}={expiration_date} +" ) .as_bytes(), ) diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index 5d743511a..f57b86572 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -491,10 +491,9 @@ mod tests { toml::from_str(&format!( " [git_branch] - truncation_length = {} - {} - ", - truncate_length, config_options + truncation_length = {truncate_length} + {config_options} + " )) .unwrap(), ) @@ -530,10 +529,9 @@ mod tests { toml::from_str(&format!( r#" [git_branch] - format = "{}" - {} - "#, - format, config_options + format = "{format}" + {config_options} + "# )) .unwrap(), ) diff --git a/src/modules/haxe.rs b/src/modules/haxe.rs index de0a8133c..09d9e5cee 100644 --- a/src/modules/haxe.rs +++ b/src/modules/haxe.rs @@ -132,7 +132,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -151,7 +151,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -173,7 +173,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -201,7 +201,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -230,7 +230,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -260,7 +260,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) @@ -290,7 +290,7 @@ mod tests { "haxe --version", Some(CommandOutput { stdout: "4.3.0-rc.1+\n".to_owned(), - stderr: "".to_owned(), + stderr: String::new(), }), ) .path(dir.path()) diff --git a/src/modules/hg_branch.rs b/src/modules/hg_branch.rs index 0ec4873ab..3aefd4b65 100644 --- a/src/modules/hg_branch.rs +++ b/src/modules/hg_branch.rs @@ -326,8 +326,7 @@ mod tests { let expected = Some(format!( "on {} ", expect_style.paint(format!( - "{} {}{}", - expect_symbol, expect_branch_name, expect_truncation_symbol + "{expect_symbol} {expect_branch_name}{expect_truncation_symbol}" )), )); assert_eq!(expected, actual); diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index e0aee2bce..6fec82d72 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -385,12 +385,11 @@ users: [] apiVersion: v1 clusters: [] contexts: [] -current-context: {} +current-context: {ctx_name} kind: Config preferences: {{}} users: [] -", - ctx_name +" ) .as_bytes(), )?; @@ -695,15 +694,14 @@ clusters: [] contexts: - context: cluster: test_cluster - user: {} + user: {user_name} namespace: test_namespace name: test_context current-context: test_context kind: Config preferences: {{}} users: [] -", - user_name +" ) .as_bytes(), )?; diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 8e463aa55..e9117054d 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -11,7 +11,7 @@ mod cobol; mod conda; mod container; mod crystal; -pub(crate) mod custom; +pub mod custom; mod daml; mod dart; mod deno; diff --git a/src/modules/os.rs b/src/modules/os.rs index aa4d9b93f..77d9d83a0 100644 --- a/src/modules/os.rs +++ b/src/modules/os.rs @@ -77,7 +77,7 @@ fn get_type(os: &os_info::Info) -> Option { fn get_version(os: &os_info::Info) -> Option { Some(os.version()) .filter(|&x| x != &os_info::Version::Unknown) - .map(|x| x.to_string()) + .map(os_info::Version::to_string) } #[cfg(test)] diff --git a/src/modules/rust.rs b/src/modules/rust.rs index b494761fb..5e5a97578 100644 --- a/src/modules/rust.rs +++ b/src/modules/rust.rs @@ -394,7 +394,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option Some(formatted), Err(error) => { log::warn!("Error formatting `rust` version:\n{}", error); - Some(format!("v{}", version)) + Some(format!("v{version}")) } } } @@ -402,7 +402,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option) -> String { default_host_triple .map_or(toolchain, |triple| { - toolchain.trim_end_matches(&format!("-{}", triple)) + toolchain.trim_end_matches(&format!("-{triple}")) }) .to_owned() } diff --git a/src/modules/utils/directory_nix.rs b/src/modules/utils/directory_nix.rs index 920d72cb2..110e5f955 100644 --- a/src/modules/utils/directory_nix.rs +++ b/src/modules/utils/directory_nix.rs @@ -13,6 +13,7 @@ use std::path::Path; /// 2a) (not implemented on macOS) one of the supplementary groups of the current user is the /// directory group owner and whether it has write access /// 3) 'others' part of the access mask has the write access +#[allow(clippy::useless_conversion)] // On some platforms it is not u32 pub fn is_write_allowed(folder_path: &Path) -> Result { let meta = fs::metadata(folder_path).map_err(|e| format!("Unable to stat() directory: {e:?}"))?; @@ -22,14 +23,15 @@ pub fn is_write_allowed(folder_path: &Path) -> Result { if euid.is_root() { return Ok(true); } + if meta.uid() == euid.as_raw() { - Ok(perms & Mode::S_IWUSR.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWUSR.bits()) != 0) } else if (meta.gid() == Gid::effective().as_raw()) || (get_supplementary_groups().contains(&meta.gid())) { - Ok(perms & Mode::S_IWGRP.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWGRP.bits()) != 0) } else { - Ok(perms & Mode::S_IWOTH.bits() as u32 != 0) + Ok(perms & u32::from(Mode::S_IWOTH.bits()) != 0) } } diff --git a/src/utils.rs b/src/utils.rs index 6994290e8..06a5c2701 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -668,8 +668,8 @@ mod tests { fn exec_no_output() { let result = internal_exec_cmd("true", &[] as &[&OsStr], Duration::from_millis(500)); let expected = Some(CommandOutput { - stdout: String::from(""), - stderr: String::from(""), + stdout: String::new(), + stderr: String::new(), }); assert_eq!(result, expected) @@ -682,7 +682,7 @@ mod tests { internal_exec_cmd("/bin/sh", &["-c", "echo hello"], Duration::from_millis(500)); let expected = Some(CommandOutput { stdout: String::from("hello\n"), - stderr: String::from(""), + stderr: String::new(), }); assert_eq!(result, expected) @@ -697,7 +697,7 @@ mod tests { Duration::from_millis(500), ); let expected = Some(CommandOutput { - stdout: String::from(""), + stdout: String::new(), stderr: String::from("hello\n"), }); From 0abf4b937e6bab416321b7460fd642bec40b2d57 Mon Sep 17 00:00:00 2001 From: Martin Weissbach Date: Sun, 18 Dec 2022 03:51:38 +0100 Subject: [PATCH 5/5] docs(config): clarify git-commit tag variable (#4729) The `git_commit` module uses a `tag` variable in its format string, which is not explained in the Variables section of this module. Missing clarification of this `tag` variable is added to the documentation of the `git_commit` module. Fixes starship/4640 --- docs/config/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index 4d1a7161f..5cd20bad1 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1641,10 +1641,11 @@ The `git_commit` module shows the current commit hash and also the tag (if any) ### Variables -| Variable | Example | Description | -| -------- | --------- | ----------------------------------- | -| hash | `b703eb3` | The current git commit hash | -| style\* | | Mirrors the value of option `style` | +| Variable | Example | Description | +| -------- | --------- | -------------------------------------------- | +| hash | `b703eb3` | The current git commit hash | +| tag | `v1.0.0` | The tag name if showing tag info is enabled. | +| style\* | | Mirrors the value of option `style` | *: This variable can only be used as a part of a style string