/cobra

DCS367 homework - a simple "replacement" for spf13/cobra

Primary LanguageGoApache License 2.0Apache-2.0

cobra

GoDoc

A simple "replacement" for spf13/cobra, and it just works!

Example

package main

import (
	"fmt"

	"github.com/robinWongM/cobra"
)

func main() {
	rootCmd := &cobra.Command{Use: "root", Run: func(_ *cobra.Command, _ []string) {}}

	helloCmd := &cobra.Command{
		Use: "hello",
		Run: func(_ *cobra.Command, args []string) {
			name := "World"
			if len(args) >= 1 {
				name = args[0]
			}
			fmt.Printf("Hello, %v!\n", name)
		},
	}

	rootCmd.AddCommand(helloCmd)

	rootCmd.Execute()
}

Acknowledgements

This repository contains (lots of) code from spf13/cobra, which is licensed under Apache License, Version 2.0.