Skip to content

huweihuang/cobra-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cobra-demo

cobra 命令行框架的Demo

steps

install cobra

go get -u github.com/spf13/cobra/cobra

init project

# mkdir 
mkdir -p cobra-demo && cd cobra-demo

# init project
cobra init --pkg-name github.com/huweihuang/cobra-demo

project tree

./
├── LICENSE
├── cmd
│   ├── root.go
└── main.go

add command

cobra add serve
cobra add config
cobra add create -p 'configCmd' # 在父命令config命令下创建子命令create,若没有指定-p,默认的父命令为rootCmd。

project tree

./
├── LICENSE
├── cmd
│   ├── config.go  # rootCmd的子命令 
│   ├── create.go  # config的子命令
│   ├── root.go    # 默认父命令
│   └── server.go  # rootCmd的子命令
└── main.go

Complete code logic

Complete specific code logic

About

cobra 命令行框架的Demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages