Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Make command available exlusively to interactive mode #71

Open
byt3bl33d3r opened this issue Sep 12, 2020 · 5 comments
Open

Make command available exlusively to interactive mode #71

byt3bl33d3r opened this issue Sep 12, 2020 · 5 comments

Comments

@byt3bl33d3r
Copy link

Hello!

I was wondering if there was a way of specifying a command to only be available in interactive mode? It seems like I might be able to do this by pulling some hackery in the Context.on_cli() method but I was wondering if there's a better way?

Cheers

@byt3bl33d3r byt3bl33d3r changed the title Commands available exlusively to interactive mode Make command available exlusively to interactive mode Sep 12, 2020
@AndreasBackx
Copy link
Contributor

AndreasBackx commented Sep 12, 2020

You should be able to do this when implementing the Command class itself, but it's in the internal API. What @command decorators do is they add information to the function which is picked up on startup and then converted into an AutoCommand (a subclass of Command). So if you would like to implement this, I would add parameters to the @command decorator that defines whether cli/interactive is allowed. Then these would be passed on AutoCommand and in the respective methods it can then be disabled. Maybe some other stuff needs to be done to see it's not picked up, but that's what I have in mind.

def command(
    name_or_function=None, help=None, aliases=None, exclusive_arguments=None,
+   cli=True, interactive=True,
):

Which would allow for disabling it for either like so:

@command(cli=False)
def my_command():
	pass

@byt3bl33d3r
Copy link
Author

byt3bl33d3r commented Sep 13, 2020

Thanks for that, is this something you think you'd be interested in merging if I submitted a PR? I feel like it would be useful for a lot of situations.

@AhmedSoliman
Copy link
Contributor

Thanks @AndreasBackx for sharing the context. @byt3bl33d3r yeah, we don't mind having this, I think it's a great feature if implemented reliably.

@AhmedSoliman
Copy link
Contributor

@byt3bl33d3r have got a chance to work on this?

@ddutt
Copy link

ddutt commented Dec 16, 2021

This would be very useful to have if you can in addition then support dynamic command completions for those commands that are interactive only. From what I remember, to help bash, the current model of completions only supports statically defined lists.

If this can be enabled as well, then I can look at adding support as well, and would appreciate info on how to add dynamic completion then.

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

No branches or pull requests

4 participants