Last active
January 24, 2017 22:47
-
-
Save sdomino/d2639a4270adde117cb9641d32270632 to your computer and use it in GitHub Desktop.
Writing better CLI's one snake at a time: https://medium.com/@skdomino/writing-better-clis-one-snake-at-a-time-d22e50e60056#.1ahuzi4qp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package commands | |
import ( | |
"fmt" | |
"github.com/spf13/cobra" | |
"github.com/spf13/viper" | |
) | |
var ( | |
// alias for show | |
fetchCmd = &cobra.Command{ | |
Hidden: true, | |
Use: "fetch", | |
Short: "Display a file from the hoarder storage", | |
Long: ``, | |
Run: show, | |
} | |
// alias for show | |
getCmd = &cobra.Command{ | |
Hidden: true, | |
Use: "get", | |
Short: "Display a file from the hoarder storage", | |
Long: ``, | |
Run: show, | |
} | |
// | |
showCmd = &cobra.Command{ | |
Use: "show", | |
Short: "Display a file from the hoarder storage", | |
Long: ``, | |
Run: show, | |
} | |
) | |
// init | |
func init() { | |
fetchCmd.Flags().StringVarP(&key, "key", "k", "", "The key to get the data by") | |
getCmd.Flags().StringVarP(&key, "key", "k", "", "The key to get the data by") | |
showCmd.Flags().StringVarP(&key, "key", "k", "", "The key to get the data by") | |
} | |
// show utilizes the api to show data associated to key | |
func show(ccmd *cobra.Command, args []string) { | |
// handle any missing args | |
switch { | |
case key == "": | |
fmt.Println("Missing key - please provide the key for the record you'd like to create") | |
return | |
} | |
// do command stuff... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment