Skip to content

Commit

Permalink
feat: Create login command (#319)
Browse files Browse the repository at this point in the history
Create login command
  • Loading branch information
dbolson authored Jun 17, 2024
1 parent 06073ae commit f151a71
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cmd/login/login.go
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,6 +86,7 @@ func NewRootCommand(
"completion",
"config",
"help",
"login",
} {
if cmd.HasParent() && cmd.Parent().Name() == name {
cmd.DisableFlagParsing = true
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f151a71

Please sign in to comment.