Display your Python argparse parser as a TUI.
Project description
argparse-tui
Display your Python argparse parser as a TUI.
Links | |
---|---|
Code Repo | https://www.github.com/fresh2dev/argparse-tui |
Mirror Repo | https://www.f2dv.com/r/argparse-tui |
Documentation | https://www.f2dv.com/r/argparse-tui |
Changelog | https://www.f2dv.com/r/argparse-tui/changelog |
License | https://www.f2dv.com/r/argparse-tui/license |
Funding | https://www.f2dv.com/fund |
Overview
This is a fork of the Textualize Trogon TUI library that introduces these features:
- add support for Python's argparse parsers
- add
--tui
flag as an argument - or, add
tui
command to your subparser - or, invoke the TUI with
invoke_tui(parser)
- add
- remove support for Click
- add ability for TUI parameter to filter subcommands
- support for manually constructing schemas
- support for argparse
- add examples for yapx, myke, and sys.argv
- support ommission of hidden parameters and subcommands from the TUI
- support the redaction of sensitive "secret" values
- support for showing required prompts as read-only
- ability to join list arguments values like this:
-x 1 -x 2 -x 3
(default), or like this:-x 1 2 3
- vim-friendly keybindings
Install
Install from PyPI:
pip install argparse-tui
Use
import arparse
from argparse_tui import add_tui_argument, add_tui_command
parser = argparse.ArgumentParser()
# Add tui argument (my-cli --tui)
add_tui_argument(parser, option_strings=["--tui"], help="Open Textual UI")
# Or, add tui command (my-cli tui)
add_tui_command(parser, command="tui", help="Open Textual UI")
parser.print_help()
invoke_tui
argparse-tui offers this function to display a TUI based on the arguments of the given parser:
import argparse
from argparse_tui import invoke_tui
parser = argparse.ArgumentParser(prog="echo")
parser.add_argument("STRING", nargs="*")
parser.add_argument(
"-n",
action="store_true",
help="do not output the trailing newline",
)
invoke_tui(parser)
In this way, argparse
is not actually serving as an argument parser, but instead as the specification language for the TUI. Whoa.
ChatGPT and TUIview
Given the structured help text output of some CLI program, it turns out ChatGPT is decent at implementing an equivalent CLI using a Python argparse parser. Whoaaa.
Coupled with invoke_tui
, this means that argparse-tui is capable of producing a TUI for any CLI. This is the idea behind a tool built using argparse-tui: TUIview. It does not use ChatGPT itself, but I used ChatGPT to generate equivalent-enough argparse parsers for git
, rsync
, grep
.
Docs
See more examples in the reference docs.
Support
Brought to you by...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for argparse_tui-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de210c17b8bac362f4752718a068489ced78a0f7cba6dcc9c0ca40081e09494 |
|
MD5 | e0c256defbe1a33e3e4244d9ca988beb |
|
BLAKE2b-256 | 90f2ccc60b54777ab1592253c4e99043b1b7c01c31aa7806b79c8f5c7a3db6ba |