|
CdCommand |
|
1 // joi/10/juno/CdCommand.java
2 //
3 //
4 // Copyright 2003, Bill Campbell and Ethan Bolker
5
6 import java.util.*;
7
8 /**
9 * The Juno shell command to change directory.
10 * Usage:
11 * <pre>
12 * cd [directory]
13 * </pre>
14 * for moving to the named directory.
15 *
16 * @version 10
17 */
18
19 class CdCommand extends ShellCommand
20 {
21 CdCommand()
22 {
23 super( "change current directory", "[ directory ]" );
24 }
25
26 /**
27 * Move to the named directory
28 *
29 * @param args the remainder of the command line.
30 * @param sh the current shell
31 *
32 * @exception JunoException for reporting errors
33 */
34
35 public void doIt( StringTokenizer args, Shell sh )
36 throws JunoException
37 {
38 String dirname = "";
39 Directory d = sh.getUser().getHome(); // default
40 if ( args.hasMoreTokens() ) {
41 dirname = args.nextToken();
42 if (dirname.equals("..")) {
43 if (sh.getDot().isRoot())
44 d = sh.getDot(); // no change
45 else
46 d = sh.getDot().getParent();
47 }
48 else if (dirname.equals(".")) {
49 d = sh.getDot(); // no change
50 }
51 else {
52 d = (Directory)(sh.getDot().retrieveJFile(dirname));
53 }
54 }
55 sh.setDot( d );
56 }
57 }
58
|
CdCommand |
|