// Path: spydra/src/main/java/com/spotify/spydra/historytools/commands/DumpLogsCommand.java
// @AutoValue
// public abstract class DumpLogsCommand {
// 
//   DumpLogsCommand() {
//   }
// 
//   public abstract String clientId();
// 
//   public abstract ApplicationId applicationId();
// 
//   public abstract String username();
// 
//   public abstract String logBucket();
// 
//   public static Builder builder() {
//     return new AutoValue_DumpLogsCommand.Builder();
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
//     public abstract Builder clientId(String clientId);
// 
//     public abstract Builder applicationId(ApplicationId jobId);
// 
//     public abstract Builder username(String username);
// 
//     public abstract Builder logBucket(String logBucket);
// 
//     public abstract DumpLogsCommand build();
//   }
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliConsts.java
// public class CliConsts {
//   public static final String SUBMIT_CMD_NAME = "submit";
//   public static final String LOGS_CMD_NAME = "dump-logs";
//   public static final String DUMP_HISTORY_CMD_NAME = "dump-history";
//   public static final String RUN_JHS_CMD_NAME = "run-jhs";
//   public static final String JOB_ID_OPTION_NAME = "application";
//   public static final String CLIENT_ID_OPTION_NAME = "clientid";
//   public static final String JAR_OPTION_NAME = "jar";
//   public static final String JARS_OPTION_NAME = "jars";
//   public static final String SPYDRA_JSON_OPTION_NAME = "spydra-json";
//   public static final String USERNAME_OPTION_NAME = "username";
//   public static final String LOG_BUCKET_OPTION_NAME = "log-bucket";
//   public static final String JOBNAME_OPTION_NAME = "job-name";
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliHelper.java
// public class CliHelper {
// 
//   private static final Logger logger = LoggerFactory.getLogger(CliHelper.class);
// 
//   /**
//    * Creates an optional long parameter with a single argument.
//    */
//   public static Option createSingleOption(String optName, String description) {
//     return createOption(optName, description, false, false);
//   }
// 
//   /**
//    * Creates a required long parameter with a single argument.
//    */
//   public static Option createRequiredSingleOption(String optName, String description) {
//     return createOption(optName, description, true, false);
//   }
// 
//   /**
//    * Creates an optional long parameter with multiple arguments.
//    */
//   public static Option createMultiOption(String optName, String description) {
//     return createOption(optName, description, false, true);
//   }
// 
//   /**
//    * Small helper for creating some of the long parameter settings we frequently
//    * use here.
//    *
//    * @param optName       name of the parameter/option
//    * @param description   description for the help text
//    * @param isRequired    whether this parameter is strictly required
//    * @param unlimitedArgs whether it supports multiple arguments, default is on argument
//    */
//   public static Option createOption(
//       String optName, String description,
//       boolean isRequired, boolean unlimitedArgs) {
// 
//     Option.Builder builder = Option.builder()
//         .longOpt(optName)
//         .hasArg()
//         .valueSeparator(',')
//         .required(isRequired)
//         .desc(description);
// 
//     if (unlimitedArgs) {
//       builder.hasArgs();
//     }
// 
//     return builder.build();
//   }
// 
//   public static CommandLine tryParse(
//       CommandLineParser parser,
//       Options options,
//       String[] args) {
//     try {
//       return parser.parse(options, args);
//     } catch (MissingOptionException moe) {
//       logger.error(moe.getMessage());
//       throw new CliParser.ParsingException(moe);
//     } catch (ParseException e) {
//       logger.error("Failed parsing options", e);
//       throw new CliParser.ParsingException(e);
//     }
//   }
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliParser.java
// public interface CliParser<T> {
// 
//   T parse(String[] args) throws IOException;
// 
//   /**
//    * Prints help for the subcommand this parser is responsible for.
//    */
//   void printHelp();
// 
//   boolean enoughArgs(String[] args);
// 
//   class ParsingException extends RuntimeException {
//     public ParsingException(Throwable cause) {
//       super(cause);
//     }
//   }
// }


