Skip to main content

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

GitHub release (latest SemVer) GitHub Release Date License GitHub Repo stars GitHub issues GitHub pull requests PyPI - Downloads Docker Pulls Changelog Funding


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)
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparse-tui-0.2.0.tar.gz (58.3 kB view hashes)

Uploaded Source

Built Distribution

argparse_tui-0.2.0-py3-none-any.whl (66.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page