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

Command.args() has no command line visibility #17

Open
unicornsasfuel opened this issue May 27, 2016 · 2 comments
Open

Command.args() has no command line visibility #17

unicornsasfuel opened this issue May 27, 2016 · 2 comments

Comments

@unicornsasfuel
Copy link

It would be useful to have visibility into the command line being completed in Command.args().

For instance, if you wanted to do bash-style path completion, you could simply:

from ishell.console import Console
from ishell.command import Command
import glob

class ExampleCommand(Command):
   def args(self, line):
      line_without_command_name = ''.join(line.split()[1:])
      return glob.glob(line_without_command_name + '*')
   def run(self, line):
      print "This is an example command."

example = ExampleCommand('example', dynamic_args=True)
console = Console()
console.addChild(example)
@italorossi
Copy link
Owner

You can get the current readline buffer with readline.get_line_buffer(), it'll probably return the line you want.

The only problem in adding the line there is breaking the api since the Command will call args function with an additional argument. We can do this but probably version it with a new major version like 1.0.0 and put a warning in 0.1.5 if we detect only one arg.

@unicornsasfuel
Copy link
Author

Thank you for the workaround! Yes, readline.get_line_buffer() appears to provide the right line.

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

No branches or pull requests

2 participants