A simple command-line application built with Go and Cobra.
# Clone the repository
git clone https://github.com/jbrinkman/MyCli.git
cd MyCli
# Build the application
go build -o mycli
# Optionally, install it to your GOPATH/bin
go install# Run the base command
./mycli# Display version information
./mycli version# Echo text to the console
./mycli echo Hello, World!
# Echo text in uppercase
./mycli echo --uppercase Hello, World!# Enable verbose output
./mycli --verbose
# Get help
./mycli --helpTo add a new command:
- Create a new file in the
cmddirectory - Define your command using the Cobra framework
- Add it to the root command in the
init()function
Example:
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var newCmd = &cobra.Command{
Use: "new",
Short: "A brief description",
Long: `A longer description`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("New command executed")
},
}
func init() {
RootCmd.AddCommand(newCmd)
}