mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Initial implementation for uutils uname (#11684)
Hi, This PR aims at implementing the first iteration for `uname` using `uutils`. Couple of things: * Currently my [PR](https://github.com/uutils/coreutils/pull/5921) to make the required changes is pending in `uutils` repo. * I guess the number of flags has to be investigated. Still the tests cover all of them. <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - [X] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [X] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [X] `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - [X] `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
parent
87c5f6e455
commit
838fc7e098
8 changed files with 180 additions and 26 deletions
74
Cargo.lock
generated
74
Cargo.lock
generated
|
@ -2176,9 +2176,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.152"
|
version = "0.2.153"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
|
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libflate"
|
name = "libflate"
|
||||||
|
@ -2636,6 +2636,18 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.28.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.4.2",
|
||||||
|
"cfg-if",
|
||||||
|
"cfg_aliases",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
|
@ -2957,6 +2969,7 @@ dependencies = [
|
||||||
"uu_mkdir",
|
"uu_mkdir",
|
||||||
"uu_mktemp",
|
"uu_mktemp",
|
||||||
"uu_mv",
|
"uu_mv",
|
||||||
|
"uu_uname",
|
||||||
"uu_whoami",
|
"uu_whoami",
|
||||||
"uucore",
|
"uucore",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
@ -3780,6 +3793,16 @@ dependencies = [
|
||||||
"array-init-cursor",
|
"array-init-cursor",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "platform-info"
|
||||||
|
version = "2.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6259c4860e53bf665016f1b2f46a8859cadfa717581dc9d597ae4069de6300f"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "polars"
|
name = "polars"
|
||||||
version = "0.37.0"
|
version = "0.37.0"
|
||||||
|
@ -5510,9 +5533,9 @@ checksum = "cfb5fa503293557c5158bd215fdc225695e567a77e453f5d4452a50a193969bd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.10.0"
|
version = "3.10.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67"
|
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
|
@ -5983,9 +6006,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_cp"
|
name = "uu_cp"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "927869e2df48ac2f09ebc083459e96efc97028863a41dce96cfe8164c5c722ba"
|
checksum = "fcbe045dc92209114afdfd366bd18f7b95dbf999f3eaa85ad6dca910b0be3d56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"filetime",
|
"filetime",
|
||||||
|
@ -5999,9 +6022,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_mkdir"
|
name = "uu_mkdir"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d303b73c3a1ede83101c4a01c7f2f72f000ec9241a5d788ceba6a91a9ce1cb3"
|
checksum = "040aa4584036b2f65e05387b0ea9ac468afce1db325743ce5f350689fd9ce4ae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"uucore",
|
"uucore",
|
||||||
|
@ -6009,9 +6032,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_mktemp"
|
name = "uu_mktemp"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c7e25b0928c96297836d3400c049d7c772073d0534720e4d13dd0e4a6ed52349"
|
checksum = "f240a99c36d768153874d198c43605a45c86996b576262689a0f18248cc3bc57"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"rand",
|
"rand",
|
||||||
|
@ -6021,9 +6044,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_mv"
|
name = "uu_mv"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ec472139edb0e91d9706779bfdf45814b139d8b23bea2ad0feaaac1fb6c1523"
|
checksum = "0c99fd7c75e6e85553c92537314be3d9a64b4927051aa1608513feea2f933022"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
|
@ -6032,10 +6055,21 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_whoami"
|
name = "uu_uname"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "521f16cb67ba9f55341e00cd6b806556cefef430e9d80ea425607628da3a40e5"
|
checksum = "5951832d73199636bde6c0d61cf960932b3c4450142c290375bc10c7abed6db5"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"platform-info",
|
||||||
|
"uucore",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uu_whoami"
|
||||||
|
version = "0.0.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3b44166eb6335aeac42744ea368cc4c32d3f2287a4ff765a5ce44d927ab8bb4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -6045,15 +6079,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uucore"
|
name = "uucore"
|
||||||
version = "0.0.24"
|
version = "0.0.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d5de2eba1364f6274f35f121eb8671b98ac5fa8fe1271694721e17034e85e8bc"
|
checksum = "23994a722acb43dbc56877e271c9723f167ae42c4c089f909b2d7dd106c3a9b4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dunce",
|
"dunce",
|
||||||
"glob",
|
"glob",
|
||||||
"libc",
|
"libc",
|
||||||
"nix 0.27.1",
|
"nix 0.28.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"os_display",
|
"os_display",
|
||||||
"uucore_procs",
|
"uucore_procs",
|
||||||
|
@ -6162,9 +6196,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.4.0"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
|
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"same-file",
|
"same-file",
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
|
|
13
Cargo.toml
13
Cargo.toml
|
@ -147,12 +147,13 @@ unicode-segmentation = "1.11"
|
||||||
unicode-width = "0.1"
|
unicode-width = "0.1"
|
||||||
ureq = { version = "2.9", default-features = false }
|
ureq = { version = "2.9", default-features = false }
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
uu_cp = "0.0.24"
|
uu_cp = "0.0.25"
|
||||||
uu_mkdir = "0.0.24"
|
uu_mkdir = "0.0.25"
|
||||||
uu_mktemp = "0.0.24"
|
uu_mktemp = "0.0.25"
|
||||||
uu_mv = "0.0.24"
|
uu_mv = "0.0.25"
|
||||||
uu_whoami = "0.0.24"
|
uu_whoami = "0.0.25"
|
||||||
uucore = "0.0.24"
|
uu_uname = "0.0.25"
|
||||||
|
uucore = "0.0.25"
|
||||||
uuid = "1.8.0"
|
uuid = "1.8.0"
|
||||||
v_htmlescape = "0.15.0"
|
v_htmlescape = "0.15.0"
|
||||||
wax = "0.6"
|
wax = "0.6"
|
||||||
|
|
|
@ -91,6 +91,7 @@ uu_cp = { workspace = true }
|
||||||
uu_mkdir = { workspace = true }
|
uu_mkdir = { workspace = true }
|
||||||
uu_mktemp = { workspace = true }
|
uu_mktemp = { workspace = true }
|
||||||
uu_mv = { workspace = true }
|
uu_mv = { workspace = true }
|
||||||
|
uu_uname = { workspace = true }
|
||||||
uu_whoami = { workspace = true }
|
uu_whoami = { workspace = true }
|
||||||
uuid = { workspace = true, features = ["v4"] }
|
uuid = { workspace = true, features = ["v4"] }
|
||||||
v_htmlescape = { workspace = true }
|
v_htmlescape = { workspace = true }
|
||||||
|
|
|
@ -122,6 +122,8 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
|
||||||
Exec,
|
Exec,
|
||||||
NuCheck,
|
NuCheck,
|
||||||
Sys,
|
Sys,
|
||||||
|
UName,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Help
|
// Help
|
||||||
|
|
|
@ -13,6 +13,7 @@ mod ps;
|
||||||
mod registry_query;
|
mod registry_query;
|
||||||
mod run_external;
|
mod run_external;
|
||||||
mod sys;
|
mod sys;
|
||||||
|
mod uname;
|
||||||
mod which_;
|
mod which_;
|
||||||
|
|
||||||
pub use complete::Complete;
|
pub use complete::Complete;
|
||||||
|
@ -30,4 +31,5 @@ pub use ps::Ps;
|
||||||
pub use registry_query::RegistryQuery;
|
pub use registry_query::RegistryQuery;
|
||||||
pub use run_external::{External, ExternalCommand};
|
pub use run_external::{External, ExternalCommand};
|
||||||
pub use sys::Sys;
|
pub use sys::Sys;
|
||||||
|
pub use uname::UName;
|
||||||
pub use which_::Which;
|
pub use which_::Which;
|
||||||
|
|
100
crates/nu-command/src/system/uname.rs
Normal file
100
crates/nu-command/src/system/uname.rs
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
use nu_protocol::record;
|
||||||
|
use nu_protocol::Value;
|
||||||
|
use nu_protocol::{
|
||||||
|
ast::Call,
|
||||||
|
engine::{Command, EngineState, Stack},
|
||||||
|
Category, Example, PipelineData, ShellError, Signature, Type,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct UName;
|
||||||
|
|
||||||
|
impl Command for UName {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"uname"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("uname")
|
||||||
|
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
|
||||||
|
.category(Category::System)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Print certain system information."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
// add other terms?
|
||||||
|
vec!["system"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
_engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
|
call: &Call,
|
||||||
|
_input: PipelineData,
|
||||||
|
) -> Result<PipelineData, ShellError> {
|
||||||
|
let span = call.head;
|
||||||
|
// Simulate `uname -all` is called every time
|
||||||
|
let opts = uu_uname::Options {
|
||||||
|
all: true,
|
||||||
|
kernel_name: false,
|
||||||
|
nodename: false,
|
||||||
|
kernel_release: false,
|
||||||
|
kernel_version: false,
|
||||||
|
machine: false,
|
||||||
|
processor: false,
|
||||||
|
hardware_platform: false,
|
||||||
|
os: false,
|
||||||
|
};
|
||||||
|
let output = uu_uname::UNameOutput::new(&opts).map_err(|e| ShellError::GenericError {
|
||||||
|
error: format!("{}", e),
|
||||||
|
msg: format!("{}", e),
|
||||||
|
span: None,
|
||||||
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
|
})?;
|
||||||
|
let outputs = [
|
||||||
|
output.kernel_name,
|
||||||
|
output.nodename,
|
||||||
|
output.kernel_release,
|
||||||
|
output.kernel_version,
|
||||||
|
output.machine,
|
||||||
|
output.os,
|
||||||
|
];
|
||||||
|
let outputs = outputs
|
||||||
|
.iter()
|
||||||
|
.map(|name| {
|
||||||
|
Ok(name
|
||||||
|
.as_ref()
|
||||||
|
.ok_or("unknown")
|
||||||
|
.map_err(|_| ShellError::NotFound { span })?
|
||||||
|
.to_string())
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<String>, ShellError>>()?;
|
||||||
|
Ok(PipelineData::Value(
|
||||||
|
Value::record(
|
||||||
|
record! {
|
||||||
|
"kernel-name" => Value::string(outputs[0].clone(), span),
|
||||||
|
"nodename" => Value::string(outputs[1].clone(), span),
|
||||||
|
"kernel-release" => Value::string(outputs[2].clone(), span),
|
||||||
|
"kernel-version" => Value::string(outputs[3].clone(), span),
|
||||||
|
"machine" => Value::string(outputs[4].clone(), span),
|
||||||
|
"operating-system" => Value::string(outputs[5].clone(), span),
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Print all information",
|
||||||
|
example: "uname",
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
|
@ -111,7 +111,9 @@ mod try_;
|
||||||
mod ucp;
|
mod ucp;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
mod ulimit;
|
mod ulimit;
|
||||||
|
|
||||||
mod umkdir;
|
mod umkdir;
|
||||||
|
mod uname;
|
||||||
mod uniq;
|
mod uniq;
|
||||||
mod uniq_by;
|
mod uniq_by;
|
||||||
mod update;
|
mod update;
|
||||||
|
|
12
crates/nu-command/tests/commands/uname.rs
Normal file
12
crates/nu-command/tests/commands/uname.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use nu_test_support::nu;
|
||||||
|
use nu_test_support::playground::Playground;
|
||||||
|
#[test]
|
||||||
|
fn test_uname_all() {
|
||||||
|
Playground::setup("uname_test_1", |dirs, _| {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
"uname"
|
||||||
|
);
|
||||||
|
assert!(actual.status.success())
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue