mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
mkdir creates intermediary directories as required (the default). --create-all/--deep flag removed.
This commit is contained in:
parent
50393bdf42
commit
ba6d62ea0c
4 changed files with 11 additions and 40 deletions
|
@ -129,7 +129,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat
|
||||||
| cd path | Change to a new path |
|
| cd path | Change to a new path |
|
||||||
| cp source path | Copy files |
|
| cp source path | Copy files |
|
||||||
| ls (path) | View the contents of the current or given path |
|
| ls (path) | View the contents of the current or given path |
|
||||||
| mkdir path | Make directories, (to create intermediary directories append '--create-all') |
|
| mkdir path | Make directories, creates intermediary directories as required. |
|
||||||
| date (--utc) | Get the current datetime |
|
| date (--utc) | Get the current datetime |
|
||||||
| ps | View current processes |
|
| ps | View current processes |
|
||||||
| sys | View information about the current system |
|
| sys | View information about the current system |
|
||||||
|
|
|
@ -154,7 +154,6 @@ pub fn cp(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
sources.walk_decorate(&entry);
|
sources.walk_decorate(&entry);
|
||||||
|
|
||||||
if entry.is_file() {
|
if entry.is_file() {
|
||||||
|
|
||||||
let strategy = |(source_file, _depth_level)| {
|
let strategy = |(source_file, _depth_level)| {
|
||||||
if destination.exists() {
|
if destination.exists() {
|
||||||
let mut new_dst = dunce::canonicalize(destination.clone()).unwrap();
|
let mut new_dst = dunce::canonicalize(destination.clone()).unwrap();
|
||||||
|
|
|
@ -17,8 +17,7 @@ impl Command for Mkdir {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config(&self) -> CommandConfig {
|
fn config(&self) -> CommandConfig {
|
||||||
let mut named: IndexMap<String, NamedType> = IndexMap::new();
|
let named: IndexMap<String, NamedType> = IndexMap::new();
|
||||||
named.insert("create-all".to_string(), NamedType::Switch);
|
|
||||||
|
|
||||||
CommandConfig {
|
CommandConfig {
|
||||||
name: self.name().to_string(),
|
name: self.name().to_string(),
|
||||||
|
@ -39,23 +38,12 @@ pub fn mkdir(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !args.has("create-all") {
|
match std::fs::create_dir_all(full_path) {
|
||||||
match std::fs::create_dir(full_path) {
|
Err(reason) => Err(ShellError::labeled_error(
|
||||||
Err(_) => Err(ShellError::labeled_error(
|
reason.to_string(),
|
||||||
"No such file or directory",
|
reason.to_string(),
|
||||||
"No such file or directory",
|
args.nth(0).unwrap().span(),
|
||||||
args.nth(0).unwrap().span(),
|
)),
|
||||||
)),
|
Ok(_) => Ok(OutputStream::empty()),
|
||||||
Ok(_) => Ok(OutputStream::empty()),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match std::fs::create_dir_all(full_path) {
|
|
||||||
Err(reason) => Err(ShellError::labeled_error(
|
|
||||||
reason.to_string(),
|
|
||||||
reason.to_string(),
|
|
||||||
args.nth(0).unwrap().span(),
|
|
||||||
)),
|
|
||||||
Ok(_) => Ok(OutputStream::empty()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,31 +19,15 @@ fn creates_directory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_if_intermediary_directory_doesnt_exist() {
|
fn creates_intermediary_directories() {
|
||||||
let sandbox = Playground::setup_for("mkdir_test_2").test_dir_name();
|
let sandbox = Playground::setup_for("mkdir_test_2").test_dir_name();
|
||||||
|
|
||||||
let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let full_path = format!("{}/{}", Playground::root(), sandbox);
|
||||||
|
|
||||||
nu_error!(
|
|
||||||
output,
|
|
||||||
cwd(&full_path),
|
|
||||||
"mkdir some_folder/another/deeper_one"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(output.contains("some_folder/another/deeper_one"));
|
|
||||||
assert!(output.contains("No such file or directory"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn creates_intermediary_directories_with_p_flag() {
|
|
||||||
let sandbox = Playground::setup_for("mkdir_test_3").test_dir_name();
|
|
||||||
|
|
||||||
let full_path = format!("{}/{}", Playground::root(), sandbox);
|
|
||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
_output,
|
_output,
|
||||||
cwd(&full_path),
|
cwd(&full_path),
|
||||||
"mkdir some_folder/another/deeper_one --create-all"
|
"mkdir some_folder/another/deeper_one"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut expected = PathBuf::from(full_path);
|
let mut expected = PathBuf::from(full_path);
|
||||||
|
|
Loading…
Reference in a new issue