parent
c6d8b37b58
commit
de1b3ab315
|
@ -70,8 +70,9 @@ export class Commands {
|
|||
"echo": new Command(
|
||||
this.echo,
|
||||
`display text`,
|
||||
`echo [TEXT]`,
|
||||
`Displays [TEXT].`.trimLines(),
|
||||
`echo [-n] [TEXT]`,
|
||||
`Displays [TEXT].
|
||||
Unless the -n parameter is given, a newline is appended to the end.`.trimLines(),
|
||||
new InputValidator()
|
||||
),
|
||||
"exit": new Command(
|
||||
|
@ -109,10 +110,11 @@ export class Commands {
|
|||
"mkdir": new Command(
|
||||
this.mkdir,
|
||||
`make directories`,
|
||||
`mkdir DIRECTORY...`,
|
||||
`mkdir [-p] DIRECTORY ...`,
|
||||
`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(),
|
||||
If more than one directory is given, the directories are created in the order they are given in.
|
||||
If the -p option is given, parent directories that do not exist are created as well.`.trimLines(),
|
||||
new InputValidator({minArgs: 1})
|
||||
),
|
||||
"mv": new Command(
|
||||
|
@ -262,7 +264,8 @@ export class Commands {
|
|||
}
|
||||
|
||||
private echo(input: InputArgs): string {
|
||||
return input.args.join(" ").replace("hunter2", "*******") + "\n";
|
||||
return input.args.join(" ").replace("hunter2", "*******")
|
||||
+ input.hasOption("n") ? "\n" : "";
|
||||
}
|
||||
|
||||
private exit(): string {
|
||||
|
@ -336,7 +339,7 @@ export class Commands {
|
|||
}
|
||||
|
||||
private mkdir(input: InputArgs): string {
|
||||
return this.fileSystem.mkdirs(input.args);
|
||||
return this.fileSystem.mkdirs(input.args, input.hasOption("p"));
|
||||
}
|
||||
|
||||
private mv(input: InputArgs): string {
|
||||
|
|
|
@ -298,11 +298,14 @@ export class FileSystem {
|
|||
/**
|
||||
* Creates an empty directory in the file system.
|
||||
*
|
||||
* @param pathString {string} the absolute or relative path to the directory to create
|
||||
* @param pathString the absolute or relative path to the directory to create
|
||||
* @param createParents `true` if and only intermediate directories that do not exist should be created
|
||||
* @return an empty string if the removal was successful, or a message explaining what went wrong
|
||||
*/
|
||||
private mkdir(pathString: string): string {
|
||||
private mkdir(pathString: string, createParents: boolean): string {
|
||||
const path = this.getPathTo(pathString);
|
||||
if (createParents && path.toString() !== "/")
|
||||
this.mkdir(path.parent.toString(), true);
|
||||
|
||||
const parentNode = this.getNode(path.parent);
|
||||
if (parentNode === undefined)
|
||||
|
@ -317,13 +320,14 @@ export class FileSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Calls {@link mkdir} on all elements in {@code paths}.
|
||||
* Calls `mkdir` on all elements in `paths`.
|
||||
*
|
||||
* @param paths {string[]} the absolute or relative paths to the directories to create
|
||||
* @param paths the absolute or relative paths to the directories to create
|
||||
* @param createParents `true` if and only intermediate directories that do not exist should be created
|
||||
* @return the warnings generated during creation of the directories
|
||||
*/
|
||||
mkdirs(paths: string[]): string {
|
||||
return this.executeForEach(paths, this.mkdir.bind(this));
|
||||
mkdirs(paths: string[], createParents: boolean): string {
|
||||
return this.executeForEach(paths, path => this.mkdir(path, createParents));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,9 +405,7 @@ export class FileSystem {
|
|||
* @return the warnings generated during removal of the directories
|
||||
*/
|
||||
rms(paths: string[], force: boolean = false, recursive: boolean = false, noPreserveRoot: boolean = false): string {
|
||||
return this.executeForEach(paths, path => {
|
||||
return this.rm(path, force, recursive, noPreserveRoot);
|
||||
});
|
||||
return this.executeForEach(paths, path => this.rm(path, force, recursive, noPreserveRoot));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue