Merge branch 'master' into conditional-style

This commit is contained in:
Filip Bachul 2022-07-21 23:37:25 +02:00
commit eb6352d49c
9 changed files with 403 additions and 73 deletions

View File

@ -4603,6 +4603,12 @@
"default": "\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)",
"type": "string"
},
"pipestatus_segment_format": {
"type": [
"string",
"null"
]
},
"disabled": {
"default": true,
"type": "boolean"

View File

@ -14,7 +14,7 @@ jobs:
- name: Setup | Checkout
uses: actions/checkout@v3
- name: Docs | Format
uses: dprint/check@v2.0
uses: dprint/check@v2.1
# Validate preset files
taplo:

227
Cargo.lock generated
View File

@ -204,6 +204,18 @@ dependencies = [
"byte-tools",
]
[[package]]
name = "bumpalo"
version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
[[package]]
name = "byte-slice-cast"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e"
[[package]]
name = "byte-tools"
version = "0.3.1"
@ -270,9 +282,9 @@ dependencies = [
[[package]]
name = "clap"
version = "3.2.10"
version = "3.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69c5a7f9997be616e47f0577ee38c91decb33392c5be4866494f34cdf329a9aa"
checksum = "54635806b078b7925d6e36810b1755f2a4b5b4d57560432c1ecf60bcbe10602b"
dependencies = [
"atty",
"bitflags",
@ -336,6 +348,12 @@ dependencies = [
"cache-padded",
]
[[package]]
name = "const_fn"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935"
[[package]]
name = "const_format"
version = "0.2.25"
@ -362,7 +380,17 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
dependencies = [
"core-foundation-sys",
"core-foundation-sys 0.7.0",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
dependencies = [
"core-foundation-sys 0.8.3",
"libc",
]
@ -372,6 +400,12 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cpufeatures"
version = "0.2.2"
@ -864,6 +898,18 @@ dependencies = [
"winapi",
]
[[package]]
name = "iana-time-zone"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8185498dab35f87e740e2a878ec92b2241ef2c12ac85680f8ba7491f1ed76b"
dependencies = [
"core-foundation 0.9.3",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "idna"
version = "0.2.3"
@ -931,6 +977,15 @@ dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -1122,9 +1177,9 @@ dependencies = [
[[package]]
name = "nix"
version = "0.24.1"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
@ -1269,9 +1324,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "open"
version = "3.0.1"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "360bcc8316bf6363aa3954c3ccc4de8add167b087e0259190a043c9514f910fe"
checksum = "f23a407004a1033f53e93f9b45580d14de23928faad187384f891507c9b0c045"
dependencies = [
"pathdiff",
"windows-sys",
@ -1431,7 +1486,16 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12"
dependencies = [
"phf_shared",
"phf_shared 0.8.0",
]
[[package]]
name = "phf"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
dependencies = [
"phf_shared 0.10.0",
]
[[package]]
@ -1441,7 +1505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815"
dependencies = [
"phf_generator",
"phf_shared",
"phf_shared 0.8.0",
]
[[package]]
@ -1450,7 +1514,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
dependencies = [
"phf_shared",
"phf_shared 0.8.0",
"rand 0.7.3",
]
@ -1463,6 +1527,15 @@ dependencies = [
"siphasher",
]
[[package]]
name = "phf_shared"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
dependencies = [
"siphasher",
]
[[package]]
name = "pin-project-lite"
version = "0.2.9"
@ -1841,18 +1914,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.139"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.139"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb"
checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [
"proc-macro2",
"quote",
@ -1945,14 +2018,15 @@ dependencies = [
[[package]]
name = "shadow-rs"
version = "0.12.0"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed1b83da0a4e48d8dcc13ad177b64f2fc40097974f9bf176c2bcb702cabadff3"
checksum = "700d9f534a341a3ed1322dd10cd04daefcb229bc09b44a83ee20873dfa03d292"
dependencies = [
"chrono",
"const_format",
"git2",
"is_debug",
"time 0.3.11",
"tzdb",
]
[[package]]
@ -2047,7 +2121,7 @@ dependencies = [
"local_ipaddress",
"log",
"mockall",
"nix 0.24.1",
"nix 0.24.2",
"notify-rust",
"once_cell",
"open",
@ -2080,7 +2154,7 @@ dependencies = [
"urlencoding",
"versions",
"which",
"windows 0.38.0",
"windows 0.39.0",
"winres",
"yaml-rust",
]
@ -2092,7 +2166,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3336198ad004af4447ae69be4f4e562c26814570f8f0c1e37858405a294e015d"
dependencies = [
"cfg-if 1.0.0",
"core-foundation",
"core-foundation 0.7.0",
"lazycell",
"libc",
"mach",
@ -2202,7 +2276,7 @@ dependencies = [
"dirs 2.0.2",
"fnv",
"nom 5.1.2",
"phf",
"phf 0.8.0",
"phf_codegen",
]
@ -2299,6 +2373,7 @@ version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217"
dependencies = [
"itoa",
"libc",
"num_threads",
]
@ -2377,6 +2452,28 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "tz-rs"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb454313e3d79601e2116bb6c7a93ec0eda1dbb52f9204f831f897204182c5f"
dependencies = [
"const_fn",
]
[[package]]
name = "tzdb"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02a29f1fbaa871320d9d6c81e19c650837a3959cf463472408c934c49af7df5f"
dependencies = [
"byte-slice-cast",
"iana-time-zone",
"phf 0.10.1",
"phf_shared 0.10.0",
"tz-rs",
]
[[package]]
name = "ucd-trie"
version = "0.1.3"
@ -2530,6 +2627,60 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be"
[[package]]
name = "wepoll-ffi"
version = "0.1.2"
@ -2595,15 +2746,15 @@ dependencies = [
[[package]]
name = "windows"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c47017195a790490df51a3e27f669a7d4f285920d90d03ef970c5d886ef0af1"
checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a"
dependencies = [
"windows_aarch64_msvc 0.38.0",
"windows_i686_gnu 0.38.0",
"windows_i686_msvc 0.38.0",
"windows_x86_64_gnu 0.38.0",
"windows_x86_64_msvc 0.38.0",
"windows_aarch64_msvc 0.39.0",
"windows_i686_gnu 0.39.0",
"windows_i686_msvc 0.39.0",
"windows_x86_64_gnu 0.39.0",
"windows_x86_64_msvc 0.39.0",
]
[[package]]
@ -2627,9 +2778,9 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_aarch64_msvc"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b12add87e2fb192fff3f4f7e4342b3694785d79f3a64e2c20d5ceb5ccbcfc3cd"
checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2"
[[package]]
name = "windows_i686_gnu"
@ -2645,9 +2796,9 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_gnu"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c98f2db372c23965c5e0f43896a8f0316dc0fbe48d1aa65bea9bdd295d43c15"
checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b"
[[package]]
name = "windows_i686_msvc"
@ -2663,9 +2814,9 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_i686_msvc"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdf0569be0f2863ab6a12a6ba841fcfa7d107cbc7545a3ebd57685330db0a3ff"
checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106"
[[package]]
name = "windows_x86_64_gnu"
@ -2681,9 +2832,9 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "905858262c8380a36f32cb8c1990d7e7c3b7a8170e58ed9a98ca6d940b7ea9f1"
checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65"
[[package]]
name = "windows_x86_64_msvc"
@ -2699,9 +2850,9 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "windows_x86_64_msvc"
version = "0.38.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "890c3c6341d441ffb38f705f47196e3665dc6dd79f6d72fa185d937326730561"
checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809"
[[package]]
name = "winres"

View File

@ -38,7 +38,7 @@ notify = ["notify-rust"]
[dependencies]
ansi_term = "0.12.1"
chrono = "0.4.19"
clap = { version = "=3.2.10", features = ["derive", "cargo", "unicode", "unstable-v4"] }
clap = { version = "=3.2.14", features = ["derive", "cargo", "unicode", "unstable-v4"] }
clap_complete = "3.2.3"
dirs-next = "2.0.0"
dunce = "1.0.2"
@ -51,7 +51,7 @@ log = { version = "0.4.16", features = ["std"] }
# see: https://github.com/NixOS/nixpkgs/issues/160876
notify-rust = { version = "4.5.8", optional = true }
once_cell = "1.13.0"
open = "3.0.1"
open = "3.0.2"
os_info = "3.4.0"
path-slash = "0.2.0"
pest = "2.1.3"
@ -62,10 +62,10 @@ rayon = "1.5.3"
regex = "1.6.0"
rust-ini = "0.18.0"
semver = "1.0.12"
serde = { version = "1.0.139", features = ["derive"] }
serde = { version = "1.0.140", features = ["derive"] }
serde_json = "1.0.82"
sha-1 = "0.10.0"
shadow-rs = "0.12.0"
shadow-rs = "0.16.0"
# 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 }
@ -96,7 +96,7 @@ features = ["preserve_order", "indexmap"]
deelevate = "0.2.0"
[target.'cfg(windows)'.dependencies.windows]
version = "0.38.0"
version = "0.39.0"
features = [
"Win32_Foundation",
"Win32_UI_Shell",
@ -106,10 +106,10 @@ features = [
]
[target.'cfg(not(windows))'.dependencies]
nix = { version = "0.24.1", default-features = false, features = ["feature", "fs", "user"] }
nix = { version = "0.24.2", default-features = false, features = ["feature", "fs", "user"] }
[build-dependencies]
shadow-rs = "0.12.0"
shadow-rs = "0.16.0"
[target.'cfg(windows)'.build-dependencies]
winres = "0.1.12"

View File

@ -3322,22 +3322,23 @@ To enable it, set `disabled` to `false` in your configuration file.
### Options
| Option | Default | Description |
| ----------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------- |
| `format` | `"[$symbol$status]($style) "` | The format of the module |
| `symbol` | `"✖"` | The symbol displayed on program error |
| `success_symbol` | `""` | The symbol displayed on program success |
| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable |
| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found |
| `sigint_symbol` | `"🧱"` | The symbol displayed on SIGINT (Ctrl + c) |
| `signal_symbol` | `"⚡"` | The symbol displayed on any signal |
| `style` | `"bold red"` | The style for the module. |
| `recognize_signal_code` | `true` | Enable signal mapping from exit code |
| `map_symbol` | `false` | Enable symbols mapping from exit code |
| `pipestatus` | `false` | Enable pipestatus reporting |
| `pipestatus_separator` | ` | ` |
| `pipestatus_format` | `\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)` | The format of the module when the command is a pipeline |
| `disabled` | `true` | Disables the `status` module. |
| Option | Default | Description |
| --------------------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `format` | `"[$symbol$status]($style) "` | The format of the module |
| `symbol` | `"✖"` | The symbol displayed on program error |
| `success_symbol` | `""` | The symbol displayed on program success |
| `not_executable_symbol` | `"🚫"` | The symbol displayed when file isn't executable |
| `not_found_symbol` | `"🔍"` | The symbol displayed when the command can't be found |
| `sigint_symbol` | `"🧱"` | The symbol displayed on SIGINT (Ctrl + c) |
| `signal_symbol` | `"⚡"` | The symbol displayed on any signal |
| `style` | `"bold red"` | The style for the module. |
| `recognize_signal_code` | `true` | Enable signal mapping from exit code |
| `map_symbol` | `false` | Enable symbols mapping from exit code |
| `pipestatus` | `false` | Enable pipestatus reporting |
| `pipestatus_separator` | <code>&vert;</code> | The symbol used to separate pipestatus segments |
| `pipestatus_format` | `\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)` | The format of the module when the command is a pipeline |
| `pipestatus_segment_format` | | When specified, replaces `format` when formatting pipestatus segments |
| `disabled` | `true` | Disables the `status` module. |
### Variables

View File

@ -17,6 +17,8 @@ pub struct StatusConfig<'a> {
pub pipestatus: bool,
pub pipestatus_separator: &'a str,
pub pipestatus_format: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
pub pipestatus_segment_format: Option<&'a str>,
pub disabled: bool,
}
@ -37,6 +39,7 @@ impl<'a> Default for StatusConfig<'a> {
pipestatus_separator: "|",
pipestatus_format:
"\\[$pipestatus\\] => [$symbol$common_meaning$signal_name$maybe_int]($style)",
pipestatus_segment_format: None,
disabled: true,
}
}

View File

@ -7,6 +7,8 @@ use quick_xml::events::Event as QXEvent;
use quick_xml::Reader as QXReader;
use regex::Regex;
use serde_json as json;
use std::fs;
use std::io::Read;
/// Creates a module with the current package version
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
@ -213,10 +215,45 @@ fn get_sbt_version(context: &Context, config: &PackageConfig) -> Option<String>
}
fn get_cargo_version(context: &Context, config: &PackageConfig) -> Option<String> {
let file_contents = context.read_file_from_pwd("Cargo.toml")?;
let mut file_contents = context.read_file_from_pwd("Cargo.toml")?;
let cargo_toml: toml::Value = toml::from_str(&file_contents).ok()?;
let raw_version = cargo_toml.get("package")?.get("version")?.as_str()?;
let mut cargo_toml: toml::Value = toml::from_str(&file_contents).ok()?;
let cargo_version = cargo_toml.get("package").and_then(|p| p.get("version"));
let raw_version = if let Some(v) = cargo_version.and_then(|v| v.as_str()) {
// regular version string
v
} else if cargo_version
.and_then(|v| v.get("workspace"))
.and_then(|w| w.as_bool())
.unwrap_or_default()
{
// workspace version string (`package.version.worspace = true`)
// need to read the Cargo.toml file from the workspace root
let mut version = None;
// disover the workspace root
for path in context.current_dir.ancestors().skip(1) {
// Assume the workspace root is the first ancestor that contains a Cargo.toml file
if let Ok(mut file) = fs::File::open(path.join("Cargo.toml")) {
file.read_to_string(&mut file_contents).ok()?;
cargo_toml = toml::from_str(&file_contents).ok()?;
// Read workspace.package.version
version = cargo_toml
.get("workspace")?
.get("package")?
.get("version")?
.as_str();
break;
}
}
version?
} else {
// This might be a workspace file
cargo_toml
.get("workspace")?
.get("package")?
.get("version")?
.as_str()?
};
format_version(raw_version, config.version_format)
}
@ -356,6 +393,88 @@ mod tests {
project_dir.close()
}
#[test]
fn test_extract_cargo_version_ws() -> io::Result<()> {
let ws_config_name = "Cargo.toml";
let ws_config_content = toml::toml! {
[workspace.package]
version = "0.1.0"
}
.to_string();
let config_name = "member/Cargo.toml";
let config_content = toml::toml! {
[package]
version.workspace = true
}
.to_string();
let project_dir = create_project_dir()?;
fs::create_dir(project_dir.path().join("member"))?;
fill_config(&project_dir, ws_config_name, Some(&ws_config_content))?;
fill_config(&project_dir, config_name, Some(&config_content))?;
// Version can be read both from the workspace and the member.
expect_output(&project_dir, Some("v0.1.0"), None);
let actual = ModuleRenderer::new("package")
.path(project_dir.path().join("member"))
.collect();
let expected = Some(format!(
"is {} ",
Color::Fixed(208).bold().paint("📦 v0.1.0")
));
assert_eq!(actual, expected);
project_dir.close()
}
#[test]
fn test_extract_cargo_version_ws_false() -> io::Result<()> {
let ws_config_name = "Cargo.toml";
let ws_config_content = toml::toml! {
[workspace.package]
version = "0.1.0"
}
.to_string();
let config_name = "member/Cargo.toml";
let config_content = toml::toml! {
[package]
version.workspace = false
}
.to_string();
let project_dir = create_project_dir()?;
fs::create_dir(project_dir.path().join("member"))?;
fill_config(&project_dir, ws_config_name, Some(&ws_config_content))?;
fill_config(&project_dir, config_name, Some(&config_content))?;
// Version can be read both from the workspace and the member.
let actual = ModuleRenderer::new("package")
.path(project_dir.path().join("member"))
.collect();
let expected = None;
assert_eq!(actual, expected);
project_dir.close()
}
#[test]
fn test_extract_cargo_version_ws_missing_parent() -> io::Result<()> {
let config_name = "Cargo.toml";
let config_content = toml::toml! {
[package]
name = "starship"
version.workspace = true
}
.to_string();
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(&config_content))?;
expect_output(&project_dir, None, None);
project_dir.close()
}
#[test]
fn test_extract_nimble_package_version() -> io::Result<()> {
let config_name = "test_project.nimble";

View File

@ -55,9 +55,10 @@ impl RustToolingEnvironmentInfo {
// To display appropriate versions preventing `rustc` from downloading toolchains, we have to
// check
// 1. `$RUSTUP_TOOLCHAIN`
// 2. `rustup override list`
// 2. The override list from ~/.rustup/settings.toml (like `rustup override list`)
// 3. `rust-toolchain` or `rust-toolchain.toml` in `.` or parent directories
// 4. `rustup default`
// 4. The `default_toolchain` from ~/.rustup/settings.toml (like `rustup default`)
// 5. `rustup default` (in addition to the above, this also looks at global fallback config files)
// as `rustup` does.
// https://github.com/rust-lang/rustup.rs/tree/eb694fcada7becc5d9d160bf7c623abe84f8971d#override-precedence
//
@ -74,6 +75,11 @@ impl RustToolingEnvironmentInfo {
.lookup_override(context.current_dir.as_path())
})
.or_else(|| find_rust_toolchain_file(context))
.or_else(|| {
self.get_rustup_settings(context)
.default_toolchain()
.map(std::string::ToString::to_string)
})
.or_else(|| execute_rustup_default(context));
log::debug!("Environmental toolchain override is {:?}", out);
@ -87,12 +93,32 @@ impl RustToolingEnvironmentInfo {
fn get_rustup_rustc_version(&self, context: &Context) -> &RustupRunRustcVersionOutcome {
self.rustup_rustc_output.get_or_init(|| {
let out = if let Some(toolchain) = self.get_env_toolchain_override(context) {
create_command("rustup")
.and_then(|mut cmd| {
cmd.args(&["run", toolchain, "rustc", "--version"])
.current_dir(&context.current_dir)
.output()
// First try runnig ~/.rustup/toolchains/<toolchain>/bin/rustc --version
rustup_home()
.map(|rustup_folder| {
rustup_folder
.join("toolchains")
.join(toolchain)
.join("bin")
.join("rustc")
})
.and_then(|rustc| {
log::trace!("Running rustc --version directly with {:?}", rustc);
create_command(rustc).map(|mut cmd| {
cmd.arg("--version");
cmd
})
})
.or_else(|_| {
// If that fails, try running rustup rustup run <toolchain> rustc --version
// Depending on the source of the toolchain override, it might not have been a full toolchain name ("stable" or "nightly").
log::trace!("Running rustup {toolchain} rustc --version");
create_command("rustup").map(|mut cmd| {
cmd.args(&["run", toolchain, "rustc", "--version"]);
cmd
})
})
.and_then(|mut cmd| cmd.current_dir(&context.current_dir).output())
.map(extract_toolchain_from_rustup_run_rustc_version)
.unwrap_or(RustupRunRustcVersionOutcome::RustupNotWorking)
} else {

View File

@ -54,12 +54,14 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
let segment_format = config.pipestatus_segment_format.unwrap_or(config.format);
// Create pipestatus string
let pipestatus = match pipestatus_status {
PipeStatusStatus::Pipe(pipestatus) => pipestatus
.iter()
.map(
|ec| match format_exit_code(ec.as_str(), config.format, None, &config, context) {
|ec| match format_exit_code(ec.as_str(), segment_format, None, &config, context) {
Ok(segments) => segments
.into_iter()
.map(|s| s.to_string())
@ -684,4 +686,26 @@ mod tests {
assert_eq!(expected, actual);
}
}
#[test]
fn pipestatus_segment_format() {
let pipe_exit_code = &[0, 1];
let main_exit_code = 1;
let expected = Some("[0]|[1] => <1>".to_string());
let actual = ModuleRenderer::new("status")
.config(toml::toml! {
[status]
format = "\\($status\\)"
pipestatus = true
pipestatus_separator = "|"
pipestatus_format = "$pipestatus => <$status>"
pipestatus_segment_format = "\\[$status\\]"
disabled = false
})
.status(main_exit_code)
.pipestatus(pipe_exit_code)
.collect();
assert_eq!(expected, actual);
}
}