Checks the actual number of arguments against the required number

Throws an exception if arguments are missing.

This is run from CLI automatically and usually does not need to be called directly

@throws Exception
761646
public function checkArguments()
    {
        $argc = count($this->args);

        $req = 0;
        foreach ($this->setup[$this->command]['args'] as $arg) {
            if (!$arg['required']) {
                break;
            } // last required arguments seen
            $req++;
        }

        if ($req > $argc) {
            throw new Exception("Not enough arguments", Exception::E_OPT_ARG_REQUIRED);
        }
    }
322995
private function checkRequired()
    {
        // Loop through all params
        foreach ($this->params as $param) {
            if (array_key_exists('required', $param) && $param['required'] == true) {
                if (!array_key_exists($param['name'], $this->pinputs)) {
                    throw new \Exception('Parameter "' . $param['name'] . '" is required');
                }
            }
        }

        // Loop through all options
        foreach ($this->options as $key => $option) {
            // if option is required
            if (array_key_exists('required', $option) && $option['required'] == true) {
                // check that it is defined in pinputs
                if ($this->pinputs[$option['short']] == false) {
                    throw new \Exception('Option "' . $option['help'] . '" is required');
                }
            }
        }

    }
230128
private void doit(String[] args)
    {
        try
        {
            // load parameters from the commandline
            loadParameters(args);

            // Try to load the private key
            importKeyPair();
        }
        catch (Exception e)
        {
            System.out.println("Exception: " + e.getMessage());
            e.printStackTrace();
            
            System.exit(23);
        }
    }
100455
public int run(String[] args) throws Exception {
    if (args.length != 2) {
      System.err.println("Usage: "+getClass().getName()+" <nMaps> <nSamples>");
      ToolRunner.printGenericCommandUsage(System.err);
      return -1;
    }
    
    final int nMaps = Integer.parseInt(args[0]);
    final long nSamples = Long.parseLong(args[1]);
        
    System.out.println("Number of Maps  = " + nMaps);
    System.out.println("Samples per Map = " + nSamples);
        
    final JobConf jobConf = new JobConf(getConf(), getClass());
    System.out.println("Estimated value of Pi is "
        + estimate(nMaps, nSamples, jobConf));
    return 0;
  }
5933
public static void main(String[] args) throws Exception {
    ArgP argp = new ArgP();
    CliOptions.addCommon(argp);
    argp.addOption("--use-data-table",
        "Scan against the raw data table instead of the meta data table.");
    args = CliOptions.parse(argp, args);
    if (args == null) {
      usage(argp, "Invalid usage");
      System.exit(2);
    } else if (args.length < 1) {
      usage(argp, "Not enough arguments");
      System.exit(2);
    }
    
    final boolean use_data_table = argp.has("--use-data-table");
    
    Config config = CliOptions.getConfig(argp);
    final TSDB tsdb = new TSDB(config);
    tsdb.checkNecessaryTablesExist().joinUninterruptibly();
    
    int rc;
    try {
      rc = runCommand(tsdb, use_data_table, args);
    } finally {
      try {
        tsdb.getClient().shutdown().joinUninterruptibly();
        LOG.info("Gracefully shutdown the TSD");
      } catch (Exception e) {
        LOG.error("Unexpected exception while shutting down", e);
        rc = 42;
      }
    }
    System.exit(rc);
  }
