pyvec / elsa

Helper module for hosting Frozen-Flask based websites on GitHub pages
Other
28 stars 49 forks source link

A way of reusing the elsa cli #45

Closed mikicz closed 6 years ago

mikicz commented 6 years ago

I want to add a command to naucse, however, elsa invokes the cli right away and I couldn't way a way to "subclass" the cli other than this one.

The following is an example from naucse, when this function is called, all three commands from elsa and the new_command are available from command line.

import elsa
import click

def cli(app, *, base_url=None, freezer=None):
    elsa_group = elsa.cli(app, base_url=base_url, freezer=freezer, invoke_cli=False)

    @click.group()
    def naucse():
        pass

    @naucse.command()
    def new_command():
        """ Some new command. """

    cli = click.CommandCollection(sources=[naucse, elsa_group])

    return cli()
hroncok commented 6 years ago

This is hack-ish, I don't like the API. But having a different API would be backwards incompatible :( In reality, we should do #39 properly instead. However #39 is stalled for more than a half of year, so I'm probably OK with this. Please add a test tough and update the docstring, which currently lies a bit I guess (I mean before this PR anyway).

mikicz commented 6 years ago

I updated the docstring and added a test, that tests adding a custom command if invoke_cli is set to False. Is it enough? I'm not sure how to test it more thoroughly...

I get that this isn't the ideal solution, however, I took a look at #39 and the problem is still there, the Elsa.cli method invokes the cli and doesn't enable to "subclass" the cli anyway.

hroncok commented 6 years ago

Thanks.