diff --git a/cli/descriptors/org.jnode.command.file.xml b/cli/descriptors/org.jnode.command.file.xml
index ab2c369520..8e89bd9cf5 100644
--- a/cli/descriptors/org.jnode.command.file.xml
+++ b/cli/descriptors/org.jnode.command.file.xml
@@ -335,7 +335,12 @@
-
+
+
+
+
+
+
diff --git a/cli/src/commands/org/jnode/command/file/MkdirCommand.java b/cli/src/commands/org/jnode/command/file/MkdirCommand.java
index 1bd385f266..5ee73b9428 100644
--- a/cli/src/commands/org/jnode/command/file/MkdirCommand.java
+++ b/cli/src/commands/org/jnode/command/file/MkdirCommand.java
@@ -26,6 +26,7 @@
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FileArgument;
+import org.jnode.shell.syntax.FlagArgument;
/**
* @author Guillaume BINET (gbin@users.sourceforge.net)
@@ -34,16 +35,19 @@
public class MkdirCommand extends AbstractCommand {
private static final String help_dir = "the directory to create";
+ private static final String help_parents = "if set, create parent directories as needed";
private static final String help_super = "Create a new directory";
private static final String fmt_exists = "%s already exists%n";
private static final String err_cant_create = "Cannot create directory";
private final FileArgument argDir;
+ private final FlagArgument argParents;
public MkdirCommand() {
super(help_super);
- argDir = new FileArgument("directory", Argument.MANDATORY | Argument.NONEXISTENT, help_dir);
- registerArguments(argDir);
+ argDir = new FileArgument("directory", Argument.MANDATORY, help_dir);
+ argParents = new FlagArgument("parents", Argument.OPTIONAL, help_parents);
+ registerArguments(argDir, argParents);
}
public static void main(String[] args) throws Exception {
@@ -53,13 +57,20 @@ public static void main(String[] args) throws Exception {
public void execute() {
File dir = argDir.getValue();
PrintWriter err = getError().getPrintWriter();
- if (dir.exists()) {
- err.format(fmt_exists, dir);
- exit(1);
- }
- if (!dir.mkdir()) {
- err.println(err_cant_create);
- exit(1);
+ if (argParents.isSet()) {
+ if (!dir.mkdirs()) {
+ err.println(err_cant_create);
+ exit(1);
+ }
+ } else {
+ if (dir.exists()) {
+ err.format(fmt_exists, dir);
+ exit(1);
+ }
+ if (!dir.mkdir()) {
+ err.println(err_cant_create);
+ exit(1);
+ }
}
}
}
diff --git a/cli/src/test/org/jnode/test/command/file/all-file-tests.xml b/cli/src/test/org/jnode/test/command/file/all-file-tests.xml
index 467061020f..88d2c4f569 100644
--- a/cli/src/test/org/jnode/test/command/file/all-file-tests.xml
+++ b/cli/src/test/org/jnode/test/command/file/all-file-tests.xml
@@ -8,4 +8,5 @@
+
diff --git a/cli/src/test/org/jnode/test/command/file/mkdir-command-tests.xml b/cli/src/test/org/jnode/test/command/file/mkdir-command-tests.xml
new file mode 100644
index 0000000000..18fa1b27b8
--- /dev/null
+++ b/cli/src/test/org/jnode/test/command/file/mkdir-command-tests.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ @TEMP_DIR@/newdir
+
+
+ -p
+ @TEMP_DIR@/a/b/c
+
+
+ --parents
+ @TEMP_DIR@/x/y/z
+
+
+ -p
+ @TEMP_DIR@/newdir
+
+
+ @TEMP_DIR@/d/e/f
+
+