Arg::num_args
num_args
Section titled “num_args ”Specifies the number of arguments parsed per occurrence.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”name = "prog"[args]mode = { long = "mode", default-missing-value = "slow", default-value = "plaid", num-args = "optional" }
name: progargs: mode: long: mode default-missing-value: slow default-value: plaid num-args: optional
{ "name": "prog", "args": { "mode": { "long": "mode", "default-missing-value": "slow", "default-value": "plaid", "num-args": "optional" } }}
prog --mode fast
Output
Section titled “Output”claptrap_mode='fast'
Example 2
Section titled “Example 2”name = "prog"[args]mode = { long = "mode", default-missing-value = "slow", default-value = "plaid", num-args = "optional" }
name: progargs: mode: long: mode default-missing-value: slow default-value: plaid num-args: optional
{ "name": "prog", "args": { "mode": { "long": "mode", "default-missing-value": "slow", "default-value": "plaid", "num-args": "optional" } }}
prog --mode
Output
Section titled “Output”claptrap_mode='slow'
Example 3
Section titled “Example 3”name = "prog"[args]mode = { long = "mode", default-missing-value = "slow", default-value = "plaid", num-args = "optional" }
name: progargs: mode: long: mode default-missing-value: slow default-value: plaid num-args: optional
{ "name": "prog", "args": { "mode": { "long": "mode", "default-missing-value": "slow", "default-value": "plaid", "num-args": "optional" } }}
prog
Output
Section titled “Output”claptrap_mode='plaid'
Example 4
Section titled “Example 4”name = "prog"[args]file = { short = 'F', num-args = "..", action = "set" }word = {}
name: progargs: file: short: F num-args: .. action: set word: {}
{ "name": "prog", "args": { "file": { "short": "F", "num-args": "..", "action": "set" }, "word": {} }}
prog -F file1 file2 file3 word
Output
Section titled “Output”claptrap_file=('file1' 'file2' 'file3' 'word')
Example 5
Section titled “Example 5”name = "prog"[args]file = { short = 'F', num-args = "..", action = "set" }word = {}
name: progargs: file: short: F num-args: .. action: set word: {}
{ "name": "prog", "args": { "file": { "short": "F", "num-args": "..", "action": "set" }, "word": {} }}
prog word -F file1 file2 file3
Output
Section titled “Output”claptrap_word='word'claptrap_file=('file1' 'file2' 'file3')
Example 6
Section titled “Example 6”name = "prog"[args]file = { short = 'F', action = "append" }word = {}
name: progargs: file: short: F action: append word: {}
{ "name": "prog", "args": { "file": { "short": "F", "action": "append" }, "word": {} }}
prog -F file1 -F file2 -F file3 word
Output
Section titled “Output”claptrap_file=('file1' 'file2' 'file3')claptrap_word='word'
Example 7
Section titled “Example 7”name = "prog"[args]file = { short = 'F', num-args = 2, action = "set" }
name: progargs: file: short: F num-args: 2 action: set
{ "name": "prog", "args": { "file": { "short": "F", "num-args": 2, "action": "set" } }}
prog -F in-file out-file
Output
Section titled “Output”claptrap_file=('in-file' 'out-file')
Example 8
Section titled “Example 8”name = "prog"[args]file = { short = 'F', num-args = 2, action = "set" }
name: progargs: file: short: F num-args: 2 action: set
{ "name": "prog", "args": { "file": { "short": "F", "num-args": 2, "action": "set" } }}
prog -F file1
Output
Section titled “Output”error: 2 values required for '-F <file> <file>' but 1 was provided
Usage: prog [OPTIONS]
For more information, try '--help'.
Example 9
Section titled “Example 9”name = "prog"[args]mode = { long = "mode", num-args = 1 }
name: progargs: mode: long: mode num-args: 1
{ "name": "prog", "args": { "mode": { "long": "mode", "num-args": 1 } }}
prog --mode fast
Output
Section titled “Output”claptrap_mode='fast'