248 points · by willm · 3y ago · 70 comments
Trogon is a project to generate a TUI for command line apps.
It presents the arguments, options, and switches as a form. Editing the form generates a command line, which you can then run with a keypress.
I'm a lover of the command line. But I can recall only a fraction of the switches for most commands I use. I would love it if there was a TUI available for most commands.
Trogon currently works with Python and the Click library, but I would like it to cover more of the Python ecosystem and also generate TUIs for apps not written in Python.
More information in the repository.
Let me know what you think...
Once you have that (and it’s actually adopted) there are many possibilities. TUI/GUI is just one of them. Think autocomplete, type checking, discoverability...
[0] https://github.com/oilshell/oil/wiki/Shellac-Protocol-Propos...
I'm dreaming of a universal standard based on JSON Schema. Dynamicity is a challenge of course. I guess one needs to strike a balance between static data, say for each subcommand, and a full blown configuration language, say nix.
I hate to be the LLM guy but they're really good at processing semi-structured data to structured data. You could go that route and have a universal autocomplete for the CLI. Kinda like Co-Pilot for Bash, or you could use it to do what the parent's doing and have a universal TUI program for building commands.
https://github.com/simonw/sqlite-utils/commit/ec12b780d5dcd6...
There's an animated GIF demo of the result here: https://github.com/simonw/sqlite-utils/issues/545#issuecomme...
To install:
pipx install sqlite-utils
Then add the trogon dependency - this command ensures it gets added to the correct virtual environment: sqlite-utils install trogon
Then run this: sqlite-utils tui
Screenshot in the docs: https://sqlite-utils.datasette.io/en/stable/cli.html#cli-tui pipx inject sqlite-utils trogon
or really, pipx install 'sqlite-utils[tui]'
i believe you can expose sub-commands only if an extra is installed; i know this is true for separate entry points.I’m thinking a lot could be extracted from help and man pages. But maybe for some apps we could just write it by hand, or partially by hand.
These schemas could be in a repo and downloaded on demand.
In fact I’d love to try to do that
My tool uPlaybook[0] is kind of a CookieCutter [1] / Ansible [2] mashup, and the playbooks typically would have a number of "slots" you can configure to control the templating, like project name, license, if you want to "git init", that sort of thing.
It currently auto-generates a argparse interface, or it can interactively ask you those questions. But I've been working on a Textual UI as well. I chose argparse over Click largely because I want to work with minimal dependencies, and the Textual UI would be an optional dependency.
Going to have to check this guy out.
[0] https://github.com/linsomniac/uplaybook [1] https://cookiecutter.readthedocs.io/en/stable/ [2] https://www.ansible.com/
The biggest thing preventing me from learning more CLI explained in one sentence, I'll definitely be looking into this.
cmd —help
man cmd
ls -la /usr/share/doc/cmd
While some of the language can be daunting, it is generally good reads. And these days we have ChatGPT etc that can help explain tricky words etc in more context, even if you native language is not English.
My new default advice actually for junior developers here in Sweden. Works for many other tech areas too, not just the terminal.
It's somewhat related to this because it's generating a TUI dynamically based on an input schema coming over the wire via gRPC.
Would love any feedback http://uggly.bytester.net
But, also, “What is old is new again”.
Back in the days of the mainframe and 3270 terminals, all of the commands were pretty much like this. There really was no command line. Rather, it was a screen of fields filled in by the operator and sent wholesale to the system.
Of course it did not end there. Most every Unix system had some kind of, effectively, “curses” based, full screen administration TUI. They were all pretty good for basic and intermediate tasks. I recall doing a lot of disk operations (partition, raid/striping, etc) just following prompts on these things.
Unix System V actually had a rather nice form and menu package you could use from scripts to do your own TUI just like the admin console they shipped.
Anyway, nice project. Just always interesting to watch stuff come around again.
https://twitter.com/renan_r_santoss/status/16603059638391029...
ok, we’re cooking with gas now!
For example, there might be a frequency option whose value can be either annual or monthly. If this was communicated correctly in a man page then it's still possible for someone to typo that as monttly.
They'd pick it up if the error reporting is good, but having the options in a tui should prevent such issues.
So here's a simple attempt at taking the output of `black --help` and turning it into a python `argparse` script. You could feed the `--help` or man page for pretty much any command into GPT-4 with this sort of prompt and get an argparse script. It probably doesn't hurt that GPT-4 is already familiar with the argument syntax for all the popular cli tools.
You could then imagine executing the generated code against a faux-argparse library which instantiates the data structures you need to render a Trogon UI. Probably best to do this in an appropriate sandbox.
$ black --help | aichat --model gpt-4 --prompt 'write a python program that uses argparse to *exactly* parse this tools command line'
```python
import argparse
import sys
def main(args=None):
parser = argparse.ArgumentParser(description="The uncompromising code formatter.")
parser.add_argument("SRC", nargs="*", help="Source files to format")
parser.add_argument("-c", "--code", type=str, help="Format the code passed in as a string.")
parser.add_argument("-l", "--line-length", type=int, default=88, help="How many characters per line to allow. [default: 88]")
parser.add_argument("-t", "--target-version", choices=["py33", "py34", "py35", "py36", "py37", "py38", "py39", "py310", "py311"], help="Python versions that should be supported by Black's output.")
parser.add_argument("--pyi", action="store_true", help="Format all input files like typing stubs regardless of file extension (useful when piping source on standard input).")
...
parser.add_argument("-h", "--help", action="help", help="Show this message and exit.")
if args is None:
args = sys.argv[1:]
parsed_args = parser.parse_args(args)
print(parsed_args)
if __name__ == "__main__":
main()
```
This Python program uses argparse to parse the command line options for the Black code formatter. You can run this script and pass the command line arguments to see the parsed output.Even though CLI parameters are passed to the application as strings, in reality they are often expected to be (and converted to) numbers, enums, lists, file descriptors, … And don't forget that some parameters are optional and/or can be repeated.
In short, there is ample opportunity for proper type annotations.
So you want the parameters to be annotated for their valid values?
Have you not heard of man pages?
I honestly have no idea what else you could mean by type annotations for cli parameters. Do you have an example?
https://gitlab.com/stavros/parachute
Unfortunately, it doesn't seem to work, failing to find the `cli.command()` function (a group function) after I decorate `cli()` with @tui...
$ . <(fab --print-completion-script zsh)
to enable autocomplete for fab in zsh shell.I got it working for my sqlite-utils tool in zsh by running this:
eval "$(_SQLITE_UTILS_COMPLETE=zsh_source sqlite-utils)"what I envisioned is a similar experience for the CLI tools we've come to know and love
not sure anyone neeeeeeds that, but no-one neeeeded an IDE at first too