Search in sources :

Example 1 with DumpUsageException

use of com.facebook.stetho.dumpapp.DumpUsageException in project stetho by facebook.

the class APODDumperPlugin method dump.

@Override
public void dump(DumperContext dumpContext) throws DumpException {
    PrintStream writer = dumpContext.getStdout();
    Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();
    String command = ArgsHelper.nextOptionalArg(argsIter, null);
    if (CMD_LIST.equalsIgnoreCase(command)) {
        doList(writer);
    } else if (CMD_DELETE.equalsIgnoreCase(command)) {
        doRemove(writer, argsIter);
    } else if (CMD_CLEAR.equalsIgnoreCase(command)) {
        doClear(writer);
    } else if (CMD_REFRESH.equalsIgnoreCase(command)) {
        doRefresh(writer);
    } else {
        usage(writer);
        if (command != null) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DumpUsageException(com.facebook.stetho.dumpapp.DumpUsageException)

Example 2 with DumpUsageException

use of com.facebook.stetho.dumpapp.DumpUsageException in project stetho by facebook.

the class SharedPreferencesDumperPlugin method doWrite.

/**
   * Executes command to update one value in the shared preferences
   */
// We explicitly want commit() so that the dumper blocks while the write occurs.
@SuppressLint("CommitPrefEdits")
private void doWrite(List<String> args) throws DumpUsageException {
    String usagePrefix = "Usage: prefs write <path> <key> <type> <value>, where type is one of: ";
    Iterator<String> argsIter = args.iterator();
    String path = nextArg(argsIter, "Expected <path>");
    String key = nextArg(argsIter, "Expected <key>");
    String typeName = nextArg(argsIter, "Expected <type>");
    Type type = Type.of(typeName);
    if (type == null) {
        throw new DumpUsageException(Type.appendNamesList(new StringBuilder(usagePrefix), ", ").toString());
    }
    SharedPreferences sharedPreferences = getSharedPreferences(path);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    switch(type) {
        case BOOLEAN:
            editor.putBoolean(key, Boolean.valueOf(nextArgValue(argsIter)));
            break;
        case INT:
            editor.putInt(key, Integer.valueOf(nextArgValue(argsIter)));
            break;
        case LONG:
            editor.putLong(key, Long.valueOf(nextArgValue(argsIter)));
            break;
        case FLOAT:
            editor.putFloat(key, Float.valueOf(nextArgValue(argsIter)));
            break;
        case STRING:
            editor.putString(key, nextArgValue(argsIter));
            break;
        case SET:
            putStringSet(editor, key, argsIter);
            break;
    }
    editor.commit();
}
Also used : SharedPreferences(android.content.SharedPreferences) DumpUsageException(com.facebook.stetho.dumpapp.DumpUsageException) SuppressLint(android.annotation.SuppressLint)

Example 3 with DumpUsageException

use of com.facebook.stetho.dumpapp.DumpUsageException in project fresco by facebook.

the class BaseFrescoStethoPlugin method dump.

/**
   * Entry point for the Stetho dumpapp script.
   *
   * {@link #initialize} must have been called in the app before running dumpapp.
   */
@Override
public void dump(DumperContext dumpContext) throws DumpException {
    ensureInitialized();
    List<String> args = dumpContext.getArgsAsList();
    PrintStream writer = dumpContext.getStdout();
    String cmd = args.isEmpty() ? null : args.get(0);
    List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size());
    if (cmd != null && cmd.equals("memcache")) {
        memcache(writer, rest);
    } else if (cmd != null && cmd.equals("diskcache")) {
        diskcache(mMainFileCache, "Main", writer, rest);
        diskcache(mSmallFileCache, "Small", writer, rest);
    } else {
        usage(writer);
        if (TextUtils.isEmpty(cmd)) {
            throw new DumpUsageException("Missing command");
        } else {
            throw new DumpUsageException("Unknown command: " + cmd);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) DumpUsageException(com.facebook.stetho.dumpapp.DumpUsageException)

Aggregations

DumpUsageException (com.facebook.stetho.dumpapp.DumpUsageException)3 PrintStream (java.io.PrintStream)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1