Repository navigation
Expand file tree
/
Copy pathConstants.java
More file actions
160 lines (151 loc) · 8.37 KB
/
Copy pathConstants.java
File metadata and controls
160 lines (151 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package constants;
import java.util.Hashtable;
import commands.Cat;
import commands.Cd;
import commands.Command;
import commands.Cp;
import commands.Echo;
import commands.Exit;
import commands.Find;
import commands.Get;
import commands.History;
import commands.Load;
import commands.Ls;
import commands.Man;
import commands.Mkdir;
import commands.Mv;
import commands.Popd;
import commands.Pushd;
import commands.Pwd;
import commands.Save;
import commands.Tree;
/**
* This class holds the constants variables in the program
*/
public class Constants {
// path related constants
public static final String SYSTEM_FILE_PATH_SEPERATOR = "/";
public static final String SYSTEM_FILE_ROOT_NAME = "/";
public static final String PARENT_OF_SYSTEM_FILE_INDICATOR = "..";
public static final String CURRENT_SYSTEM_FILE_INDICATOR = ".";
// invalid file naming characters
public static final char[] INVALID_NAMING_CHAR = {'/','.', '!', '@', '#',
'$', '%', '^', '&', '*', '(', ')', '{', '}', '~', '|', '<', '>', '?'};
public static final String REDIRECTION_OVERWRITE = ">";
public static final String REDIRECTION_APPEND = ">>";
// command dictionary
public static final Hashtable<String, Command> COMMAND_DIC =
new Hashtable<String, Command>();
static {
COMMAND_DIC.put("get", new Get());
COMMAND_DIC.put("exit", new Exit());
COMMAND_DIC.put("mkdir", new Mkdir());
COMMAND_DIC.put("cd", new Cd());
COMMAND_DIC.put("ls", new Ls());
COMMAND_DIC.put("pwd", new Pwd());
COMMAND_DIC.put("pushd", new Pushd());
COMMAND_DIC.put("popd", new Popd());
COMMAND_DIC.put("history", new History());
COMMAND_DIC.put("cat", new Cat());
COMMAND_DIC.put("echo", new Echo());
COMMAND_DIC.put("man", new Man());
COMMAND_DIC.put("mv", new Mv());
COMMAND_DIC.put("cp", new Cp());
COMMAND_DIC.put("tree", new Tree());
COMMAND_DIC.put("save", new Save());
COMMAND_DIC.put("load", new Load());
COMMAND_DIC.put("find", new Find());
}
//optional parameters dictionary maps optional parameter to its decorator
public static final Hashtable<String, String> OPTIONAL_PARAM_DIC =
new Hashtable<String, String>();
static {
OPTIONAL_PARAM_DIC.put("-R", "RecursiveDecorator");
}
public static final Hashtable<String, String> COMMAND_DOCUMENTATION =
new Hashtable<String, String>();
static {
COMMAND_DOCUMENTATION.put("exit","Quit the program");
COMMAND_DOCUMENTATION.put("mkdir", "Create directories, each of which may"
+ " be relative to the current directory \n or may be a full path.");
COMMAND_DOCUMENTATION.put("cd", "Change directory to DIR, which may be"
+ " relative to the current directory or \n may be a full path. As"
+ " with Unix, .. means a parent directory and a .means the current"
+ " directory.");
COMMAND_DOCUMENTATION.put("ls", "If no paths are given, print the"
+ " contents (file or directory) of the current \n directory, with a"
+ " new line following each of the content (file or directory). \n"
+ " Otherwise, for each path p, the order listed: \n"
+ " •If p specifies a file, print p \n"
+ " •If p specifies a directory, print p, a colon, then"
+ " the contents of that directory, then an extra new line. \n"
+ " •If p does not exist, print a suitable message. ");
COMMAND_DOCUMENTATION.put("pwd", "Print the current working directory"
+ " (including the whole path). ");
COMMAND_DOCUMENTATION.put("cp"," Move item OLDPATH to NEWPATH, but don’t"
+ " remove OLDPATH. \n If OLDPATHis a directory, recursively copy the"
+ " contents.");
COMMAND_DOCUMENTATION.put("mv"," Move item OLDPATH to NEWPATH. Both "
+ "OLDPATH and NEWPATH \n may be relative to the current directory"
+ "or may be full paths. If NEWPATH is a directory, move the item"
+ "into the directory.");
COMMAND_DOCUMENTATION.put("pushd","Saves the current working directory by"
+ " pushing onto directory stack and \n then changes the new current"
+ " working directory to DIR. The push must be\nconsistent as per"
+ " the LIFO behavior of a stack. The pushd command \n saves the"
+ " old current working directory in directory stack so that it can"
+ " be \n returned to at any time (via the popd command). The size of"
+ " the directory \n stack is dynamic and dependent on the pushd and"
+ " the popd commands. ");
COMMAND_DOCUMENTATION.put("popd", "Remove the top entry from the"
+ " directory stack, and cd into it. The removal \n must be"
+ " consistent as per the LIFO behavior of a stack. The popd \n"
+ "command removes the top most directory from the directory stack"
+ " and \n makes it the current working directory. If there is no"
+ " directory onto the \n stack, then give appropriate error message."
+ " ");
COMMAND_DOCUMENTATION.put("history","This command will print out recent"
+ " commands, one command per line. \nHistory will also include"
+ "any syntactical errors typed by the user ");
COMMAND_DOCUMENTATION.put("cat", "Display the contents of FILE1 and other"
+ " files (i.e. File2 ....) concatenated in the shell.");
COMMAND_DOCUMENTATION.put("echo","•echo STRING: prints the provided " +
"STRING argument.\nSTRING argument must be surrounded by double quotes"
+ "unless it consists of only one word");
COMMAND_DOCUMENTATION.put("man", "Print documentation for command");
COMMAND_DOCUMENTATION.put("get", "Retrieve the file at given URL and add" +
" it to the current working directory");
COMMAND_DOCUMENTATION.put("save", "Saves the session of the JShell"
+ " onto a file in the given path");
COMMAND_DOCUMENTATION.put("load", "Loads the session of the JShell"
+ " from the file of the given path. Load must be called at the start"
+ "of the new session");
COMMAND_DOCUMENTATION.put("find", "The syntax of thefindcommand is as"
+ "follows:find path ... -type [f|d] -name expression. \n So here are"
+ " some examples of how thefindcommand may be used:"
+ "\n •find /users/Desktop -type f -name \"xyz\". This command will"
+ " search the directoryDesktopand find all files (indicated by type"
+ " f) that have the name exactlyxyz. \n"
+ " •find /users/Desktop -type d -name \"abc\". This command will"
+ " search the directoryDesktopand find all directories (indicated by"
+ " type d) that have the name exactlyabc. \n"
+ " •find /users/Desktop. This command will result in an error"
+ " because it has missing arguments. \n"
+ " •find /users/Desktop /users/Desktop1 -type d -name \"abc\". "
+ " This command will searchthe directoryDesktopandDesktop1 and"
+ " find all directories (indicated bytype d) that have the name"
+ " exactly abc. \n "
+ "•find /users/Desktop /users/Desktop1 -type f -name \"abc\". "
+ " This command will searchthe directory Desktop and Desktop1 and"
+ " find all directories (indicated bytype f) that have the name"
+ " exactly abc.\n"
+ " •If at any point one of the path in this command is invalid,"
+ " shell will print out an error for that path,however, you must"
+ " continue searching for any other files or directories that may"
+ " exist in other valid paths. \n"
+ " •Thefindcommand must accept the path as relative or in absolute"
+ " path.");
COMMAND_DOCUMENTATION.put("tree", "Tree will display the entire"
+ " filesystem as a tree starting from the root directory");
}
}