Move to Android N-MR1 SDK.
[android_tools.git] / sdk / sources / android-25 / com / android / commands / svc / Svc.java
blob2cccd1a4dc9207172391fe27643554ddf6e1bcc0
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.commands.svc;
19 public class Svc {
21 public static abstract class Command {
22 private String mName;
24 public Command(String name) {
25 mName = name;
28 public String name() {
29 return mName;
32 public abstract String shortHelp(); // should fit on one short line
33 public abstract String longHelp(); // take as much space as you need, 75 col max
34 public abstract void run(String[] args); // run the command
37 public static void main(String[] args) {
38 if (args.length >= 1) {
39 Command c = lookupCommand(args[0]);
40 if (c != null) {
41 c.run(args);
42 return;
45 COMMAND_HELP.run(args);
48 private static Command lookupCommand(String name) {
49 final int N = COMMANDS.length;
50 for (int i=0; i<N; i++) {
51 Command c = COMMANDS[i];
52 if (c.name().equals(name)) {
53 return c;
56 return null;
59 public static final Command COMMAND_HELP = new Command("help") {
60 public String shortHelp() {
61 return "Show information about the subcommands";
63 public String longHelp() {
64 return shortHelp();
66 public void run(String[] args) {
67 if (args.length == 2) {
68 Command c = lookupCommand(args[1]);
69 if (c != null) {
70 System.err.println(c.longHelp());
71 return;
75 System.err.println("Available commands:");
76 final int N = COMMANDS.length;
77 int maxlen = 0;
78 for (int i=0; i<N; i++) {
79 Command c = COMMANDS[i];
80 int len = c.name().length();
81 if (maxlen < len) {
82 maxlen = len;
85 String format = " %-" + maxlen + "s %s";
86 for (int i=0; i<N; i++) {
87 Command c = COMMANDS[i];
88 System.err.println(String.format(format, c.name(), c.shortHelp()));
93 public static final Command[] COMMANDS = new Command[] {
94 COMMAND_HELP,
95 new PowerCommand(),
96 new DataCommand(),
97 new WifiCommand(),
98 new UsbCommand(),
99 new NfcCommand(),