670042
function checkArgs(args) {
  if (args.length !== 2) {
    console.warn(`WWWW Checking claudia args: args.length !== 2, is: ${args.length}`, inspect({args}));
  }
}
1018096
public static void main(String[] args) throws Exception {

		boolean valid = true;
		boolean requiredArguments = false;

		String imageFormat = null;
		boolean rawImage = false;
		File inputDirectory = null;
		TileFormatType tileType = null;
		File geoPackageFile = null;
		String tileTable = null;

		for (int i = 0; valid && i < args.length; i++) {

			String arg = args[i];

			// Handle optional arguments
			if (arg.startsWith(ARGUMENT_PREFIX)) {

				String argument = arg.substring(ARGUMENT_PREFIX.length());

				switch (argument) {

				case ARGUMENT_IMAGE_FORMAT:
					if (i < args.length) {
						imageFormat = args[++i];
					} else {
						valid = false;
						System.out.println("Error: Image Format argument '"
								+ arg + "' must be followed by a image format");
					}
					break;

				case ARGUMENT_RAW_IMAGE:
					rawImage = true;
					break;

				default:
					valid = false;
					System.out.println("Error: Unsupported arg: '" + arg + "'");
				}

			} else {
				// Set required arguments in order
				if (inputDirectory == null) {
					inputDirectory = new File(arg);
				} else if (tileType == null) {
					tileType = TileFormatType.valueOf(arg.toUpperCase());
				} else if (geoPackageFile == null) {
					geoPackageFile = new File(arg);
				} else if (tileTable == null) {
					tileTable = arg;
					requiredArguments = true;
				} else {
					valid = false;
					System.out.println("Error: Unsupported extra argument: "
							+ arg);
				}
			}
		}

		if (!valid || !requiredArguments) {
			printUsage();
		} else {
			// Read the tiles
			try {
				readTiles(geoPackageFile, tileTable, inputDirectory,
						imageFormat, tileType, rawImage);
			} catch (Exception e) {
				printUsage();
				throw e;
			}
		}

	}
1030675
private void checkParaCount() {
        int[] saveLimits;
        byte[] saveLevels;
        int count = paraCount;
        if (count <= paras_level.length)
            return;
        int oldLength = paras_level.length;
        saveLimits = paras_limit;
        saveLevels = paras_level;
        try {
            paras_limit = new int[count * 2];
            paras_level = new byte[count * 2];
        } catch (Exception e) {
            throw new OutOfMemoryError("Failed to allocate memory for paras");
        }
        System.arraycopy(saveLimits, 0, paras_limit, 0, oldLength);
        System.arraycopy(saveLevels, 0, paras_level, 0, oldLength);
    }
