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

_parse stays zero when parsing subcommands from INI #345

Closed
aparaschos opened this issue Nov 22, 2019 · 2 comments · Fixed by #362
Closed

_parse stays zero when parsing subcommands from INI #345

aparaschos opened this issue Nov 22, 2019 · 2 comments · Fixed by #362
Labels

Comments

@aparaschos
Copy link

I use an INI file to configure my app and cmd line arguments to overwrite some of it's properties.

Trying to figure out which options are set from the INI, by not passing any arguments from the cmd line, I realized that app.got_subcommnad(sApp) is always false.

Additionally, the ->required() flag that I set to some of the sub-commnads options is ignored at the INI level.

I temporarily fixed the issue by extending _parse_single_config to call ->increment_parsed() for the sub-commands, i.e.,

    /// Fill in a single config option
    bool _parse_single_config(const ConfigItem &item, size_t level = 0) {
        if(level < item.parents.size()) {
            try {
                auto subcom = get_subcommand(item.parents.at(level));

               //TODO tmp fix
                subcom->increment_parsed();


                return subcom->_parse_single_config(item, level + 1);
            } catch(const OptionNotFound &) {
                return false;
            }
        }

and appears to resolve my issues. I don't really have an overview of the arch to figure out whether there are side effects by doing so. Any suggestions?

@phlptp
Copy link
Collaborator

phlptp commented Nov 23, 2019

That seems like a bug, though also seems like from some of the other issues, some work needs to be done with the config to make the processing behave more like handling of command line arguments. Which would resolve this and a few other issues, and likely some others that haven't been expressed yet.

I haven't verified but you might also be able to use the count_all function to get a number of the arguments called within a subcommand, I think that should be non-zero even in the config file.

@phlptp phlptp added the bug label Nov 23, 2019
@phlptp phlptp mentioned this issue Dec 6, 2019
13 tasks
@phlptp
Copy link
Collaborator

phlptp commented Dec 23, 2019

Update to this issue.
Digging into it the way it was designed by default the configuration file was intended to only update defaults. The command line overrides any arguments. The same is true for subcommands, so it was not intended to trigger subcommands so by default it would update the values but not increment the count on the subcommand so for that purpose the current behavior of not incrementing the count makes a lot of sense.

That being said there are cases where you want the subcommand to be triggered from a file. So what I am doing in #362 is adding a configurable flag (like exists on options) that is off by default but if that is set then subcommands can be triggered via config file even if they were not present in the actual command line. Which should create the expected behavior in this issue, once completed and tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants