jumpaku / cyamli Goto Github PK
View Code? Open in Web Editor NEWA command line tool to generate command line interfaces for your command line tools from the YAML-based CLI schemas.
License: BSD 2-Clause "Simplified" License
A command line tool to generate command line interfaces for your command line tools from the YAML-based CLI schemas.
License: BSD 2-Clause "Simplified" License
https://github.com/Jumpaku/cyamli/blob/main/python3/cli_gen.py.tpl#L62
https://github.com/Jumpaku/cyamli/blob/main/python3/cli_gen.py.tpl#L121
Wrong:
input.{{$Argument.InputFieldName}} = parse_value({{$Argument.InputFieldType}}, arguments[{{$Index}}:])
Correct:
input.{{$Argument.InputFieldName}} = parse_value({{$Argument.InputFieldType}}, *arguments[{{$Index}}:])
Shouldn't we fix the command examples in the README?
go run main.go cli.gen.go list -c=config.yaml
go run main.go cli.gen.go fetch -c=config.yaml -v table1 table2
cli.yaml
name: demo
description: demo app to get table information from databases
subcommands:
list:
description: list tables
options:
-config:
description: path to config file
short: -c
describe:
description: show information of tables
options:
-config:
description: path to config file
short: -c
-verbose:
description: shows detailed log
short: -v
type: boolean
arguments:
- name: tables
variadic: true
description: names of tables to be described
main..py
import cli_gen
import sys
def func(args, err):
if err is not None:
raise err
print(args)
cli = cli_gen.CLI()
cli.FUNC = func
cli.list.FUNC = func
cli.describe.FUNC = func
cli_gen.run(cli, sys.argv)
cyamli python3 -schema-path=cli.yaml -out-path=cli_gen.py
python main.py describe -c=config.json -v T1 T2 T3
Traceback (most recent call last):
File "/work/main.py", line 16, in <module>
cli_gen.run(cli, sys.argv)
File "/work/cli_gen.py", line 178, in run
cli.describe.FUNC(input, ex)
File "/work/main.py", line 7, in func
raise err
File "/work/cli_gen.py", line 175, in run
input = resolve_CLI_Describe_Input(rest_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/work/cli_gen.py", line 92, in resolve_CLI_Describe_Input
split[1] = "True"
~~~~~^^^
IndexError: list assignment index out of range
Like typical Linux commands, there are times when a main command with options is sufficient, without the need for a subcommand.
I think it would be better if the subcommand were not mandatory, as shown below. What do you think?
<program> [<subcommand>] [<option>|<argument>]... [-- [<argument>]...]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.