mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
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:
parent
bf425874b8
commit
7b95e37bbe
@ -203,7 +203,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
|
||||
bind_command! {
|
||||
Cd,
|
||||
Ls,
|
||||
Mkdir,
|
||||
UMkdir,
|
||||
Mktemp,
|
||||
Mv,
|
||||
|
@ -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,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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,
|
||||
},
|
||||
]
|
||||
|
@ -1,125 +0,0 @@
|
||||
use nu_test_support::fs::files_exist_at;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn creates_directory() {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir my_new_directory"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("my_new_directory");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_and_creates_directories() {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir dir_1 dir_2 dir_3"
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
||||
dirs.test()
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_intermediary_directories() {
|
||||
Playground::setup("mkdir_test_3", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir some_folder/another/deeper_one"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("some_folder/another/deeper_one");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_directory_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("mkdir_test_4", |dirs, sandbox| {
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
"mkdir .../boo"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("boo");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn print_created_paths() {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline(
|
||||
"mkdir -v dir_1 dir_2 dir_3"
|
||||
));
|
||||
|
||||
assert!(files_exist_at(
|
||||
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
|
||||
dirs.test()
|
||||
));
|
||||
|
||||
assert!(actual.err.contains("dir_1"));
|
||||
assert!(actual.err.contains("dir_2"));
|
||||
assert!(actual.err.contains("dir_3"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_directory_three_dots() {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir test..."
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test...");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_directory_four_dots() {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir test...."
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test....");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn creates_directory_three_dots_quotation_marks() {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mkdir 'test...'"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test...");
|
||||
|
||||
assert!(expected.exists());
|
||||
})
|
||||
}
|
@ -60,7 +60,6 @@ mod ls;
|
||||
mod match_;
|
||||
mod math;
|
||||
mod merge;
|
||||
mod mkdir;
|
||||
mod mktemp;
|
||||
mod move_;
|
||||
mod mut_;
|
||||
|
@ -5,10 +5,10 @@ use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn creates_directory() {
|
||||
Playground::setup("umkdir_test_1", |dirs, _| {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir my_new_directory"
|
||||
"mkdir my_new_directory"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("my_new_directory");
|
||||
@ -19,10 +19,10 @@ fn creates_directory() {
|
||||
|
||||
#[test]
|
||||
fn accepts_and_creates_directories() {
|
||||
Playground::setup("umkdir_test_2", |dirs, _| {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir dir_1 dir_2 dir_3"
|
||||
"mkdir dir_1 dir_2 dir_3"
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
@ -34,10 +34,10 @@ fn accepts_and_creates_directories() {
|
||||
|
||||
#[test]
|
||||
fn creates_intermediary_directories() {
|
||||
Playground::setup("umkdir_test_3", |dirs, _| {
|
||||
Playground::setup("mkdir_test_3", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir some_folder/another/deeper_one"
|
||||
"mkdir some_folder/another/deeper_one"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("some_folder/another/deeper_one");
|
||||
@ -48,12 +48,12 @@ fn creates_intermediary_directories() {
|
||||
|
||||
#[test]
|
||||
fn create_directory_two_parents_up_using_multiple_dots() {
|
||||
Playground::setup("umkdir_test_4", |dirs, sandbox| {
|
||||
Playground::setup("mkdir_test_4", |dirs, sandbox| {
|
||||
sandbox.within("foo").mkdir("bar");
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
"umkdir .../boo"
|
||||
"mkdir .../boo"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("boo");
|
||||
@ -64,10 +64,10 @@ fn create_directory_two_parents_up_using_multiple_dots() {
|
||||
|
||||
#[test]
|
||||
fn print_created_paths() {
|
||||
Playground::setup("umkdir_test_2", |dirs, _| {
|
||||
Playground::setup("mkdir_test_2", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
pipeline("umkdir -v dir_1 dir_2 dir_3")
|
||||
pipeline("mkdir -v dir_1 dir_2 dir_3")
|
||||
);
|
||||
|
||||
assert!(files_exist_at(
|
||||
@ -83,10 +83,10 @@ fn print_created_paths() {
|
||||
|
||||
#[test]
|
||||
fn creates_directory_three_dots() {
|
||||
Playground::setup("umkdir_test_1", |dirs, _| {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir test..."
|
||||
"mkdir test..."
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test...");
|
||||
@ -97,10 +97,10 @@ fn creates_directory_three_dots() {
|
||||
|
||||
#[test]
|
||||
fn creates_directory_four_dots() {
|
||||
Playground::setup("umkdir_test_1", |dirs, _| {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir test...."
|
||||
"mkdir test...."
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test....");
|
||||
@ -111,10 +111,10 @@ fn creates_directory_four_dots() {
|
||||
|
||||
#[test]
|
||||
fn creates_directory_three_dots_quotation_marks() {
|
||||
Playground::setup("umkdir_test_1", |dirs, _| {
|
||||
Playground::setup("mkdir_test_1", |dirs, _| {
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"umkdir 'test...'"
|
||||
"mkdir 'test...'"
|
||||
);
|
||||
|
||||
let expected = dirs.test().join("test...");
|
||||
|
Loading…
Reference in New Issue
Block a user