Making coreutils umkdir as the default mkdir (#12007)

<!--
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.
-->
`umkdir` was added in #10785, I think it's time to replace the default
one.

# After Submitting

Remove the old `mkdir` command and making coreutils' `umkdir` as the
default
This commit is contained in:
Justin Ma
2024-02-28 20:27:10 +08:00
committed by GitHub
parent bf425874b8
commit 7b95e37bbe
7 changed files with 20 additions and 257 deletions

View File

@ -203,7 +203,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
bind_command! {
Cd,
Ls,
Mkdir,
UMkdir,
Mktemp,
Mv,

View File

@ -1,108 +0,0 @@
use std::collections::VecDeque;
use nu_engine::env::current_dir;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature,
SyntaxShape, Type, Value,
};
#[derive(Clone)]
pub struct Mkdir;
impl Command for Mkdir {
fn name(&self) -> &str {
"mkdir"
}
fn signature(&self) -> Signature {
Signature::build("mkdir")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.rest(
"rest",
SyntaxShape::Directory,
"The name(s) of the path(s) to create.",
)
.switch("verbose", "print created path(s).", Some('v'))
.category(Category::FileSystem)
}
fn usage(&self) -> &str {
"Make directories, creates intermediary directories as required."
}
fn search_terms(&self) -> Vec<&str> {
vec!["directory", "folder", "create", "make_dirs"]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let path = current_dir(engine_state, stack)?;
let mut directories = call
.rest::<String>(engine_state, stack, 0)?
.into_iter()
.map(|dir| path.join(dir))
.peekable();
let is_verbose = call.has_flag(engine_state, stack, "verbose")?;
let mut stream: VecDeque<Value> = VecDeque::new();
if directories.peek().is_none() {
return Err(ShellError::MissingParameter {
param_name: "requires directory paths".to_string(),
span: call.head,
});
}
for (i, dir) in directories.enumerate() {
let span = call
.positional_nth(i)
.expect("already checked through directories")
.span;
let dir_res = std::fs::create_dir_all(&dir);
if let Err(reason) = dir_res {
return Err(ShellError::CreateNotPossible {
msg: format!("failed to create directory: {reason}"),
span: call
.positional_nth(i)
.expect("already checked through directories")
.span,
});
}
if is_verbose {
let val = format!("{:}", dir.to_string_lossy());
stream.push_back(Value::string(val, span));
}
}
stream
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone())
.print_not_formatted(engine_state, false, true)?;
Ok(PipelineData::empty())
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Make a directory named foo",
example: "mkdir foo",
result: None,
},
Example {
description: "Make multiple directories and show the paths created",
example: "mkdir -v foo/bar foo2",
result: None,
},
]
}
}

View File

@ -2,7 +2,6 @@ mod cd;
mod du;
mod glob;
mod ls;
mod mkdir;
mod mktemp;
mod mv;
mod open;
@ -21,7 +20,6 @@ pub use cd::Cd;
pub use du::Du;
pub use glob::Glob;
pub use ls::Ls;
pub use mkdir::Mkdir;
pub use mktemp::Mktemp;
pub use mv::Mv;
pub use rm::Rm;

View File

@ -16,7 +16,7 @@ const DEFAULT_MODE: u32 = 0o777;
impl Command for UMkdir {
fn name(&self) -> &str {
"umkdir"
"mkdir"
}
fn usage(&self) -> &str {
@ -28,7 +28,7 @@ impl Command for UMkdir {
}
fn signature(&self) -> Signature {
Signature::build("umkdir")
Signature::build("mkdir")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.rest(
"rest",
@ -85,12 +85,12 @@ impl Command for UMkdir {
vec![
Example {
description: "Make a directory named foo",
example: "umkdir foo",
example: "mkdir foo",
result: None,
},
Example {
description: "Make multiple directories and show the paths created",
example: "umkdir -v foo/bar foo2",
example: "mkdir -v foo/bar foo2",
result: None,
},
]