【问题标题】:What's the difference between Arguments and Options?参数和选项有什么区别?
【发布时间】:2013-07-24 03:03:05
【问题描述】:

我不确定这个术语存在于哪个级别,但在 php-framework 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),
        );
    }

两者有什么区别?

【问题讨论】:

  • 大声笑我刚刚读了我自己的老问题,例如“论点和意见之间有什么区别”。确实很哲学。

标签: php shell command-line command laravel


【解决方案1】:

看看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.

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

显然,Option 是可选的,用于修改命令行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-14
    • 2020-05-25
    • 1970-01-01
    • 2014-10-06
    • 2013-01-08
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多