916751
public int run(String[] args) throws Exception {

    Configuration hbaseConf = HBaseConfiguration.create(getConf());

    // Grab input args and allow for -Dxyz style arguments
    String[] otherArgs =
        new GenericOptionsParser(hbaseConf, args).getRemainingArgs();

    // Grab the arguments we're looking for.
    CommandLine commandLine = parseArgs(otherArgs);

    // Grab the cluster argument
    String cluster = commandLine.getOptionValue("c");
    LOG.info("cluster=" + cluster);

    // Number of parallel threads to use
    int threadCount = 1;
    if (commandLine.hasOption("t")) {
      try {
        threadCount = Integer.parseInt(commandLine.getOptionValue("t"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "Provided thread-count argument (-t) is not a number: "
                + commandLine.getOptionValue("t"),
            nfe);
      }
      if (threadCount < 1) {
        throw new IllegalArgumentException(
            "Cannot run fewer than 1 thread. Provided thread-count argument (-t): "
                + threadCount);
      }
    }
    LOG.info("threadCount=" + threadCount);

    boolean reprocess = commandLine.hasOption("r");
    LOG.info("reprocess=" + reprocess);

    // Grab the batch-size argument
    int batchSize;
    if (commandLine.hasOption("b")) {
      try {
        batchSize = Integer.parseInt(commandLine.getOptionValue("b"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "batch size option -b is is not a valid number: "
                + commandLine.getOptionValue("b"),
            nfe);
      }
      // Additional check
      if (batchSize < 1) {
        throw new IllegalArgumentException(
            "Cannot process files in batches smaller than 1. Specified batch size option -b is: "
                + commandLine.getOptionValue("b"));
      }
    } else {
      batchSize = DEFAULT_BATCH_SIZE;
    }

    // Grab the costfile argument

    String costFilePath = commandLine.getOptionValue("zf");
    LOG.info("cost properties file on hdfs=" + costFilePath);
    if (costFilePath == null)
      costFilePath = Constants.COST_PROPERTIES_HDFS_DIR;
    Path hdfsPath = new Path(costFilePath + Constants.COST_PROPERTIES_FILENAME);
    // add to distributed cache
    DistributedCache.addCacheFile(hdfsPath.toUri(), hbaseConf);

    // Grab the machine type argument
    String machineType = commandLine.getOptionValue("m");
    // set it as part of conf so that the
    // hRaven job can access it in the mapper
    hbaseConf.set(Constants.HRAVEN_MACHINE_TYPE, machineType);

    // check if re-aggregate option is forced on
    // if yes, we need to aggregate for this job inspite of
    // job having aggregation done status in raw table
    boolean reAggregateFlagValue = false;
    if (commandLine.hasOption("ra")) {
      String reaggregateFlag = commandLine.getOptionValue("ra");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(reaggregateFlag)) {
        LOG.info(" reaggregateFlag is: " + reaggregateFlag);
        if (StringUtils.equalsIgnoreCase(reaggregateFlag,
            Boolean.TRUE.toString())) {
          reAggregateFlagValue = true;
        }
      }
    }
    LOG.info(AggregationConstants.RE_AGGREGATION_FLAG_NAME + "="
        + reAggregateFlagValue);
    hbaseConf.setBoolean(AggregationConstants.RE_AGGREGATION_FLAG_NAME,
        reAggregateFlagValue);

    // set aggregation to off by default
    boolean aggFlagValue = false;
    if (commandLine.hasOption("a")) {
      String aggregateFlag = commandLine.getOptionValue("a");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(aggregateFlag)) {
        LOG.info(" aggregateFlag is: " + aggregateFlag);
        if (StringUtils.equalsIgnoreCase(aggregateFlag,
            Boolean.TRUE.toString())) {
          aggFlagValue = true;
        }
      }
    }
    if (reprocess) {
      // turn off aggregation if reprocessing is true
      // we don't want to inadvertently aggregate again while re-processing
      // re-aggregation needs to be a conscious setting
      aggFlagValue = false;
    }
    LOG.info(AggregationConstants.AGGREGATION_FLAG_NAME + "=" + aggFlagValue);
    hbaseConf.setBoolean(AggregationConstants.AGGREGATION_FLAG_NAME,
        aggFlagValue);

    String processFileSubstring = null;
    if (commandLine.hasOption("p")) {
      processFileSubstring = commandLine.getOptionValue("p");
    }
    LOG.info("processFileSubstring=" + processFileSubstring);

    // hbase.client.keyvalue.maxsize somehow defaults to 10 MB and we have
    // history files exceeding that. Disable limit.
    hbaseConf.setInt("hbase.client.keyvalue.maxsize", 0);

    // Shove this into the jobConf so that we can get it out on the task side.
    hbaseConf.setStrings(Constants.CLUSTER_JOB_CONF_KEY, cluster);

    boolean success = false;
    Connection hbaseConnection = null;
    try {
      hbaseConnection = ConnectionFactory.createConnection(hbaseConf);
      if (reprocess) {
        success = reProcessRecords(hbaseConf, hbaseConnection, cluster,
            batchSize, threadCount);
      } else {
        success = processRecords(hbaseConf, hbaseConnection, cluster, batchSize,
            threadCount, processFileSubstring);
      }
    } finally {
      if (hbaseConnection == null) {
        success = false;
      } else {
        hbaseConnection.close();
      }
    }

    // Return the status
    return success ? 0 : 1;
  }
312991
def enforce_count(args, params, diff = 0)
      num_args = args.size
      num_params = params == 'V' ? 0 : params.size + diff
      if num_args != num_params
        raise ArgumentError, "wrong number of parameters: expected #{num_params}, got #{num_args}"
      end
    end
