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

Use arrays for ordered items #24

Closed
epage opened this issue Jan 26, 2022 · 4 comments · Fixed by #32
Closed

Use arrays for ordered items #24

epage opened this issue Jan 26, 2022 · 4 comments · Fixed by #32

Comments

@epage
Copy link

epage commented Jan 26, 2022

Currently subcommands and args are objects in the data model. A lot of serialization sources consider the objects to have an undefined order but order of these is important. Rather than relying on implementation details of the serializers (and tools mucking with the raw data), I'd recommend switching these to arrays like in the old clap YAML support

name: myapp
version: "1.0"
author: Kevin K. <kbknapp@gmail.com>
about: Does awesome things
args:
    - config:
        short: c
        long: config
        value_name: FILE
        help: Sets a custom config file
        takes_value: true
    - INPUT:
        help: Sets the input file to use
        required: true
        index: 1
    - verbose:
        short: v
        multiple: true
        help: Sets the level of verbosity
subcommands:
    - test:
        about: controls testing features
        version: "1.3"
        author: Someone E. <someone_else@other.com>
        args:
            - debug:
                short: d
                help: print debug information
@epage
Copy link
Author

epage commented Jan 26, 2022

Interesting, it looks like your YAML syntax already does this which is different than toml/json.

@aobatact
Copy link
Owner

aobatact commented Jan 31, 2022

Sorry for delay.
Is this means that deserializer should treat Args (or subcommand) as Vec<(Sting, Arg)> not HashMap<String,Arg>?

Edit:
Oh this is about serializer.
Is this that the order should be specified when serializing arg and subcommand?

@epage
Copy link
Author

epage commented Jan 31, 2022

This is about deserialization. At a glance, I'm not seeing any HashMaps but effectively the data model should be Vec<(String, Arg)>. Ordering of args and subcommands can be significant and we should respect that ordering and make it clear that we do. Some source crates will preserve ordering but that is an implementation detail, usually the underlying formats (like json) are defined as unordered.

@aobatact
Copy link
Owner

Sorry for delay.
Fixed in #32.

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

Successfully merging a pull request may close this issue.

2 participants