@@ -27,27 +27,57 @@ public class Dir
27
27
/*
28
28
* Dir() void
29
29
*
30
- * Constructor for calling methods .
30
+ * Constructor for calling Process() function .
31
31
*/
32
- public Dir (ArrayList < String > options ) { }
32
+ public Dir () { }
33
33
34
34
/*
35
35
* Process() void
36
36
*
37
37
* Process the input.
38
38
*
39
- * ArrayList< String> options - command options
39
+ * String options - command options
40
40
*/
41
- public static void Process (ArrayList < String > options )
41
+ public static void Process (String options )
42
42
{
43
43
44
- // Display help information
45
- System .out .println ("Directory Commands\n \n ls\t cd\n chdir\t pwd\n md" );
44
+ ArrayList <String > optionsArray = JTerm .GetAsArray (options );
45
+ if (optionsArray .toArray ().length == 0 )
46
+ optionsArray .add (0 , "help" );
47
+
48
+ String command = optionsArray .get (0 );
49
+ optionsArray .remove (0 );
50
+
51
+ switch (command )
52
+ {
53
+ case "ls" : // @pmorgan3
54
+ PrintDir (optionsArray );
55
+ break ;
56
+
57
+ case "cd" :
58
+ case "chdir" :
59
+ ChangeDir (optionsArray );
60
+ break ;
61
+
62
+ case "pwd" :
63
+ PrintWorkingDir (optionsArray );
64
+ break ;
65
+
66
+ case "md" :
67
+ NewDir (optionsArray );
68
+ break ;
69
+
70
+ case "help" :
71
+ default :
72
+ System .out .println ("Directory Commands\n \n ls\t cd\n chdir\t pwd\n md\t help" );
73
+ return ;
74
+
75
+ }
46
76
47
77
}
48
78
49
79
/*
50
- * Ls () void (@pmorgan3)
80
+ * PrintDir () void
51
81
*
52
82
* Prints the contents of a specified directory
53
83
* to a file.
@@ -65,15 +95,13 @@ public static void Process(ArrayList<String> options)
65
95
*
66
96
* Examples
67
97
*
68
- * Ls (options);
98
+ * PrintDir (options);
69
99
* => [Contents of "dir/"]
70
100
* => F RW myFile.txt 2 KB
71
101
*/
72
- public static void Ls (ArrayList <String > options ) throws NullPointerException
102
+ public static void PrintDir (ArrayList <String > options ) throws NullPointerException
73
103
{
74
104
75
- System .out .println (options );
76
-
77
105
String path = JTerm .currentDirectory ;
78
106
boolean printFull = true ;
79
107
@@ -126,7 +154,7 @@ else if (option.equals("-h"))
126
154
127
155
128
156
/*
129
- * Cd () void
157
+ * ChangeDir () void
130
158
*
131
159
* Changes the working directory to the specified
132
160
* input.
@@ -138,7 +166,7 @@ else if (option.equals("-h"))
138
166
*
139
167
* ArrayList<String> options - command options
140
168
*/
141
- public static void Cd (ArrayList <String > options )
169
+ public static void ChangeDir (ArrayList <String > options )
142
170
{
143
171
144
172
String newDirectory = "" ;
@@ -195,25 +223,10 @@ else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.i
195
223
// It does exist, and it is a directory, so just change the global working directory variable to the input
196
224
JTerm .currentDirectory = newDirectory ;
197
225
198
-
199
- }
200
-
201
- /*
202
- * Chdir() void
203
- *
204
- * Identical to 'cd'; calls Cd().
205
- *
206
- * ArrayList<String> options - command options
207
- */
208
- public static void Chdir (ArrayList <String > options )
209
- {
210
-
211
- Cd (options );
212
-
213
226
}
214
227
215
228
/*
216
- * Pwd () void
229
+ * PrintWorkingDir () void
217
230
*
218
231
* Prints the working directory to the console.
219
232
*
@@ -222,7 +235,7 @@ public static void Chdir(ArrayList<String> options)
222
235
*
223
236
* ArrayList<String> options - command options
224
237
*/
225
- public static void Pwd (ArrayList <String > options )
238
+ public static void PrintWorkingDir (ArrayList <String > options )
226
239
{
227
240
228
241
for (String option : options )
@@ -242,7 +255,7 @@ public static void Pwd(ArrayList<String> options)
242
255
}
243
256
244
257
/*
245
- * Md () void
258
+ * NewDir () void
246
259
*
247
260
* Creates a new directory.
248
261
*
@@ -251,7 +264,7 @@ public static void Pwd(ArrayList<String> options)
251
264
*
252
265
* ArrayList<String> options - command options
253
266
*/
254
- public static void Md (ArrayList <String > options )
267
+ public static void NewDir (ArrayList <String > options )
255
268
{
256
269
257
270
String name = "" ;
@@ -274,7 +287,6 @@ public static void Md(ArrayList<String> options)
274
287
275
288
File dir = new File (name );
276
289
dir .mkdir ();
277
-
278
290
}
279
291
280
292
}
0 commit comments