Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libelektra-opts optional parameter args #4952

Open
kodebach opened this issue May 27, 2023 · 0 comments
Open

libelektra-opts optional parameter args #4952

kodebach opened this issue May 27, 2023 · 0 comments

Comments

@kodebach
Copy link
Member

kodebach commented May 27, 2023

Noticed by @hannes99 in #4949

libelektra-opts does support parameter arguments. A "parameter argument" is a CLI arguments that is neither an option, an option argument nor a subcommand, e.g. in kdb --color never get user:/foo only user:/foo is a parameter argument.

[from]
args = indexed
args/index = 0

[to]
args = indexed
args/index = 1

[more/#]
args = remaining

For example, the spec above will load the first parameter argument into from, the second into to and the rest into more/#0, more/#1 etc. However, by using args/index = N we also introduce the restriction that there must be at least N parameter arguments. This not always what we want.

Proposal

libelektra-opts should also accept fewer than N parameter arguments, even if args/index = N is specified. The additional args = indexed keys should be left unset.

However, producing the old behaviour should still be possible. I have two ideas for achieving this.
The second one is a bit simpler IMO, but introduces new syntax, while the first one reuses the existing require metakey.

Version 1

  1. It should still be required that: If args/index = N is used, args/index = M for all 0 <= M < N must also be part of the specification.
  2. If the metakey require is set on a specification key with args = indexed, there must be parameter argument to assign to this key.
  3. Following from the above, when require is set on a key with args/index = N the old behaviour is restored up to N, i.e. there must be at least N parameter arguments. To make this more obvious, libelektra-opts should enforce that: If args/index = N is used on a key with require, the metakey require must also be set on all keys with args/index = M with 0 <= M < N.

Version 2

  1. On the same keys which may already use the command metakey, a new args/min = N metakey can be used. If set, this sub-command requires at least N parameter arguments.
  2. If args/min = N is not used, all parameter arguments are optional.

Personally, I prefer the second option, because it is much easier to use and probably also easier to implement (just read the metakey if it exists and check the against the number of unused args).

@kodebach kodebach mentioned this issue May 27, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant