13 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d27cc09d9 | |||
| 1b2ebab33a | |||
| 7cfe2c4775 | |||
| ce1b8b6744 | |||
| df40af9fc3 | |||
| 95a384bfff | |||
| 6df4c86fc5 | |||
| 7fcb031795 | |||
| c8036ad216 | |||
| 7eb15f2477 | |||
| 53ba9e6fbe | |||
| f175f9d5c9 | |||
| 0be02c7154 |
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
| 3d27cc09d9 |
lib.App.run_sub_commands(): Instantiate as context manager
App currently has no hook to close async resources. Call it as context manager, so that __aexit__() gets invoked if run_sub_commands() exits. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 1b2ebab33a |
lib.App.__run(): Beautify error logging
Without --backtrace, the outmost try-catch block logs exceptions plainly as their text. If it catches a key error, the exception text only consists of the key itself, which can be easily mistaken for a normal program output, so prefix it with a "Failed:". Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 7cfe2c4775 |
lib.App._run(): default_completer=NoopCompleter()
By default, argcomplete uses argcomplete.FilesCompleter as default for every argument. This mixes accessible files into the list of possible completions. For most of jw-pkg's commands, that's unwanted, so turn it off by defining a NoopCompleter class which does nothing, and by set every arguments's default completer to a NoopCompleter instance. If desired, completing files can be restored for an argument by parser.add_argument("some-arg").completer = FilesCompleter() Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| ce1b8b6744 |
lib.App: Fully parse argparse tree if _ARGCOMPLETE
Every module derived from lib.Cmd implements its own parser.add_argument() logic. As a consequence, all Cmd derived modules need to be loaded to have the full argument tree available. This is avoided during normal program startup because it takes some time. It's not necessary during normal program execution, nor for showing help messages. It is, however, needed for argcomplete to do its thing, so fully parse the command line if the program runs in argcomplete mode, as determined by checking if _ARGCOMPLETE is present in the environment. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| df40af9fc3 |
lib.App.call_async(): Add method
Use the AsyncRunner class introduced in the previous commit to add a call_async() method, allowing to run async functions from sync functions by spawning an extra event loop. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 95a384bfff |
lib.App.eloop: Add property
Expose App's __eloop member containing the application's main event loop to allow outside async event loop trickery. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 6df4c86fc5 |
lib.App: Add property cmdline
Add the property App.cmdline, containing the invoking command line as a string. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 7fcb031795 |
jw.pkg.lib.App.__run(): Use return value as exit status
If a Cmd-classes's _run() method returns an integer between 0 and 255, use that as the program's exit status. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| c8036ad216 |
jw-pkg.sh: Print help for missing subcommands
Print a help message if no subcommand is specified for one of the comamnds "distro" and "projects". Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 7eb15f2477 |
jw.pkg.lib: Don't log {e}
Don't log an Exception as {e} but as str(e) producing nicer output. Or as repr(e) if a backtrace is requested, because to people who can read backtraces, type info might be of interest. Also, remove pointless time stamps, those belong into the logging framework. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 53ba9e6fbe |
lib.App: Stay functional without autocomplete
If Python's autocomplete is not installed, jw-pkg.py fails to run commands. Fix that in order stay compatible with minimal excecution environments. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| f175f9d5c9 |
lib.Cmd: Add argument "parent" to __init__()
During __init__(), commands have no idea of their parent. This is not a problem as of now, but is easy to fix, and it's architecturally desirable to be prepared just in case, so add the parent argument to the ctor before more commands are added. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 0be02c7154 |
lib.App, .Cmd: Add modules
Add App and Cmd as generic base classes for multi-command applications. The code is taken from jw-python: The exising jw.pkg.App is very similar to the more capable jwutils.Cmds class, so, to avoid code duplication, add it here to allow for jwutils.Cmds and jw.pkg.App to derive from it at some point in the future. Both had to be slightly modified to work within jw-pkg's less equipped context, and will need futher code cleanup. Signed-off-by: Jan Lindemann <jan@janware.com> |