import com.spotify.spydra.historytools.commands.DumpLogsCommand;
import com.spotify.spydra.submitter.runner.CliConsts;
import com.spotify.spydra.submitter.runner.CliHelper;
import com.spotify.spydra.submitter.runner.CliParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.hadoop.yarn.util.ConverterUtils;
/*-
 * -\-\-
 * Spydra
 * --
 * Copyright (C) 2016 - 2018 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.spydra.historytools;


public class DumpLogsCliParser implements CliParser<DumpLogsCommand> {

  private static final String CMD_NAME = CliConsts.DUMP_HISTORY_CMD_NAME;

  private static final Options options;

  static {
    options = buildCliOptions();
  }

  @Override
  public DumpLogsCommand parse(String[] args) {
    DefaultParser parser = new DefaultParser();
    CommandLine cmdLine;

// Path: spydra/src/main/java/com/spotify/spydra/historytools/commands/DumpLogsCommand.java
// @AutoValue
// public abstract class DumpLogsCommand {
// 
//   DumpLogsCommand() {
//   }
// 
//   public abstract String clientId();
// 
//   public abstract ApplicationId applicationId();
// 
//   public abstract String username();
// 
//   public abstract String logBucket();
// 
//   public static Builder builder() {
//     return new AutoValue_DumpLogsCommand.Builder();
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
//     public abstract Builder clientId(String clientId);
// 
//     public abstract Builder applicationId(ApplicationId jobId);
// 
//     public abstract Builder username(String username);
// 
//     public abstract Builder logBucket(String logBucket);
// 
//     public abstract DumpLogsCommand build();
//   }
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliConsts.java
// public class CliConsts {
//   public static final String SUBMIT_CMD_NAME = "submit";
//   public static final String LOGS_CMD_NAME = "dump-logs";
//   public static final String DUMP_HISTORY_CMD_NAME = "dump-history";
//   public static final String RUN_JHS_CMD_NAME = "run-jhs";
//   public static final String JOB_ID_OPTION_NAME = "application";
//   public static final String CLIENT_ID_OPTION_NAME = "clientid";
//   public static final String JAR_OPTION_NAME = "jar";
//   public static final String JARS_OPTION_NAME = "jars";
//   public static final String SPYDRA_JSON_OPTION_NAME = "spydra-json";
//   public static final String USERNAME_OPTION_NAME = "username";
//   public static final String LOG_BUCKET_OPTION_NAME = "log-bucket";
//   public static final String JOBNAME_OPTION_NAME = "job-name";
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliHelper.java
// public class CliHelper {
// 
//   private static final Logger logger = LoggerFactory.getLogger(CliHelper.class);
// 
//   /**
//    * Creates an optional long parameter with a single argument.
//    */
//   public static Option createSingleOption(String optName, String description) {
//     return createOption(optName, description, false, false);
//   }
// 
//   /**
//    * Creates a required long parameter with a single argument.
//    */
//   public static Option createRequiredSingleOption(String optName, String description) {
//     return createOption(optName, description, true, false);
//   }
// 
//   /**
//    * Creates an optional long parameter with multiple arguments.
//    */
//   public static Option createMultiOption(String optName, String description) {
//     return createOption(optName, description, false, true);
//   }
// 
//   /**
//    * Small helper for creating some of the long parameter settings we frequently
//    * use here.
//    *
//    * @param optName       name of the parameter/option
//    * @param description   description for the help text
//    * @param isRequired    whether this parameter is strictly required
//    * @param unlimitedArgs whether it supports multiple arguments, default is on argument
//    */
//   public static Option createOption(
//       String optName, String description,
//       boolean isRequired, boolean unlimitedArgs) {
// 
//     Option.Builder builder = Option.builder()
//         .longOpt(optName)
//         .hasArg()
//         .valueSeparator(',')
//         .required(isRequired)
//         .desc(description);
// 
//     if (unlimitedArgs) {
//       builder.hasArgs();
//     }
// 
//     return builder.build();
//   }
// 
//   public static CommandLine tryParse(
//       CommandLineParser parser,
//       Options options,
//       String[] args) {
//     try {
//       return parser.parse(options, args);
//     } catch (MissingOptionException moe) {
//       logger.error(moe.getMessage());
//       throw new CliParser.ParsingException(moe);
//     } catch (ParseException e) {
//       logger.error("Failed parsing options", e);
//       throw new CliParser.ParsingException(e);
//     }
//   }
// }
// 
// Path: spydra/src/main/java/com/spotify/spydra/submitter/runner/CliParser.java
// public interface CliParser<T> {
// 
//   T parse(String[] args) throws IOException;
// 
//   /**
//    * Prints help for the subcommand this parser is responsible for.
//    */
//   void printHelp();
// 
//   boolean enoughArgs(String[] args);
// 
//   class ParsingException extends RuntimeException {
//     public ParsingException(Throwable cause) {
//       super(cause);
//     }
//   }
// }


// Path: spydra/src/main/java/com/spotify/spydra/historytools/DumpLogsCliParser.java
import com.spotify.spydra.historytools.commands.DumpLogsCommand;
import com.spotify.spydra.submitter.runner.CliConsts;
import com.spotify.spydra.submitter.runner.CliHelper;
import com.spotify.spydra.submitter.runner.CliParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.hadoop.yarn.util.ConverterUtils;

/*-
 * -\-\-
 * Spydra
 * --
 * Copyright (C) 2016 - 2018 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.spydra.historytools;


public class DumpLogsCliParser implements CliParser<DumpLogsCommand> {

  private static final String CMD_NAME = CliConsts.DUMP_HISTORY_CMD_NAME;

  private static final Options options;

  static {
    options = buildCliOptions();
  }

  @Override
  public DumpLogsCommand parse(String[] args) {
    DefaultParser parser = new DefaultParser();
    CommandLine cmdLine;

    cmdLine = CliHelper.tryParse(parser, options, args);