Check if the first argument is an existing command.
355436
def parse_args(self, ctx, args):
        """"""
        if args and args[0] in self.commands:
            args.insert(0, '')
        super(OptionalGroup, self).parse_args(ctx, args)
946717
def check_command(self, command):
        

        # Use `command` to see if command is callable, store exit code
        code = os.system("command -v {0} >/dev/null 2>&1 || {{ exit 1; }}".format(command))

        # If exit code is not 0, report which command failed and return False, else return True
        if code != 0:
            print("Command is not callable: {0}".format(command))
            return False
        else:
            return True
1025381
def is_app(command, *app_names, **kwargs):
    """"""

    at_least = kwargs.pop('at_least', 0)
    if kwargs:
        raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys()))

    if len(command.script_parts) > at_least:
        return command.script_parts[0] in app_names

    return False
233530
def check_commands(self, cmd_list):
        
        # if a string is passed then convert it to a list.  This prevents an
        # easy mistake that could be made
        if isinstance(cmd_list, basestring):
            cmd_list = [cmd_list]

        for cmd in cmd_list:
            if self.command_run("which {}".format(cmd)) == 0:
                return cmd
562050
function(command, arg) {
    if (!arg) {
      arg = 'default';
    }

    if (!commands[command]) {
      grunt.fail.fatal('Command [' + command + '] not found.');
    }

    // Check arg
    if (typeof (commands[command]) !== 'function') {
      if (!commands[command][arg]) {
        grunt.fail.fatal('Argument [' + arg + '] for [' + command
            + '] not found.');
      }
    }

    var func = (arg) ? commands[command][arg] : commands[command];
    if (!func) {
      func = commands[command]; // fallback to the main function
    }

    var options = this.options();
    var docker = (options.docker) ? new Docker(options.docker) : null;
    var done = this.async();

    var callback = function(e) {
      if (e) {
        grunt.fail.warn(e);
      }
      done();
    };

    func.apply(this, [ grunt, docker, options, callback, arg ]);
  }
1167716
def run_check(self, check, argument_names):
        """"""
        arguments = []
        for name in argument_names:
            arguments.append(getattr(self, name))
        return check(*arguments)
1237524
def _ensure_exists(wrapped):
    '''
    
    '''
    @functools.wraps(wrapped)
    def check_exists(name, *args, **kwargs):
        if not exists(name):
            raise CommandExecutionError(
                'Container \'{0}\' does not exist'.format(name)
            )
        return wrapped(name, *args, **salt.utils.args.clean_kwargs(**kwargs))
    return check_exists
552328
protected function findCommand(): void
    {
        if (!isset($this->args[0])) {
            return;
        }

        $newArgs = [];

        foreach ($this->args as $key => $value) {
            if ($key === 0) {
                $this->command = \trim($value);
            } elseif (\is_int($key)) {
                $newArgs[] = $value;
            } else {
                $newArgs[$key] = $value;
            }
        }

        $this->args = $newArgs;
    }
413442
def mod_run_check(cmd_kwargs, onlyif, unless):
    '''
    
    '''
    cmd_kwargs = copy.deepcopy(cmd_kwargs)
    cmd_kwargs.update({
        'use_vt': False,
        'bg': False,
        'ignore_retcode': True,
        'python_shell': True,
    })

    if onlyif is not None:
        if not isinstance(onlyif, list):
            onlyif = [onlyif]

        for command in onlyif:
            if not isinstance(command, six.string_types) and command:
                # Boolean or some other non-string which resolves to True
                continue
            try:
                if __salt__['cmd.retcode'](command, **cmd_kwargs) == 0:
                    # Command exited with a zero retcode
                    continue
            except Exception as exc:
                log.exception(
                    'The following onlyif command raised an error: %s',
                    command
                )
                return {
                    'comment': 'onlyif raised error ({0}), see log for '
                               'more details'.format(exc),
                    'result': False
                }

            return {'comment': 'onlyif condition is false',
                    'skip_watch': True,
                    'result': True}

    if unless is not None:
        if not isinstance(unless, list):
            unless = [unless]

        for command in unless:
            if not isinstance(command, six.string_types) and not command:
                # Boolean or some other non-string which resolves to False
                break
            try:
                if __salt__['cmd.retcode'](command, **cmd_kwargs) != 0:
                    # Command exited with a non-zero retcode
                    break
            except Exception as exc:
                log.exception(
                    'The following unless command raised an error: %s',
                    command
                )
                return {
                    'comment': 'unless raised error ({0}), see log for '
                               'more details'.format(exc),
                    'result': False
                }
        else:
            return {'comment': 'unless condition is true',
                    'skip_watch': True,
                    'result': True}

    return True
1164930
function(name, args) {
        if (name === "stream") {
            return true;
        }

        if (name !== "reload") {
            return false;
        }

        var firstArg = args[0];

        /**
         * If here, it's reload with args
         */
        if (_.isObject(firstArg)) {
            if (!Array.isArray(firstArg) && Object.keys(firstArg).length) {
                return firstArg.stream === true;
            }
        }

        return false;
    }
38912
def _add_two_argument_command(self, command, arg1, arg2):
        """"""
        self.lines.append("{} {} {}".format(command, arg1, arg2))
979746
def has_shell_command(self, command):
        
        try:
            output = self.shell(['command', '-v',
                                 command]).decode('utf-8').strip()
            return command in output
        except AdbError:
            # If the command doesn't exist, then 'command -v' can return
            # an exit code > 1.
            return False
248685
def check_tool(command):
    
    assert is_iterable_typed(command, basestring)
    #FIXME: why do we check the first and last elements????
    if check_tool_aux(command[0]) or check_tool_aux(command[-1]):
        return command
1270380
def __args_check(self, valid, args=None, kwargs=None):
        '''
        
        '''
        if not isinstance(valid, list):
            valid = [valid]
        for cond in valid:
            if not isinstance(cond, dict):
                # Invalid argument
                continue
            # whitelist args, kwargs
            cond_args = cond.get('args', [])
            good = True
            for i, cond_arg in enumerate(cond_args):
                if args is None or len(args) <= i:
                    good = False
                    break
                if cond_arg is None:  # None == '.*' i.e. allow any
                    continue
                if not self.match_check(cond_arg, six.text_type(args[i])):
                    good = False
                    break
            if not good:
                continue
            # Check kwargs
            cond_kwargs = cond.get('kwargs', {})
            for k, v in six.iteritems(cond_kwargs):
                if kwargs is None or k not in kwargs:
                    good = False
                    break
                if v is None:  # None == '.*' i.e. allow any
                    continue
                if not self.match_check(v, six.text_type(kwargs[k])):
                    good = False
                    break
            if good:
                return True
        return False
239428
public static void checkNumOfArgsNoMoreThan(Command cmd, CommandLine cl, int n) throws
      InvalidArgumentException {
    if (cl.getArgs().length > n) {
      throw new InvalidArgumentException(ExceptionMessage.INVALID_ARGS_NUM_TOO_MANY
          .getMessage(cmd.getCommandName(), n, cl.getArgs().length));
    }
  }
264139
def is_file(dirname):
    ''''''
    if not os.path.isfile(dirname):
        msg = "{0} is not an existing file".format(dirname)
        raise argparse.ArgumentTypeError(msg)
    else:
        return dirname
149658
function (args1, args2) {
	var i,
		len = args1.length;
	if (len === args2.length) {
		for (i = 0; i < len; i += 1) {
			var arg1 = args1[i],
				arg2 = args2[i];
			if (arg1 !== arg2) {
				return false;
			}
		}
		return true;
	} else {
		return false;
	}
}