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

CLI routing not working with extend_api() #744

Closed
akaihola opened this issue Mar 18, 2019 · 3 comments
Closed

CLI routing not working with extend_api() #744

akaihola opened this issue Mar 18, 2019 · 3 comments

Comments

@akaihola
Copy link
Contributor

As Eduardo Marinho reported on Stack Overflow:

I'm trying to use @hug.extend_api() for CLI routes but it's not working.

Calling hug -f run.py -c something, the command list is empty. The same code works fine for HTTP routing.

This is my main script (run.py):

import hug
from apitest import api


@hug.extend_api()
def apis():
   return [api]

This is apitest/api.py:

import hug


@hug.cli()  # cli route doesn't work
@hug.get('/')  # get route works fine
def root():
   return 'hello'

(ping @dudez20 in case you're the same guy here on GitHub)

akaihola pushed a commit to akaihola/hug that referenced this issue Mar 18, 2019
@akaihola
Copy link
Contributor Author

akaihola commented Mar 18, 2019

Strangely, the test in #745 doesn't fail even though doing the same with the following main program fails to include the new command in the API:

tests/module_cli_main.py:

import hug
import module_fake_http_and_cli


API = hug.API(__name__)


@hug.extend_api('/api', API)
def extend_with():
    return [module_fake_http_and_cli]


if __name__ == '__main__':
    API.cli()
$ python tests/module_cli_main.py
__main__

Available Commands:

	- 
$ python tests/module_cli_main.py made_up_go
__main__

Available Commands:

	- 

@akaihola
Copy link
Contributor Author

This is the (clumsy) work-around I'm using currently:

import hug
from module_fake_http_and_cli import made_up_go
from another_module import another_command


COMMANDS = [made_up_go, another_command]


API = hug.API(__name__)


commands = API.cli.commands
for command in COMMANDS:
    commands.update(command.interface.api._cli.commands)


@hug.extend_api('/api', API)
def extend_with():
    return {command.__module__ for command in COMMANDS}


if __name__ == '__main__':
    API.cli()

timothycrosley added a commit that referenced this issue Mar 19, 2019
Add unit test for `extend_api()` with CLI commands (#744)
@timothycrosley
Copy link
Collaborator

Should be resolved by: https://github.com/timothycrosley/hug/pull/747/files which is slated for the next release.

Thanks!

~Timothy

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