Remove unnecessary braces
This commit is contained in:
parent
be4369e0ab
commit
5c1f126481
|
@ -137,13 +137,12 @@ class Commands {
|
|||
parse(input) {
|
||||
const args = new InputArgs(input);
|
||||
|
||||
if (Object.keys(this._list).indexOf(args.getCommand()) >= 0) {
|
||||
if (Object.keys(this._list).indexOf(args.getCommand()) >= 0)
|
||||
return this._list[args.getCommand()].fun.bind(this)(args);
|
||||
} else if (args.getCommand().trim() === "") {
|
||||
else if (args.getCommand().trim() === "")
|
||||
return "";
|
||||
} else {
|
||||
else
|
||||
return `Unknown command '${args.getCommand()}'`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,13 +206,12 @@ class Commands {
|
|||
}
|
||||
|
||||
man(args) {
|
||||
if (args.getArgs().length === 0) {
|
||||
if (args.getArgs().length === 0)
|
||||
return "What manual page do you want?";
|
||||
} else if (Object.keys(this._list).indexOf(args.getArg(0)) < 0) {
|
||||
else if (Object.keys(this._list).indexOf(args.getArg(0)) < 0)
|
||||
return `No manual entry for ${args.getArg(0)}`;
|
||||
} else {
|
||||
else
|
||||
return this.help(args);
|
||||
}
|
||||
}
|
||||
|
||||
mkdir(args) {
|
||||
|
@ -229,15 +227,12 @@ class Commands {
|
|||
const target = args.hasAnyOption(["b", "blank"]) ? "_blank" : "_self";
|
||||
|
||||
const file = this._fs._getFile(fileName);
|
||||
if (file === undefined) {
|
||||
if (file === undefined)
|
||||
return `The file '${fileName}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isFile(file)) {
|
||||
if (!FileSystem.isFile(file))
|
||||
return `'${fileName}' is not a file`;
|
||||
}
|
||||
if (!(file instanceof UrlFile)) {
|
||||
if (!(file instanceof UrlFile))
|
||||
return `Could not open '${fileName}'`;
|
||||
}
|
||||
|
||||
window.open(file.url, target);
|
||||
return "";
|
||||
|
@ -358,11 +353,9 @@ class InputArgs {
|
|||
}
|
||||
|
||||
hasAnyOption(keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (this.hasOption(keys[i])) {
|
||||
for (let i = 0; i < keys.length; i++)
|
||||
if (this.hasOption(keys[i]))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
116
js/fs.js
116
js/fs.js
|
@ -29,12 +29,10 @@ class FileSystem {
|
|||
|
||||
let file = this._root;
|
||||
path.parts.forEach(part => {
|
||||
if (part === "") {
|
||||
if (part === "")
|
||||
return;
|
||||
}
|
||||
if (file === undefined) {
|
||||
if (file === undefined)
|
||||
return;
|
||||
}
|
||||
if (FileSystem.isFile(file)) {
|
||||
file = undefined;
|
||||
return;
|
||||
|
@ -53,9 +51,8 @@ class FileSystem {
|
|||
inputs.forEach(input => {
|
||||
const output = fun(input);
|
||||
|
||||
if (output !== "") {
|
||||
if (output !== "")
|
||||
outputs.push(output);
|
||||
}
|
||||
});
|
||||
|
||||
return outputs.join("\n");
|
||||
|
@ -97,12 +94,10 @@ class FileSystem {
|
|||
const path = new Path(this.pwd, pathString);
|
||||
|
||||
const file = this._getFile(path.path);
|
||||
if (file === undefined) {
|
||||
if (file === undefined)
|
||||
return `The directory '${path.path}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(file)) {
|
||||
if (!FileSystem.isDirectory(file))
|
||||
return `'${path.path}' is not a directory`;
|
||||
}
|
||||
|
||||
this.pwd = path.path;
|
||||
this.files = file;
|
||||
|
@ -120,17 +115,14 @@ class FileSystem {
|
|||
path = new Path(this.pwd, path);
|
||||
|
||||
const headNode = this._getFile(path.head);
|
||||
if (headNode === undefined) {
|
||||
if (headNode === undefined)
|
||||
return `The directory '${path.head}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(headNode)) {
|
||||
if (!FileSystem.isDirectory(headNode))
|
||||
return `${path.head} is not a directory`;
|
||||
}
|
||||
|
||||
const tailNode = headNode.getNode(path.tail);
|
||||
if (tailNode !== undefined) {
|
||||
if (tailNode !== undefined)
|
||||
return "";
|
||||
}
|
||||
|
||||
headNode.addNode(path.tail, new File(path.tail));
|
||||
return "";
|
||||
|
@ -167,15 +159,12 @@ class FileSystem {
|
|||
const destinationHeadNode = this._getFile(destinationPath.head);
|
||||
const destinationTailNode = this._getFile(destinationPath.path);
|
||||
|
||||
if (sourceTailNode === undefined) {
|
||||
if (sourceTailNode === undefined)
|
||||
return `The file '${sourcePath.path}' does not exist`;
|
||||
}
|
||||
if (!(sourceTailNode instanceof File)) {
|
||||
if (!(sourceTailNode instanceof File))
|
||||
return `Cannot copy directory.`;
|
||||
}
|
||||
if (destinationHeadNode === undefined) {
|
||||
if (destinationHeadNode === undefined)
|
||||
return `The directory '${destinationPath.head}' does not exist`;
|
||||
}
|
||||
|
||||
let targetNode;
|
||||
let targetName;
|
||||
|
@ -187,9 +176,8 @@ class FileSystem {
|
|||
targetName = sourcePath.tail;
|
||||
}
|
||||
|
||||
if (targetNode.getNode(targetName) !== undefined) {
|
||||
if (targetNode.getNode(targetName) !== undefined)
|
||||
return `The file '${targetName}' already exists`;
|
||||
}
|
||||
|
||||
targetNode.addNode(targetName, sourceTailNode.copy());
|
||||
|
||||
|
@ -206,12 +194,10 @@ class FileSystem {
|
|||
const path = new Path(this.pwd, pathString);
|
||||
|
||||
const dir = this._getFile(path.path);
|
||||
if (dir === undefined) {
|
||||
if (dir === undefined)
|
||||
return `The directory '${path.path}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(dir)) {
|
||||
if (!FileSystem.isDirectory(dir))
|
||||
return `'${path.path}' is not a directory`;
|
||||
}
|
||||
|
||||
const dirList = [new Directory({}).nameString("."), new Directory({}).nameString("..")];
|
||||
const fileList = [];
|
||||
|
@ -222,13 +208,12 @@ class FileSystem {
|
|||
.forEach(name => {
|
||||
const node = nodes[name];
|
||||
|
||||
if (FileSystem.isDirectory(node)) {
|
||||
if (FileSystem.isDirectory(node))
|
||||
dirList.push(node.nameString(name));
|
||||
} else if (FileSystem.isFile(node)) {
|
||||
else if (FileSystem.isFile(node))
|
||||
fileList.push(node.nameString(name));
|
||||
} else {
|
||||
else
|
||||
throw `${name} is neither a file nor a directory!`;
|
||||
}
|
||||
});
|
||||
|
||||
return dirList.concat(fileList).join("\n");
|
||||
|
@ -244,15 +229,12 @@ class FileSystem {
|
|||
const path = new Path(pathString);
|
||||
|
||||
const headNode = this._getFile(path.head);
|
||||
if (headNode === undefined) {
|
||||
if (headNode === undefined)
|
||||
return `The directory '${path.head}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(headNode)) {
|
||||
if (!FileSystem.isDirectory(headNode))
|
||||
return `'${path.head}' is not a directory`;
|
||||
}
|
||||
if (headNode.getNode(path.tail)) {
|
||||
if (headNode.getNode(path.tail))
|
||||
return `The directory '${path.tail}' already exists`;
|
||||
}
|
||||
|
||||
headNode.addNode(path.tail, new Directory());
|
||||
return "";
|
||||
|
@ -288,12 +270,10 @@ class FileSystem {
|
|||
const destinationHeadNode = this._getFile(destinationPath.head);
|
||||
const destinationTailNode = this._getFile(destinationPath.path);
|
||||
|
||||
if (sourceTailNode === undefined) {
|
||||
if (sourceTailNode === undefined)
|
||||
return `The file '${sourcePath.path}' does not exist`;
|
||||
}
|
||||
if (destinationHeadNode === undefined) {
|
||||
if (destinationHeadNode === undefined)
|
||||
return `The directory '${destinationPath.head}' does not exist`;
|
||||
}
|
||||
|
||||
let targetNode;
|
||||
let targetName;
|
||||
|
@ -305,9 +285,8 @@ class FileSystem {
|
|||
targetName = sourcePath.tail;
|
||||
}
|
||||
|
||||
if (targetNode.getNode(targetName) !== undefined) {
|
||||
if (targetNode.getNode(targetName) !== undefined)
|
||||
return `The file '${targetName}' already exists`;
|
||||
}
|
||||
|
||||
sourceHeadNode.removeNode(sourceTailNode);
|
||||
targetNode.addNode(sourceTailNode);
|
||||
|
@ -337,40 +316,34 @@ class FileSystem {
|
|||
const path = new Path(pathString);
|
||||
|
||||
const parentNode = this._getFile(path.head);
|
||||
if (parentNode === undefined) {
|
||||
if (parentNode === undefined)
|
||||
return force
|
||||
? ""
|
||||
: `The directory '${path.head}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(parentNode)) {
|
||||
if (!FileSystem.isDirectory(parentNode))
|
||||
return force
|
||||
? ""
|
||||
: `'${path.head}' is not a directory`;
|
||||
}
|
||||
|
||||
const childNode = this._getFile(path.path);
|
||||
if (childNode === undefined) {
|
||||
if (childNode === undefined)
|
||||
return force
|
||||
? ""
|
||||
: `The file '${path.path}' does not exist`;
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
if (path.path === "/") {
|
||||
if (noPreserveRoot) {
|
||||
if (path.path === "/")
|
||||
if (noPreserveRoot)
|
||||
this._root = new Directory();
|
||||
} else {
|
||||
else
|
||||
return "'/' cannot be removed";
|
||||
}
|
||||
} else {
|
||||
else
|
||||
parentNode.removeNode(childNode);
|
||||
}
|
||||
} else {
|
||||
if (!(childNode instanceof File)) {
|
||||
if (!(childNode instanceof File))
|
||||
return force
|
||||
? ""
|
||||
: `'${path.tail}' is not a file`;
|
||||
}
|
||||
|
||||
parentNode.removeNode(childNode);
|
||||
}
|
||||
|
@ -402,31 +375,25 @@ class FileSystem {
|
|||
const path = new Path(pathString);
|
||||
|
||||
if (path.path === "/") {
|
||||
if (this._root.getNodeCount() > 0) {
|
||||
if (this._root.getNodeCount() > 0)
|
||||
return `The directory is not empty.`;
|
||||
} else {
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const parentDir = this._getFile(path.head);
|
||||
if (parentDir === undefined) {
|
||||
if (parentDir === undefined)
|
||||
return `The directory '${path.head}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(parentDir)) {
|
||||
if (!FileSystem.isDirectory(parentDir))
|
||||
return `'${path.head}' is not a directory`;
|
||||
}
|
||||
|
||||
const childDir = parentDir.getNode(path.tail);
|
||||
if (childDir === undefined) {
|
||||
if (childDir === undefined)
|
||||
return `The directory '${path.tail}' does not exist`;
|
||||
}
|
||||
if (!FileSystem.isDirectory(childDir)) {
|
||||
if (!FileSystem.isDirectory(childDir))
|
||||
return `'${path.tail}' is not a directory`;
|
||||
}
|
||||
if (childDir.getNodeCount() > 0) {
|
||||
if (childDir.getNodeCount() > 0)
|
||||
return `The directory is not empty`;
|
||||
}
|
||||
|
||||
parentDir.removeNode(childDir);
|
||||
return "";
|
||||
|
@ -449,13 +416,12 @@ class FileSystem {
|
|||
class Path {
|
||||
constructor(currentPath, relativePath) {
|
||||
let path;
|
||||
if (relativePath === undefined) {
|
||||
if (relativePath === undefined)
|
||||
path = currentPath;
|
||||
} else if (relativePath.startsWith("/")) {
|
||||
else if (relativePath.startsWith("/"))
|
||||
path = relativePath;
|
||||
} else {
|
||||
else
|
||||
path = `${currentPath}/${relativePath}`;
|
||||
}
|
||||
|
||||
|
||||
this._path = `${path}/`
|
||||
|
|
10
js/shared.js
10
js/shared.js
|
@ -17,13 +17,12 @@ Array.prototype.sortAlphabetically = function(transform = identityFunction) {
|
|||
const aName = transform(a).toLowerCase();
|
||||
const bName = transform(b).toLowerCase();
|
||||
|
||||
if (aName < bName) {
|
||||
if (aName < bName)
|
||||
return -1;
|
||||
} else if (aName > bName) {
|
||||
else if (aName > bName)
|
||||
return 1;
|
||||
} else {
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -31,9 +30,8 @@ Array.prototype.sortAlphabetically = function(transform = identityFunction) {
|
|||
String.prototype.replaceAll = function (regex, replacement) {
|
||||
let string = this;
|
||||
|
||||
while (regex.test(string)) {
|
||||
while (regex.test(string))
|
||||
string = string.replace(regex, replacement);
|
||||
}
|
||||
|
||||
return "" + string;
|
||||
};
|
||||
|
|
|
@ -185,9 +185,8 @@ class InputHistory {
|
|||
|
||||
|
||||
addEntry(entry) {
|
||||
if (entry.trim() !== "") {
|
||||
if (entry.trim() !== "")
|
||||
this._history.unshift(entry);
|
||||
}
|
||||
this._index = -1;
|
||||
}
|
||||
|
||||
|
@ -197,27 +196,24 @@ class InputHistory {
|
|||
}
|
||||
|
||||
getEntry(index) {
|
||||
if (index >= 0) {
|
||||
if (index >= 0)
|
||||
return this._history[index];
|
||||
} else {
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
nextEntry() {
|
||||
this._index--;
|
||||
if (this._index < -1) {
|
||||
if (this._index < -1)
|
||||
this._index = -1;
|
||||
}
|
||||
|
||||
return this.getEntry(this._index);
|
||||
}
|
||||
|
||||
previousEntry() {
|
||||
this._index++;
|
||||
if (this._index >= this._history.length) {
|
||||
if (this._index >= this._history.length)
|
||||
this._index = this._history.length - 1;
|
||||
}
|
||||
|
||||
return this.getEntry(this._index);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue