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

AttributeError: 'Command' object has no attribute 'commands' #40

Closed
zerans opened this issue May 9, 2018 · 7 comments
Closed

AttributeError: 'Command' object has no attribute 'commands' #40

zerans opened this issue May 9, 2018 · 7 comments

Comments

@zerans
Copy link

zerans commented May 9, 2018

In a function called from a setup tools entry point:

@click.command()
def main():
    repl(click.get_current_context(), prompt_kwargs={'history': FileHistory(HISTFILE)})

I get this error:

  File "/Users/lol/Library/Python/2.7/lib/python/site-packages/click_repl/__init__.py", line 169, in repl
    available_commands = group_ctx.command.commands
AttributeError: 'Command' object has no attribute 'commands'

If I do this:

@click.command()
@click.pass_context
def main(ctx):
    ctx.command.commands = []
    repl(ctx, prompt_kwargs={'history': FileHistory(HISTFILE)})

I get a different error, because pop is called incorrectly.

Commenting out lines 171-180 fixes the error. available_commands isn't used anywhere else, so this seems to be dead code?

    if isinstance(group_ctx.command, click.CommandCollection):
        available_commands = {
            cmd_name: cmd_obj
            for source in group_ctx.command.sources
            for cmd_name, cmd_obj in source.commands.items()
        }
    else:
        available_commands = group_ctx.command.commands
    available_commands.pop(repl_command_name, None)
@untitaker
Copy link
Collaborator

click-repl only works if you have a command Group: What is the point of using it if there are no commands to execute on the shell?

@zerans
Copy link
Author

zerans commented May 9, 2018 via email

@untitaker
Copy link
Collaborator

untitaker commented May 9, 2018

That is not what I am talking about. I mean that if you have only one command, what would the repl allow you to do?

For my usecase I have a command like this:

my_program # launches repl
my_program foo # a subcommand

You on the other hand seem to have no subcommands, because you have no group. What exactly would the user type in the REPL?

@zerans
Copy link
Author

zerans commented May 9, 2018

There were other commands not included in the example, sorry. I think I'm misunderstanding how to achieve the goal of having the program drop straight into the REPL without requiring a repl arg. A group with invoke_without_command?

@untitaker
Copy link
Collaborator

yes, invoke_without_command, and in the group body:

if not click_ctx.invoked_subcommand: repl(...)

@zerans
Copy link
Author

zerans commented May 9, 2018 via email

@untitaker
Copy link
Collaborator

yw

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

No branches or pull requests

2 participants