As others have mentioned, GPT is quite good at reading semi-structured data and producing a structured output. I find it is very effective to ask it to output in an already popular, domain specific format whenever possible. Let it use familiar idioms, instead of trying to coerce it to use a bespoke format.
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.
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.