Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] Cobra style command line interface and project layout #312

Open
lichuan0620 opened this issue Apr 28, 2020 · 0 comments
Open
Labels
area/cli Command tool related functions. kind/design Categorizes issue or PR as related to design.

Comments

@lichuan0620
Copy link
Contributor

/kind design
/area cli

This issue proposes a new, Cobra-style CLI and a project layout that goes with it.

The Proposed Design

Right now, this is the recommended Nirvana project layout:

.
├── bin                           # binaries reside within project directories
│   └── nirvana-myproject         #
├── build                         # Dockerfiles reside within project directories
│   └── nirvana-myproject         #
│       └── Dockerfile            #
├── cmd                           # main packages reside within project directories
│   └── nirvana-myproject         #
│       └── main.go               #
├── pkg                           # packages
│   ...                           # other stuff

This encourages the user to build multiple binaries and house them within multiple container images. The CLI of each binary would support different flags and args.

With Cobra, however, encourage the use of command in support of flags and args. Basically, instead of this:

$ monitoring-init --mongo-endpoint=$(MONGO_ENDPOINT)
$ monitoring-server --port=8080 --mongo-endpoint=$(MONGO_ENDPOINT)
$ monitoring-operator --resync-period=5m

Cobra would do this:

$ monitoring init --mongo-endpoint=$(MONGO_ENDPOINT)
$ monitoring serve --port=8080 --mongo-endpoint=$(MONGO_ENDPOINT)
$ monitoring operate --resync-period=5m

And the project layout would look like this:

.
├── cmd                           # cmd package keeps all the commands
│   └── init.go                   # sub command init
│   └── serve.go                  # sub command serve
│   └── operate.go                # sub command operate
├── pkg                           # packages
├── Dockerfile                    # only one Dockerfile
├── main.go                       # only one main package located at the project root
├── project_bin                   # only one binary
│   ...                           # other stuff

Why Bother?

  1. Fewer steps during CICD. Only one binary and one Dockerfile.
  2. Easier delivery and version management. You could send someone an image, only to find out later that they need more, and have to send them more, and have to worry about if they have the compatible versions.
  3. Easier to learn. Cobra-style project layout and CLI are already massively popular, being adopted by Docker, Kubernetes, and many popular open-source projects. Why should we do things differently?
  4. Nirvana CLI is based on Cobra anyway, so why don't we focus on its core functionality and just use Cobra as it is?

/cc @ddysher @iawia002 @supereagle

@caicloud-bot caicloud-bot added kind/design Categorizes issue or PR as related to design. area/cli Command tool related functions. labels Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Command tool related functions. kind/design Categorizes issue or PR as related to design.
Projects
None yet
Development

No branches or pull requests

2 participants