mkdir creates intermediary directories as required (the default). --create-all/--deep flag removed.

This commit is contained in:
Andrés N. Robalino 2019-08-07 14:38:00 -05:00
parent 50393bdf42
commit ba6d62ea0c
4 changed files with 11 additions and 40 deletions

View File

@ -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 |
| cp source path | Copy files |
| 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 |
| ps | View current processes |
| sys | View information about the current system |

View File

@ -154,7 +154,6 @@ pub fn cp(args: CommandArgs) -> Result<OutputStream, ShellError> {
sources.walk_decorate(&entry);
if entry.is_file() {
let strategy = |(source_file, _depth_level)| {
if destination.exists() {
let mut new_dst = dunce::canonicalize(destination.clone()).unwrap();

View File

@ -17,8 +17,7 @@ impl Command for Mkdir {
}
fn config(&self) -> CommandConfig {
let mut named: IndexMap<String, NamedType> = IndexMap::new();
named.insert("create-all".to_string(), NamedType::Switch);
let named: IndexMap<String, NamedType> = IndexMap::new();
CommandConfig {
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(full_path) {
Err(_) => Err(ShellError::labeled_error(
"No such file or directory",
"No such file or directory",
args.nth(0).unwrap().span(),
)),
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()),
}
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()),
}
}

View File

@ -19,31 +19,15 @@ fn creates_directory() {
}
#[test]
fn error_if_intermediary_directory_doesnt_exist() {
fn creates_intermediary_directories() {
let sandbox = Playground::setup_for("mkdir_test_2").test_dir_name();
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!(
_output,
cwd(&full_path),
"mkdir some_folder/another/deeper_one --create-all"
"mkdir some_folder/another/deeper_one"
);
let mut expected = PathBuf::from(full_path);