diff --git a/cmd/login/login.go b/cmd/login/login.go new file mode 100644 index 00000000..e9848a97 --- /dev/null +++ b/cmd/login/login.go @@ -0,0 +1,53 @@ +package login + +import ( + "github.com/spf13/cobra" + "github.com/spf13/viper" + + cmdAnalytics "github.com/launchdarkly/ldcli/cmd/analytics" + "github.com/launchdarkly/ldcli/cmd/cliflags" + "github.com/launchdarkly/ldcli/internal/analytics" +) + +func NewLoginCmd( + analyticsTrackerFn analytics.TrackerFn, +) *cobra.Command { + cmd := cobra.Command{ + Long: "", + PreRun: func(cmd *cobra.Command, args []string) { + analyticsTrackerFn( + viper.GetString(cliflags.AccessTokenFlag), + viper.GetString(cliflags.BaseURIFlag), + viper.GetBool(cliflags.AnalyticsOptOut), + ).SendCommandRunEvent(cmdAnalytics.CmdRunEventProperties(cmd, "login", nil)) + }, + RunE: run(), + Short: "Log in to your LaunchDarkly account to set up the CLI", + Use: "login", + } + + helpFun := cmd.HelpFunc() + cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { + analyticsTrackerFn( + viper.GetString(cliflags.AccessTokenFlag), + viper.GetString(cliflags.BaseURIFlag), + viper.GetBool(cliflags.AnalyticsOptOut), + ).SendCommandRunEvent(cmdAnalytics.CmdRunEventProperties( + cmd, + "login", + map[string]interface{}{ + "action": "help", + }, + )) + + helpFun(cmd, args) + }) + + return &cmd +} + +func run() func(*cobra.Command, []string) error { + return func(cmd *cobra.Command, args []string) error { + return nil + } +} diff --git a/cmd/root.go b/cmd/root.go index 972d80e9..f5703e04 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,7 @@ import ( "github.com/launchdarkly/ldcli/cmd/cliflags" configcmd "github.com/launchdarkly/ldcli/cmd/config" flagscmd "github.com/launchdarkly/ldcli/cmd/flags" + logincmd "github.com/launchdarkly/ldcli/cmd/login" memberscmd "github.com/launchdarkly/ldcli/cmd/members" resourcecmd "github.com/launchdarkly/ldcli/cmd/resources" "github.com/launchdarkly/ldcli/internal/analytics" @@ -85,6 +86,7 @@ func NewRootCommand( "completion", "config", "help", + "login", } { if cmd.HasParent() && cmd.Parent().Name() == name { cmd.DisableFlagParsing = true @@ -186,6 +188,7 @@ func NewRootCommand( configCmd := configcmd.NewConfigCmd(configService, analyticsTrackerFn) cmd.AddCommand(configCmd.Cmd()) cmd.AddCommand(NewQuickStartCmd(analyticsTrackerFn, clients.EnvironmentsClient, clients.FlagsClient)) + cmd.AddCommand(logincmd.NewLoginCmd(analyticsTrackerFn)) cmd.AddCommand(resourcecmd.NewResourcesCmd()) resourcecmd.AddAllResourceCmds(cmd, clients.ResourcesClient, analyticsTrackerFn) diff --git a/cmd/templates.go b/cmd/templates.go index 8350efe8..024b82a4 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -14,6 +14,7 @@ Commands: {{rpad "setup" 29}} Create your first feature flag using a step-by-step guide {{rpad "config" 29}} View and modify specific configuration values {{rpad "completion" 29}} Enable command autocompletion within supported shells + {{rpad "login" 29}} Log in to your LaunchDarkly account Common resource commands: {{rpad "flags" 29}} List, create, and modify feature flags and their targeting