Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2016 12:11
Show Gist options
  • Save anonymous/94dccf42b133a425f41e to your computer and use it in GitHub Desktop.
Save anonymous/94dccf42b133a425f41e to your computer and use it in GitHub Desktop.
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/spf13/cobra"
)
func main() {
if err := NewRootCmd().Execute(); err != nil {
log.Fatalln(err)
}
}
type Args struct {
TenantID string
SubscriptionID string
}
var args Args
func NewRootCmd() *cobra.Command {
var rootCmd = &cobra.Command{
Use: "root",
}
rootCmd.Flags().StringVar(&args.TenantID, "tenant-id", "", "azure subscription id")
rootCmd.Flags().StringVar(&args.SubscriptionID, "subscription-id", "", "azure tenant id")
x := rootCmd.Flags().Lookup("tenant-id")
log.Infof("%q %q %T", x.Name, x.Usage, x)
// prints: INFO[0000] "tenant-id" "azure subscription id" *pflag.Flag
x = rootCmd.Flags().Lookup("subscription-id")
log.Infof("%q %q %T", x.Name, x.Usage, x)
// prints: INFO[0000] "subscription-id" "azure tenant id" *pflag.Flag
return rootCmd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment