cobra

command module
v0.0.0-...-bb92a31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

CLI Boilerplate

Project Setup

# 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()
  • Command line arguments are read inside Run()

Documentation

Overview

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL