Positional
位置信息主要与命令目标方法相关:
Positional information is mostly related to a command target method:
Unresolved include directive in modules/ROOT/pages/options/positional.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]
小心使用位置参数,因为它可能很快就会令人困惑,不知道哪些选项映射到这些参数。 |
Be careful with positional parameters as it may soon become confusing which options those are mapped to. |
通常当在命令行中定义选项(无论是长选项还是短选项)时,参数会映射到一个选项。一般来说,有 options、option arguments 和 arguments,其中后者没有映射到任何特定选项。
Usually arguments are mapped to an option when those are defined in a command line whether it’s a long or short option. Generally speaking there are options, option arguments and arguments where latter are the ones which are not mapped to any spesific option.
无法识别的参数可能有次要映射逻辑,其中位置信息很重要。通过选项位置,您实际上是在告诉命令解析如何解释纯原始的模棱两可参数。
Unrecognised arguments can then have a secondary mapping logic where positional information is important. With option position you’re essentially telling command parsing how to interpret plain raw ambiguous arguments.
我们看看当我们不定义位置时会发生什么。
Let’s look what happens when we don’t define a position.
Unresolved include directive in modules/ROOT/pages/options/positional.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]
选项 arg1 是必需的,并且没有有关如何处理参数 one
的信息,导致缺少选项的错误。
Option arg1 is required and there is no info what to do with argument
one
resulting error for missing option.
shell:>arity-strings-1 one
Missing mandatory option --arg1.
现在我们定义一个位置 0
。
Now let’s define a position 0
.
Unresolved include directive in modules/ROOT/pages/options/positional.adoc - include::../../../../src/test/java/org/springframework/shell/docs/OptionSnippets.java[]
参数将被处理,直到我们获得多达 2 个参数。
Arguments are processed until we get up to 2 arguments.
shell:>arity-strings-2 one
Hello [one]
shell:>arity-strings-2 one two
Hello [one, two]
shell:>arity-strings-2 one two three
Hello [one, two]