aboutsummaryrefslogtreecommitdiffstats
path: root/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Command.java
blob: b667e3f274926755be4106fc466becac1ea452e2 (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
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
package uk.ac.cam.cl.xeno.domctl;

public abstract class Command
{
  public abstract int doCommand(Defaults d, String args[]);
  public abstract String getName();			
  public abstract String getUsage();
  public abstract String getHelpText();

  public String getStringParameter(String args[], char key, String def)
  {
    String r = getParameter (args, key);
    return (r == null) ? def : r;
  }

  public int getIntParameter(String args[], char key, int def)
  {
    String r = getParameter (args, key);
    return (r == null) ? def : (Integer.parseInt (r));
  }

  public boolean getFlagParameter(String args[], char key)
  {
    String r = getParameter (args, key);
    return (r == null) ? false : true;
  }

  public String getParameter (String args[], char key)
  {
    int i;
    String result = null;
    for (i = 0; i < args.length; i ++)
      {
	if (args[i].startsWith("-" + key)) 
	  {
	    if (args[i].length() > 2)
	      {
		result = args[i].substring(2, args[i].length());
	      }
	    else
	      {
		result = "";
	      }
	  }
      }
    return result;
  }

  public int reportXIError (String message, String cmd_array[])
  {
    int i;
    System.err.print (message + " using: ");
    for (i = 0; i < cmd_array.length; i ++) {
      System.err.print (cmd_array[i] + " ");
    }
    System.err.println();
    return -1;
  }

  public int reportError (String message)
  {
    System.err.println (message);
    return -1;
  }

  public void reportCommand (String cmd_array[])
  {
    int i;
    for (i = 0; i < cmd_array.length; i ++) {
      System.out.print (cmd_array[i] + " ");
    }
    System.out.println();
  }
}