anki-code / xonsh-awesome-cli-app

Example of awesome CLI app template for xonsh.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  • Based on power and sugar from click.
  • 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 included.
  • The way to write tests included.

Install

pip install git+https://github.com/anki-code/xonsh-awesome-cli-app
mycli

or

git clone https://github.com/anki-code/xonsh-awesome-cli-app
cd xonsh-awesome-cli-app
./mycli

Usage

You can use this app as a template to your own apps.

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: hello

mycli say hello --wait
# Wait...
# Username say: hello

mycli --name Mike say hello --wait
# Wait...
# Mike say: hello

$MYCLI_NAME = 'Alex'
mycli say hello
# Alex say: hello

mycli context
# Environment:
# {'MYCLI_NAME': 'Alex'}
# Context:
# {'debug': False, 'log': <RootLogger root (INFO)>, '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

Tests

You can use pytest for test cli:

pytest tests/
# tests/test_app.xsh passed

See more CLI libs

See also

About

Example of awesome CLI app template for xonsh.

License:MIT License


Languages

Language:Python 100.0%