mirror of
https://github.com/starship/starship.git
synced 2025-01-07 06:58:54 +01:00
Merge branch 'master' into conditional-style
This commit is contained in:
commit
4fd906597f
79
.github/config-schema.json
vendored
79
.github/config-schema.json
vendored
@ -628,6 +628,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,
|
||||
@ -3271,6 +3294,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": {
|
||||
|
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -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",
|
||||
@ -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",
|
||||
|
@ -73,14 +73,14 @@ 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 }
|
||||
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"
|
||||
@ -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]
|
||||
|
@ -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)\]'
|
||||
|
||||
|
@ -37,6 +37,9 @@ format = 'via [$symbol]($style)'
|
||||
[golang]
|
||||
format = 'via [$symbol]($style)'
|
||||
|
||||
[gradle]
|
||||
format = 'via [$symbol]($style)'
|
||||
|
||||
[haxe]
|
||||
format = 'via [$symbol]($style)'
|
||||
|
||||
|
@ -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"
|
||||
|
@ -64,6 +64,9 @@ symbol = "git "
|
||||
[golang]
|
||||
symbol = "go "
|
||||
|
||||
[gradle]
|
||||
symbol = "gradle "
|
||||
|
||||
[guix_shell]
|
||||
symbol = "guix "
|
||||
|
||||
|
@ -291,6 +291,7 @@ $helm\
|
||||
$java\
|
||||
$julia\
|
||||
$kotlin\
|
||||
$gradle\
|
||||
$lua\
|
||||
$nim\
|
||||
$nodejs\
|
||||
@ -1640,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
|
||||
|
||||
@ -1927,6 +1929,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.
|
||||
|
@ -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 {
|
||||
|
36
src/configs/gradle.rs
Normal file
36
src/configs/gradle.rs
Normal file
@ -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"],
|
||||
}
|
||||
}
|
||||
}
|
@ -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>,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ pub const PROMPT_ORDER: &[&str] = &[
|
||||
"elm",
|
||||
"erlang",
|
||||
"golang",
|
||||
"gradle",
|
||||
"haskell",
|
||||
"haxe",
|
||||
"helm",
|
||||
|
@ -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"
|
||||
)
|
||||
}
|
||||
};
|
||||
|
@ -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::<StarshipLogger>::default()).unwrap();
|
||||
log::set_max_level(LevelFilter::Trace);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ pub const ALL_MODULES: &[&str] = &[
|
||||
"git_state",
|
||||
"git_status",
|
||||
"golang",
|
||||
"gradle",
|
||||
"guix_shell",
|
||||
"haskell",
|
||||
"haxe",
|
||||
@ -210,7 +211,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
if let Segment::LineTerm = segment {
|
||||
if matches!(segment, Segment::LineTerm) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
)
|
||||
|
@ -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(),
|
||||
)
|
||||
|
220
src/modules/gradle.rs
Normal file
220
src/modules/gradle.rs
Normal file
@ -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<Module<'a>> {
|
||||
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<String> {
|
||||
// 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<String> {
|
||||
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())
|
||||
);
|
||||
}
|
||||
}
|
@ -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())
|
||||
|
@ -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);
|
||||
|
@ -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(),
|
||||
)?;
|
||||
|
@ -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;
|
||||
@ -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<Module<'a>> {
|
||||
"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",
|
||||
|
@ -77,7 +77,7 @@ fn get_type(os: &os_info::Info) -> Option<String> {
|
||||
fn get_version(os: &os_info::Info) -> Option<String> {
|
||||
Some(os.version())
|
||||
.filter(|&x| x != &os_info::Version::Unknown)
|
||||
.map(|x| x.to_string())
|
||||
.map(os_info::Version::to_string)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -394,7 +394,7 @@ fn format_rustc_version(rustc_version: &str, version_format: &str) -> Option<Str
|
||||
Ok(formatted) => 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<Str
|
||||
fn format_toolchain(toolchain: &str, default_host_triple: Option<&str>) -> String {
|
||||
default_host_triple
|
||||
.map_or(toolchain, |triple| {
|
||||
toolchain.trim_end_matches(&format!("-{}", triple))
|
||||
toolchain.trim_end_matches(&format!("-{triple}"))
|
||||
})
|
||||
.to_owned()
|
||||
}
|
||||
|
@ -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<bool, String> {
|
||||
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<bool, String> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"),
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user