342806
public static void main(String args[]) throws Exception {
		String imageFolder = "C:/images/";
		String imagFilename = "test.jpg";
		String[] codebookFiles = { "C:/codebook1.csv", "C:/codebook2.csv", "C:/codebook3.csv",
				"C:/codebook4.csv" };
		int[] numCentroids = { 64, 64, 64, 64 };

		String pcaFilename = "C:/pca.txt";
		int initialLength = numCentroids.length * numCentroids[0] * AbstractFeatureExtractor.SURFLength;
		int targetLength = 128;

		ImageVectorization imvec = new ImageVectorization(imageFolder, imagFilename, targetLength, 512 * 384);
		ImageVectorization.setFeatureExtractor(new SURFExtractor());
		double[][][] codebooks = AbstractFeatureAggregator.readQuantizers(codebookFiles, numCentroids,
				AbstractFeatureExtractor.SURFLength);
		ImageVectorization.setVladAggregator(new VladAggregatorMultipleVocabularies(codebooks));
		if (targetLength < initialLength) {
			PCA pca = new PCA(targetLength, 1, initialLength, true);
			pca.loadPCAFromFile(pcaFilename);
			ImageVectorization.setPcaProjector(pca);
		}
		imvec.setDebug(true);

		ImageVectorizationResult imvr = imvec.call();
		System.out.println(imvr.getImageName() + ": " + Arrays.toString(imvr.getImageVector()));
	}
1238361
private void handleArgInput(final String arg, final Deque<String> args, final Argument argument) {
        final Map.Entry<String, String> entry = parse(arg, args);
        if (entry.getValue() == null) {
            throw new BuildException("Missing value for input " + entry.getKey());
        }
        inputs.add(argument.getValue((String) entry.getValue()));
    }
586767
public static int validate(String... argv) throws InterruptedException {
    if (argv.length < 1) {
      printHelp("Target not specified.");
      return -2;
    }
    String command = argv[0];
    String name = null;
    String[] args;
    int argsLength = 0;
    // Find all non-option command line arguments.
    while (argsLength < argv.length && !argv[argsLength].startsWith("-")) {
      argsLength++;
    }
    if (argsLength > 1) {
      name = argv[1];
      args = Arrays.copyOfRange(argv, 2, argv.length);
    } else {
      args = Arrays.copyOfRange(argv, 1, argv.length);
    }

    CommandLine cmd;
    try {
      cmd = parseArgsAndOptions(OPTIONS, args);
    } catch (InvalidArgumentException e) {
      System.err.format("Invalid argument: %s.%n", e.getMessage());
      return -1;
    }
    if (command != null && command.equals("list")) {
      printTasks();
      return 0;
    }
    return runTasks(command, name, cmd);
  }
642010
public static void executeCommand(String[] args) throws Exception {
        String subCmd = (args.length > 0) ? args[0] : "";
        args = AdminToolUtils.copyArrayCutFirst(args);
        if(subCmd.equals("get")) {
            SubCommandQuotaGet.executeCommand(args);
        } else if(subCmd.equals("set")) {
            SubCommandQuotaSet.executeCommand(args);
        } else if(subCmd.equals("reserve-memory")) {
            SubCommandQuotaReserveMemory.executeCommand(args);
        } else if(subCmd.equals("unset")) {
            SubCommandQuotaUnset.executeCommand(args);
        } else {
            printHelp(System.out);
        }
    }
787883
protected function checkRequirements()
    {
        parent::checkRequirements();

        // verify there is at least one item added
        if (empty($this->items) || $this->items->count() === 0) {
            throw new \Genesis\Exceptions\ErrorParameter('Empty (null) required parameter: items');
        }
    }
795246
def check_argument_size(args)
      if @command.numerical_arg_size? && args.size != @command.arg_size
        command_size, args_size = args.size > @command.arg_size ?
          [@command.arg_size, args.size] :
          [@command.arg_size - 1, args.size - 1]
        raise CommandArgumentError,
          "wrong number of arguments (#{args_size} for #{command_size})"
      end
    end
133592
final private function get_argument_count($callback, $accepted_args = 1)
    {
        try {
            if (\is_string($callback) && \is_callable([$this, $callback])) {
                $reflector = new ReflectionMethod($this, $callback);
                return $reflector->getNumberOfParameters();
            }

            if (\is_object($callback) && $callback instanceof Closure) {
                $reflector = new ReflectionFunction($callback);
                return $reflector->getNumberOfParameters();
            }
        } catch (ReflectionException $exception) {
            \error_log($exception->getMessage());
        }

        return $accepted_args ? $accepted_args : 1;
    }