class ListAction implements Runnable {

  @Override public void run() {
    List<String> listOptions = listActionConfig.listType;
    if (listOptions == null) {
      try {
        printing.printAllSanitizedSecrets(keywhizClient.allSecrets());
      } catch (IOException e) {
        throw Throwables.propagate(e);
      }
      return;
    }

    List<String> options = Arrays.asList(listOptions.get(0).split(","));

    String firstOption = options.get(0).toLowerCase().trim();
    try {
      switch (firstOption) {
        case "groups":
          printing.printAllGroups(keywhizClient.allGroups());
          break;

        case "clients":
          printing.printAllClients(keywhizClient.allClients());
          break;

        case "secrets":
          if (listActionConfig.idx == null && listActionConfig.num == null) {
            printing.printAllSanitizedSecrets(keywhizClient.allSecrets());
          } else if (listActionConfig.idx != null && listActionConfig.num != null) {
            checkArgument(listActionConfig.idx >= 0);
            checkArgument(listActionConfig.num >= 0);
            if (listActionConfig.newestFirst == null) {
              printing.printAllSanitizedSecrets(keywhizClient.allSecretsBatched(listActionConfig.idx, listActionConfig.num, true));
            }  else {
              printing.printAllSanitizedSecrets(keywhizClient.allSecretsBatched(listActionConfig.idx, listActionConfig.num, listActionConfig.newestFirst));
            }
          } else {
            throw new AssertionError("Both idx and num must be provided for batched secret queries");
          }
          break;

        default:
          throw new AssertionError("Invalid list option: " + firstOption);
      }
    } catch(IOException e) {
      throw Throwables.propagate(e);
    }
  }

  public  ListAction(ListActionConfig listActionConfig, KeywhizClient client, Printing printing);

}