Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anki-code/xonsh-awesome-cli-app
Example of awesome CLI app template for xonsh.
https://github.com/anki-code/xonsh-awesome-cli-app
List: xonsh-awesome-cli-app
awesome awesome-tools cli-app console python-cli python-click terminal-app xonsh xonsh-dev xontrib
Last synced: 2 months ago
JSON representation
Example of awesome CLI app template for xonsh.
- Host: GitHub
- URL: https://github.com/anki-code/xonsh-awesome-cli-app
- Owner: anki-code
- License: mit
- Created: 2024-02-28T14:22:00.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-28T09:37:24.000Z (9 months ago)
- Last Synced: 2024-05-23T07:02:02.164Z (7 months ago)
- Topics: awesome, awesome-tools, cli-app, console, python-cli, python-click, terminal-app, xonsh, xonsh-dev, xontrib
- Language: Python
- Homepage:
- Size: 69.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-xontribs - xonsh-awesome-cli-app - Example of awesome cli app template for xonsh. (Education materials)
README
Example of awesome CLI app template for xonsh. Just fork it and add your commands.
If you like the idea of bar theme click ⭐ on the repo and tweet.## Features
* CLI: based on power and sugar from [click](https://click.palletsprojects.com).
* Execution: pip-installable as well as clone-and-run.
* Ability to grow your library.
* Ability to set up context and environment.
* Ability to set up context options and command arguments.
* Ability to use environment variables as replacement of options and arguments.
* Logging
* Tests: local, docker.## Install
```xsh
pip install git+https://github.com/anki-code/xonsh-awesome-cli-app
mycli
```
or
```xsh
git clone https://github.com/anki-code/xonsh-awesome-cli-app
cd xonsh-awesome-cli-app
./mycli
```
## UsageYou can use this app as a template to your own apps.
```xsh
mycli
# Usage: mycli [OPTIONS] COMMAND [ARGS]...
#
# CLI management.
#
# Options:
# --name TEXT Context option: name.
# --debug Context option: debug mode.
# --help Show this message and exit.
#
# Commands:
# say Say.
# context Show app context.mycli hello --help
# Usage: mycli hello [OPTIONS]
#
# Say hello.
#
# Options:
# --wait Command argument: wait before print.
# --help Show this message and exit.mycli say hello
# Username say: hellomycli say hello --wait
# Wait...
# Username say: hellomycli --name Mike say hello --wait
# Wait...
# Mike say: hello$MYCLI_NAME = 'Alex'
mycli say hello
# Alex say: hellomycli context
# Environment:
# {'MYCLI_NAME': 'Alex'}
# Context:
# {'debug': False, 'log': , 'name': 'Alex'}mycli --debug say hello
# TRACE SUBPROC: (['echo', 'Username', 'say:', 'hello'],), captured=hiddenobject
# Username say: hello
# 2024-03-01 18:21:24,723 - root - INFO - Additional log message.
# TRACE SUBPROC: (['echo', 'Here', 'is', 'debug', 'message', 'too', ''],), captured=hiddenobject
# Here is debug message too
```### How to create subcommands
If you need subcommands (subgroups) e.g.:
```xsh
mycli env activate --name myname
mycli env deactivate
mycli info --full
```use this example:
```python
import click@click.group() # Create main group in `click`
def cli():
pass@cli.group() # Create subgroup `env` in `cli`
def env():
pass@env.command() # Create subcommand `activate` in `env`
@click.option('--name')
def activate(name):
click.echo(f"Activating environment: {name}")
```## Tests
You can use `pytest` for test cli:
```xsh
pytest tests/
# tests/test_app.xsh passed
```## Known issues
### pytest: xonsh not found
In some sort situations you need to use current env python to run tests:
```xsh
@(sys.executable) -m pytest -v
``````xsh
import sys
py = sys.executable
def test_help():
@(py) -m xonsh ./mycli --help
```## See more CLI libs
* [click](https://click.palletsprojects.com/), [Shared options and flags between commands](https://stackoverflow.com/questions/40182157/shared-options-and-flags-between-commands)
* [rich](https://github.com/Textualize/rich)
* [typer](https://typer.tiangolo.com/)## See also
* [xonsh-cheatsheet](https://github.com/anki-code/xonsh-cheatsheet) - Cheat sheet for xonsh shell with copy-pastable examples.
* [rc-awesome](https://github.com/anki-code/xontrib-rc-awesome) - Awesome snippets of code for xonshrc in xonsh shell.
* [macro](https://github.com/anki-code/xontrib-macro) - Library of the useful macro for the xonsh shell.
* [docker-xonsh-wrapper](https://github.com/anki-code/docker-xonsh-wrapper) - Wrap an app in docker container and catch the signals from docker using xonsh shell.
* [xunter](https://github.com/anki-code/xunter) - Profiling the xonsh shell code using [hunter](https://github.com/ionelmc/python-hunter).
* [Xxh Development Environment (xde)](https://github.com/xxh/xxh/tree/7222c47482a8e46cbdf1eb23589f40962425a4a0/xde)