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

Ability to hide extra args from web ui #1881

Merged
merged 13 commits into from
Sep 12, 2021

Conversation

fabito
Copy link
Contributor

@fabito fabito commented Sep 12, 2021

Resolves #1876

@cyberw
Copy link
Collaborator

cyberw commented Sep 12, 2021

After looking at your code more closely, I think it would be preferable to store the flag on the action itself (instead of in a separate list)

Is that possible?

@fabito
Copy link
Contributor Author

fabito commented Sep 12, 2021

We probably can.
Regardless where we decide to store it (indeed in the Action seems a better option), I think we will still need access to the parser instance I don't know how to propagate action metadata to the parsed_options.|

@fabito fabito marked this pull request as ready for review September 12, 2021 07:53
@cyberw
Copy link
Collaborator

cyberw commented Sep 12, 2021

One question: is it be possible to hide/unhide an argument after the fact?

And maybe we should invert the parameter? (change it to include_in_web_ui, default to True). What do you think?

@fabito
Copy link
Contributor Author

fabito commented Sep 12, 2021

Yeah, we can invert the flag, no problem.
What do you mean by "after the fact" ? Can you give me an example ?

@cyberw
Copy link
Collaborator

cyberw commented Sep 12, 2021

What do you mean by "after the fact" ? Can you give me an example ?

Lets say a library, like locust-plugins, or some shared file that you import in all your locust files adds a parameter that is hidden (or visible) in the web UI, and you want to show it (or hide it).

e.g (in your library)

parser.add_argument("--my-ui-invisible-argument", include_in_web_ui=False, default="I am invisible")

and then in your specific locustfile, it would be nice to be able to override that, by doing something like this:

parser.my_ui_invisible_argument.include_in_web_ui = True

@fabito
Copy link
Contributor Author

fabito commented Sep 12, 2021

I am not an ArgumentParser expert but AFAIK it does not expose an API for changing or removing arguments.
Since include_in_web_ui does not affect the parsing logic we could add a function that locates the action ( _actions attribute ) and change the flag's value.

Maybe something like this ??

def include_in_web_ui(self, arg):
    for action in self._actions:
        if (vars(action)['option_strings']
            and vars(action)['option_strings'][0] == arg) \
                or vars(action)['dest'] == arg:
            action.include_in_web_ui = True
            return

    for action in self._action_groups:
        vars_action = vars(action)
        var_group_actions = vars_action['_group_actions']
        for x in var_group_actions:
            if x.dest == arg:
                x.include_in_web_ui = True
                return

@cyberw
Copy link
Collaborator

cyberw commented Sep 12, 2021

That looks complicated, so lets not bother. it is an acceptable limitation not to be able to modify it. Thanks for the PR!

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 this pull request may close these issues.

Ability to explicitly set which arguments will be exposed/visible in the web ui
2 participants