# Create a go module for the cli
go mod init testctl
# Install cobra (This will create the cobra executable in $GOPATH/bin directory)
env GO111MODULE=on go get github.com/spf13/cobra/cobra
# Initialize cobra library
cobra init --pkg-name testctl
Create new commands
cobra add create
cobra add pod
Run and Install CLI
# Run
go run main.go create pod
# Install
go install testctl
Instructions
main.go calls Execute() function inside cmd/root.go
root.go is the top level command
All the commands by default are created as top level command. To a commond as subcommand, modify the AddCommand inside init()
Flags for a command/subcomand are defined inside init()
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.