Last active
December 1, 2017 05:04
-
-
Save flowerinthenight/221e26cea495e5adc3ae6a323b4fbdba to your computer and use it in GitHub Desktop.
This file contains 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 main | |
import ( | |
goflag "flag" | |
"github.com/golang/glog" | |
"github.com/spf13/cobra" | |
flag "github.com/spf13/pflag" | |
) | |
var ( | |
rootCmd = &cobra.Command{ | |
Long: "Use glog with cobra.", | |
Run: echo, | |
} | |
str string | |
) | |
func init() { | |
rootCmd.PersistentFlags().StringVar(&str, "echo", "hello", "echo string") | |
flag.CommandLine.AddGoFlagSet(goflag.CommandLine) | |
} | |
func echo(cmd *cobra.Command, args []string) { | |
goflag.Parse() | |
glog.Info("echo (info): ", str) | |
glog.Warning("echo (warn): ", str) | |
glog.Error("echo (error): ", str) | |
} | |
func main() { | |
err := rootCmd.Execute() | |
if err != nil { | |
glog.Error(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment