content: package com.r00t.cli;
  
  import org.apache.commons.cli.*;
  
  import java.io.File;
  
  /**
   * Command line argument parser
   * Responsible for parsing and processing command line arguments
   */
  public class CommandLineParser {
      
      private final Options options;
      
      public CommandLineParser() {
          this.options = createOptions();
      }
      
      private Options createOptions() {
          Options options = new Options();
          options.addOption("h", "help", false, "show help information");
          options.addOption("f", "file", true, "file path to upload");
          options.addOption("t", "target", true, "target URL");
          options.addOption("l", "list", true, "target list file path (one URL per line)");
          options.addOption("o", "output", true, "output file path for batch scan results");
          options.addOption("T", "threads", true, "number of threads for batch scanning (default: 5)");
          return options;
      }
      
      public CommandLineResult parse(String[] args) throws ParseException {
          CommandLine cmd = new DefaultParser().parse(options, args);
          
          if (cmd.hasOption("h") || (!cmd.hasOption("t") && !cmd.hasOption("l"))) {
              return new CommandLineResult(true, null, null, null, null, 0);
          }
          
          if (cmd.hasOption("t") && cmd.hasOption("l")) {
              return new CommandLineResult(false, null, null, null, null, 0, "Cannot use both -t and -l options");
          }
          
          String target = cmd.getOptionValue("t");
          String targetListPath = cmd.getOptionValue("l");
          String inputFilePath = expandPath(cmd.getOptionValue("f"));
          String outputFilePath = expandPath(cmd.getOptionValue("o"));
          
          int threadCount = parseThreadCount(cmd);
          if (threadCount == -1) {
              return new CommandLineResult(false, null, null, null, null, 0, "Invalid thread count");
          }
          
          validateFiles(inputFilePath, targetListPath);
          return new CommandLineResult(false, target, inputFilePath, targetListPath, outputFilePath, threadCount);
      }
      
      public void printHelp() {
          new HelpFormatter().printHelp("java -jar YongYou-U8C-Exploit-v1.0.jar", options);
      }
      
      private String expandPath(String path) {
          if (path != null && path.startsWith("~")) {
              return System.getProperty("user.home") + path.substring(1);
          }
          return path;
      }
      
      private int parseThreadCount(CommandLine cmd) {
          if (!cmd.hasOption("T")) return 5;
          try {
              int count = Integer.parseInt(cmd.getOptionValue("T"));
              return (count >= 1 && count <= 50) ? count : -1;
          } catch (NumberFormatException e) {
              return -1;
          }
      }
      
      private void validateFiles(String inputFilePath, String targetListPath) throws ParseException {
          if (inputFilePath != null && !new File(inputFilePath).exists()) {
              throw new ParseException("File does not exist: " + inputFilePath);
          }
          if (targetListPath != null && !new File(targetListPath).exists()) {
              throw new ParseException("Target list file does not exist: " + targetListPath);
          }
      }
      
      public static class CommandLineResult {
          private final boolean showHelp;
          private final String target;
          private final String inputFilePath;
          private final String targetListPath;
          private final String outputFilePath;
          private final int threadCount;
          private final String errorMessage;
          
          public CommandLineResult(boolean showHelp, String target, String inputFilePath, String targetListPath, String outputFilePath, int threadCount) {
              this(showHelp, target, inputFilePath, targetListPath, outputFilePath, threadCount, null);
          }
          
          public CommandLineResult(boolean showHelp, String target, String inputFilePath, String targetListPath, String outputFilePath, int threadCount, String errorMessage) {
              this.showHelp = showHelp;
              this.target = target;
              this.inputFilePath = inputFilePath;
              this.targetListPath = targetListPath;
              this.outputFilePath = outputFilePath;
              this.threadCount = threadCount;
              this.errorMessage = errorMessage;
          }
          
          public boolean shouldShowHelp() { return showHelp; }
          public String getTarget() { return target; }
          public String getInputFilePath() { return inputFilePath; }
          public String getTargetListPath() { return targetListPath; }
          public String getOutputFilePath() { return outputFilePath; }
          public int getThreadCount() { return threadCount; }
          public String getErrorMessage() { return errorMessage; }
          public boolean hasError() { return errorMessage != null; }
          public boolean isBatchMode() { return targetListPath != null; }
      }
  }
  