You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doc: Examples of creating single command applications #66
The docs only have examples for creating multi command applications but there are no examples for creating single command applications. Is there support for this usecase?
The docs does have an example on how to make a single command application, but as far as I can tell it doesn't work.
I tried running the following script:
#!/usr/bin/env pythonfromcleoimportApplicationfromcleoimportCommandclassGreetCommand(Command):
""" Greets someone greet {name? : Who do you want to greet?} {--y|yell : If set, the task will yell in uppercase letters} """defhandle(self):
name=self.argument('name')
ifname:
text='Hello {}'.format(name)
else:
text='Hello'ifself.option('yell'):
text=text.upper()
self.line(text)
command=GreetCommand()
app=Application()
app.add(command.default())
# this now executes the 'GreetCommand' without passing its nameapp.run()
But when I try to run the script without arguments, python cmd.py, it produces the following output:
Console Tool
USAGE
console [-h] [-q] [-v [<...>]] [-V] [--ansi] [--no-ansi] [-n] <command> [<arg1>] ... [<argN>]
ARGUMENTS
<command> The command to execute
<arg> The arguments of the command
GLOBAL OPTIONS
-h (--help) Display this help message
-q (--quiet) Do not output any message
-v (--verbose) Increase the verbosity of messages: "-v" for normal output, "-vv" for more
verbose output and "-vvv" for debug
-V (--version) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n (--no-interaction) Do not ask any interactive question
AVAILABLE COMMANDS
completions Generate completion scripts for your shell.
greet Greets someone
help Display the manual of a command
Trying to run python cmd.py John produces
[CannotResolveCommandException]
The command "John" is not defined.
So either I'm missing something on how to enable the default command, or something is wrong.
I'm running version 0.7.2, installed from PyPi, on Ubuntu 16.04, with python 3.7.2.
Reacted by Titusz, Gwenn Le Bihan and Jace Browning
Activity
sindrehan commentedon Feb 22, 2019
The docs does have an example on how to make a single command application, but as far as I can tell it doesn't work.
I tried running the following script:
But when I try to run the script without arguments,
python cmd.py, it produces the following output:Trying to run
python cmd.py JohnproducesSo either I'm missing something on how to enable the default command, or something is wrong.
I'm running version 0.7.2, installed from PyPi, on Ubuntu 16.04, with python 3.7.2.
m9810223 commentedon Dec 3, 2021
Anothor simple hacked solution:
https://github.com/m9810223/advent-of-code-python/blob/3eb52dd7b168b52064149defc4b2d59e30e05fae/aoc_run.py#L85-L93