aboutsummaryrefslogtreecommitdiffstats
path: root/tools/control/src/org/xenoserver/cmdline/Main.java
blob: a85c1923a7864f393b1d91b892d481642f1c9874 (plain)
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
package org.xenoserver.cmdline;

import org.xenoserver.control.CommandFailedException;
import org.xenoserver.control.Defaults;

public class Main {
  private static ParseHelp help = new ParseHelp();
  static CommandParser commands[] =
    { help,
      new ParseNew(),
      new ParseStart(),
      new ParseStop(),
      new ParseDestroy(),
      new ParseList() };

  public static void main(String[] args) {
    Defaults d = new Defaults();
    int ec = -1;

    if (args.length == 0) {
      help.parse(d, args);
    } else {
      String c = args[0];
      int i;
      for (i = 0; i < commands.length; i++) {
        if (commands[i].getName().equals(c)) {
          if (commands[i].getFlagParameter(args, '?')) {
            help.doHelpFor(commands[i]);
          } else {
            try {
              commands[i].parse(d, args);
              ec = 0;
            } catch (ParseFailedException e) {
              System.err.println( e.getMessage() );
            } catch (CommandFailedException e) {
              System.err.println( e.getMessage() );
            }
          }
          break;
        }
      }
      if (i == commands.length) {
        System.out.println("Unknown command " + c);
      }
    }

    System.exit(ec);
  }
}