FauxCLI (发音 foak-ley) 从给定的 YAML 文件模拟一个命令行客户端。
安装:
$ go get github.com/nextrevision/fauxcli
在当前目录创建一个 cli.yaml 文件:
name: spiderpig
help: does whatever a spiderpig does
commands:
- name: swing
help: swings from a web
output: |
I can't do that, I'm a pig!
- name: plop
help: super secret maneuver
output: |
Look out!
运行 fauxcli:
$ fauxcli
does whatever a spiderpig does
Usage:
spiderpig [command]
Available Commands:
swing swings from a web
plop super secret maneuver
Flags:
-h, --help help for spiderpig
Use "spiderpig [command] --help" for more information about a command.
子命令:
$ fauxcli swing
I can't do that, I'm a pig!
别名:
$ alias spiderpig='fauxcli'
$ spiderpig plop
Look out!
安装
go:
go get github.com/nextrevision/fauxcli
使用 GitHub 版本:
# OSX
curl -s -o /usr/local/bin/fauxcli https://github.com/nextrevision/fauxcli/releases/download/1.0.0/fauxcli_darwin_amd64
# Linux
curl -s -o /usr/local/bin/fauxcli https://github.com/nextrevision/fauxcli/releases/download/1.0.0/fauxcli_linux_amd64
chmod +x /usr/local/bin/fauxcli
cli.yaml
---
# (required) name of the command
name: mycliapp
# (required) the help text for the command (displayed with -h)
help: does something cool
# additional command aliases
aliases: ["myapp", "app"]
# output to print when the command is run
# if this key is omitted, the command will act as a
# parent to any subcommands, essentially doing nothing
# but printing the help text
output: |
Hello, World!
# flags available to the command
flags:
# (required) long name of the flag (--debug)
- name: debug
# (required) help text for the flag
help: enables debugging
# short name for the flag (-d)
short: d
# default value of the flag
default: false
# make the flag globally available
global: true
# the type of the value (default string)
# available types:
# - string
# - bool
# - int
# - float
type: bool
# subcommands (nested from all the options above)
commands:
- name: subcommand1
help: a subcommand
flags:
- name: upper
help: converts output to uppercase
short: u
type: bool
output: |
{{ if .Flags.upper.Bool -}}
HELLO FROM SC1!
{{ else -}}
Hello from SC1!
{{ end -}}
- name: subcommand2
help: another subcommand with children
commands:
- name: child1
help: the first child command
output: |
Hello from child1
- name: child2
help: the second child command
output: |
Hello from child2
FauxCLI 使用 Go 编写,托管在 GitHub:
https://github.com/nextrevision/fauxcli
ppt.cc/fVjECx ppt.cc/fEnHsx ppt.cc/fRZTnx ppt.cc/fSZ3cx ppt.cc/fLOuCx ppt.cc/fE9Nux ppt.cc/fL5Kyx ppt.cc/fIr1ax ppt.cc/f71Yqx tecmint.com linuxcool.com linux.die.net linux.it.net.cn ostechnix.com unix.com ubuntugeek.com runoob.com man.linuxde.net bit.ly/2EzoUDo bit.ly/2tW6eYT bit.ly/2X6vadl bit.ly/2viLpHU linuxprobe.com linuxtechi.com howtoforge.com linuxstory.org systutorials.com ghacks.net linuxopsys.com v.gd/2P9wTx v.gd/FtfpqE v.gd/eMfHsm v.gd/Ub7mqv v.gd/RReVk0 v.gd/vS3uTI v.gd/4Zxmba
Total Pageviews
Tuesday, 30 May 2023
FauxCLI:从给定的 YAML 文件模拟命令行客户端
Labels:
go
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment