duanli9001 2018-03-21 12:48
浏览 62
已采纳

命令行标志和命令

I need to start working on command line tool, and I’ve few questions

we have decided to use cobra for go https://github.com/spf13/cobra

From the help :

$ cobra help

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.

Usage:
  cobra [command]

Available Commands:
  add         Add a command to a Cobra Application
  help        Help about any command
  init        Initialize a Cobra Application

Flags:
  -a, --author string    author name for copyright attribution (default "YOUR NAME")
      --config string    config file (default is $HOME/.cobra.yaml)
  -h, --help             help for cobra
  -l, --license string   name of license for the project
      --viper            use Viper for configuration (default true)

Use "cobra [command] --help" for more information about a command.

My questions are:

  1. what is the relations/diff between commands and flags (Available Commands) semantic ….
  2. is there is relations between command and flags
  3. Are single command should support flags
  4. in case in Need to provide command like deploy to x should it be ‘deploy -x’
  • 写回答

1条回答 默认 最新

  • dongxie3701 2018-03-21 13:31
    关注

    A command tells the application what to do, for example "tool sayhello". Flags are used to pass information required by the application to achieve its task, for example "tool sayhello --message='Hello World'". Flags are often shortened by using their first letter and one hyphen.

    How you design the commands and flags of your application is up to you. If you want to create a deployment tool for example, you could create a command "deploy" and a flag for the machine to deploy to: "tool deploy --machine=hostip".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改