Created
February 28, 2016 12:11
-
-
Save anonymous/94dccf42b133a425f41e 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 ( | |
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