1 package nl.toolforge.karma.cli;
2
3 import nl.toolforge.karma.console.KarmaConsole;
4
5 /***
6 * Bootstrap thing for Karma. If <code>console</code> is passed as the first argument, <code>KarmaConsole</code> will be
7 * started with the remaining arguments passed as arguments to the console. Otherwise, <code>CLI</code> is started,
8 * which is the 'real' command-line modeof Karma.
9 *
10 * @author D.A. Smedes
11 * @version $Id: FireAway.java,v 1.4 2004/11/10 22:14:19 asmedes Exp $
12 */
13 public final class FireAway {
14
15 public static final String CONSOLE = "console";
16
17 public static void main(String[] args) {
18
19 if (args.length == 0) {
20 printUsage();
21 } else {
22
23
24 boolean update = false;
25 String context = "";
26
27
28
29 int tel = 0;
30 while ( (tel < args.length) && args[tel].startsWith("-") ) {
31 if ( args[tel].equals("-u") ) {
32
33
34 update = true;
35 tel += 1;
36 } else if ( args[tel].equals("-w") ) {
37
38
39 if ( (tel+1 < args.length) && !args[tel+1].startsWith("-") ) {
40 context = args[tel+1];
41 tel += 2;
42 } else {
43 System.out.println("Missing working context name (option -w).");
44 printUsage();
45 }
46 } else {
47
48 System.out.println("Unknown option: "+ args[tel]);
49 printUsage();
50 }
51 }
52
53
54 if ( tel >= args.length ) {
55
56 System.out.println("No command specified.");
57 printUsage();
58 } else if ( args[tel].equals(CONSOLE) ) {
59
60 KarmaConsole console = new KarmaConsole();
61 console.runConsole(new String[]{context, new Boolean(update).toString()});
62 } else {
63
64 String[] cliArgs = new String[ 2+(args.length-tel) ];
65 cliArgs[0] = context;
66 cliArgs[1] = new Boolean(update).toString();
67 for (int i = 0; i < (args.length-tel); i++) {
68 cliArgs[i+2] = args [tel + i];
69 }
70 CLI cli = new CLI();
71 cli.runCli(cliArgs);
72 }
73 }
74 }
75
76 private static void printUsage() {
77 System.out.println("usage: karma [options] console | <command> <command options>");
78 System.out.println("");
79 System.out.println("Options:");
80 System.out.println(" -u Update the location- and manifest store.");
81 System.out.println(" -w <working context> Load the given working context.");
82 System.out.println("");
83 System.out.println("console Start the Karma console.");
84 System.out.println("<command> <command options> Run the given command with the given options.");
85 System.out.println(" Use the 'help' command for the list of commands.");
86 System.out.println("\n\n");
87 System.exit(1);
88 }
89
90 }