FileDocCategorySizeDatePackage
BaseCommand.javaAPI DocAndroid 5.1 API4206Thu Mar 12 22:22:10 GMT 2015com.android.internal.os

BaseCommand

public abstract class BaseCommand extends Object

Fields Summary
protected String[]
mArgs
private int
mNextArg
private String
mCurArgData
public static final String
FATAL_ERROR_CODE
public static final String
NO_SYSTEM_ERROR_CODE
public static final String
NO_CLASS_ERROR_CODE
Constructors Summary
Methods Summary
public java.lang.StringnextArg()
Return the next argument on the command line, whatever it is; if there are no arguments left, return null.

        if (mCurArgData != null) {
            String arg = mCurArgData;
            mCurArgData = null;
            return arg;
        } else if (mNextArg < mArgs.length) {
            return mArgs[mNextArg++];
        } else {
            return null;
        }
    
public java.lang.StringnextArgRequired()
Return the next argument on the command line, whatever it is; if there are no arguments left, throws an IllegalArgumentException to report this to the user.

        String arg = nextArg();
        if (arg == null) {
            String prev = mArgs[mNextArg - 1];
            throw new IllegalArgumentException("Argument expected after \"" + prev + "\"");
        }
        return arg;
    
public java.lang.StringnextOption()
Return the next option on the command line -- that is an argument that starts with '-'. If the next argument is not an option, null is returned.

        if (mCurArgData != null) {
            String prev = mArgs[mNextArg - 1];
            throw new IllegalArgumentException("No argument expected after \"" + prev + "\"");
        }
        if (mNextArg >= mArgs.length) {
            return null;
        }
        String arg = mArgs[mNextArg];
        if (!arg.startsWith("-")) {
            return null;
        }
        mNextArg++;
        if (arg.equals("--")) {
            return null;
        }
        if (arg.length() > 1 && arg.charAt(1) != '-") {
            if (arg.length() > 2) {
                mCurArgData = arg.substring(2);
                return arg.substring(0, 2);
            } else {
                mCurArgData = null;
                return arg;
            }
        }
        mCurArgData = null;
        return arg;
    
public abstract voidonRun()
Implement the command.

public abstract voidonShowUsage(java.io.PrintStream out)
Print help text for the command.

public voidrun(java.lang.String[] args)
Call to run the command.


              
        
        if (args.length < 1) {
            onShowUsage(System.out);
            return;
        }

        mArgs = args;
        mNextArg = 0;
        mCurArgData = null;

        try {
            onRun();
        } catch (IllegalArgumentException e) {
            onShowUsage(System.err);
            System.err.println();
            System.err.println("Error: " + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(1);
        }
    
public voidshowError(java.lang.String message)
Convenience to show usage information to error output along with an error message.

        onShowUsage(System.err);
        System.err.println();
        System.err.println(message);
    
public voidshowUsage()
Convenience to show usage information to error output.

        onShowUsage(System.err);