参数和选项有什么区别?

24

我并不确定这个术语的级别,但在php框架Laravel中有一个命令行工具叫做Artisan,用于创建cronjobs(也称为命令)。当你创建一个命令时,可以像这样指定参数和选项:

/**
 * Get the console command arguments.
 *
 * @return array
 */
protected function getArguments()
{
    return array(
        array('example', InputArgument::REQUIRED, 'An example argument.'),
    );
}

/**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return array(
            array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
        );
    }

这两者有什么区别?


3
哈哈,我刚刚读了自己以前的问题,像是这样的:“论点和观点有什么区别。” 真是深奥的哲学问题。 - Himmators
1个回答

27

看一下 artisan migrate:make 命令的帮助文档:

Usage:
 migrate:make [--bench[="..."]] [--create] [--package[="..."]] [--path[="..."]] [--table[="..."]] name

Arguments:
 name                  The name of the migration

Options:
 --bench               The workbench the migration belongs to.
 --create              The table needs to be created.
 --package             The package the migration belongs to.
 --path                Where to store the migration.
 --table               The table to migrate.
 --help (-h)           Display this help message.
 --quiet (-q)          Do not output any message.
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version.
 --ansi                Force ANSI output.
 --no-ansi             Disable ANSI output.
 --no-interaction (-n) Do not ask any interactive question.
 --env                 The environment the command should run under.

参数通常至少需要提供一个,否则该命令将引发错误。在这种情况下,您需要提供迁移名称。

选项显然是可选的,您可以使用它来修改命令的行为。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接