forked from tools/josh
1
0
Fork 0

Implement creating/removing multiple directories

This commit is contained in:
Florine W. Dekker 2018-11-29 09:08:24 +01:00
parent 6f8affebb2
commit 86f57cb56d
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 36 additions and 11 deletions

View File

@ -48,9 +48,12 @@ class Commands {
},
mkdir: {
fun: this.mkdir,
summary: `make directory`,
usage: `mkdir DIRECTORY`,
desc: `Creates a directory with name DIRECTORY.`
summary: `make directories`,
usage: `mkdir DIRECTORY...`,
desc: "" +
`Creates the directories given by DIRECTORY.
If more than one directory is given, the directories are created in the order they are given in`.trimLines()
},
open: {
fun: this.open,
@ -81,10 +84,12 @@ class Commands {
},
rmdir: {
fun: this.rmdir,
summary: `remove directory`,
usage: `rmdir [-f | --force] DIRECTORY`,
summary: `remove directories`,
usage: `rmdir [-f | --force] DIRECTORY...`,
desc: "" +
`Removes DIRECTORY if it is a directory.
`Removes the directories given by DIRECTORY.
If more than one directory is given, the directories are removed in the order they are given in.s
If -f or --force is set, DIRECTORY is deleted even if it contains files or other directories.`.trimLines()
}
@ -159,7 +164,7 @@ class Commands {
}
mkdir(args) {
return this._fs.mkdir(args.getArg(0));
return this._fs.mkdirs(args.getArgs());
}
open(args) {
@ -207,10 +212,7 @@ class Commands {
}
rmdir(args) {
const path = args.getArg(0);
const force = args.hasAnyOption(["-f", "--force"]);
return this._fs.rmdir(path, force);
return this._fs.rmdirs(args.getArgs(), args.hasAnyOption(["-f", "--force"]));
}
}

View File

@ -224,6 +224,17 @@ class FileSystem {
return "";
}
mkdirs(paths) {
for (let i = 0; i < paths.length; i++) {
const output = this.mkdir(paths[i]);
if (output !== "") {
return output;
}
}
return "";
}
/**
* Resets navigation in the file system.
*/
@ -295,6 +306,18 @@ class FileSystem {
delete parentDir[childDirName];
return "";
}
rmdirs(paths, force) {
for (let i = 0; i < paths.length; i++) {
const output = this.rmdir(paths[i], force);
if (output !== "") {
return output;
}
}
return "";
}
}