diff --git a/cmd/humanlog/helper.go b/cmd/humanlog/helper.go index 5e34a9ab..08a505e5 100644 --- a/cmd/humanlog/helper.go +++ b/cmd/humanlog/helper.go @@ -51,7 +51,7 @@ func ensureLoggedIn( Affirmative("Yes!"). Negative("No."). Value(&confirms). - WithTheme(huh.ThemeCatppuccin()). + WithTheme(huhTheme). Run() if err != nil { return nil, err @@ -82,7 +82,7 @@ func ensureLoggedIn( Affirmative("Yes!"). Negative("No."). Value(&confirms). - WithTheme(huh.ThemeCatppuccin()). + WithTheme(huhTheme). Run() if err != nil { return nil, err @@ -225,7 +225,7 @@ func huhSelectOrganizations(ctx context.Context, client userv1connect.UserServic Title(title). Options(options...). Value(&selected). - WithTheme(huh.ThemeCatppuccin()). + WithTheme(huhTheme). Run() if err != nil { return -1, fmt.Errorf("prompting for org selection: %v", err) @@ -281,7 +281,7 @@ func ensureAccountSelected( Title("You have access to multiple accounts. Which one would you like to use?"). Options(options...). Value(&selected). - WithTheme(huh.ThemeCatppuccin()). + WithTheme(huhTheme). Run() if err != nil { return -1, fmt.Errorf("prompting for account selection: %v", err) diff --git a/cmd/humanlog/main.go b/cmd/humanlog/main.go index 4f39d6d5..67da00e3 100644 --- a/cmd/humanlog/main.go +++ b/cmd/humanlog/main.go @@ -18,6 +18,7 @@ import ( "github.com/99designs/keyring" "github.com/aybabtme/rgbterm" "github.com/blang/semver" + "github.com/charmbracelet/huh" types "github.com/humanlogio/api/go/types/v1" "github.com/humanlogio/humanlog" "github.com/humanlogio/humanlog/internal/pkg/config" @@ -64,6 +65,8 @@ var ( }() defaultApiAddr = "https://api.humanlog.io" defaultBaseSiteAddr = "https://humanlog.io" + + huhTheme = huh.ThemeCatppuccin() ) func fatalf(c *cli.Context, format string, args ...interface{}) { @@ -365,6 +368,7 @@ func newApp() *cli.App { } app.Commands = append( app.Commands, + onboardingCmd(getCtx, getLogger, getCfg, getState, getTokenSource, getAPIUrl, getBaseSiteURL, getHTTPClient), versionCmd(getCtx, getLogger, getCfg, getState, getTokenSource, getAPIUrl, getBaseSiteURL, getHTTPClient), authCmd(getCtx, getLogger, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), organizationCmd(getCtx, getLogger, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), diff --git a/cmd/humanlog/onboarding.go b/cmd/humanlog/onboarding.go new file mode 100644 index 00000000..332740ed --- /dev/null +++ b/cmd/humanlog/onboarding.go @@ -0,0 +1,59 @@ +package main + +import ( + "context" + "log/slog" + "net/http" + + "github.com/charmbracelet/huh" + "github.com/humanlogio/api/go/svc/auth/v1/authv1connect" + "github.com/humanlogio/humanlog/internal/pkg/config" + "github.com/humanlogio/humanlog/internal/pkg/state" + "github.com/humanlogio/humanlog/pkg/auth" + "github.com/urfave/cli" +) + +const onboardingCmdName = "onboarding" + +func onboardingCmd( + getCtx func(cctx *cli.Context) context.Context, + getLogger func(cctx *cli.Context) *slog.Logger, + getCfg func(cctx *cli.Context) *config.Config, + getState func(cctx *cli.Context) *state.State, + getTokenSource func(cctx *cli.Context) *auth.UserRefreshableTokenSource, + getAPIUrl func(cctx *cli.Context) string, + getBaseSiteURL func(cctx *cli.Context) string, + getHTTPClient func(*cli.Context) *http.Client, +) cli.Command { + return cli.Command{ + Name: onboardingCmdName, + Usage: "Onboarding humanlog after installs or updates", + Hidden: true, + Action: func(cctx *cli.Context) error { + var wantsSignup bool + err := huh.NewConfirm(). + Title("Welcome to humanlog. New features are coming up soon!"). + Description("Would you like to sign-up to learn more?"). + Affirmative("Yes!"). + Negative("No."). + Value(&wantsSignup). + WithTheme(huhTheme).Run() + if err != nil { + return err + } + if wantsSignup { + loginfo("awesome, thanks for your interest!") + ctx := getCtx(cctx) + state := getState(cctx) + tokenSource := getTokenSource(cctx) + apiURL := getAPIUrl(cctx) + httpClient := getHTTPClient(cctx) + authClient := authv1connect.NewAuthServiceClient(httpClient, apiURL) + _, err := performLoginFlow(ctx, state, authClient, tokenSource) + return err + } + loginfo("sounds good, enjoy humanlog! keep an eye on `https://humanlog.io` if you want to learn more") + return nil + }, + } +} diff --git a/cmd/humanlog/organization.go b/cmd/humanlog/organization.go index 2fe955b8..a08cbd58 100644 --- a/cmd/humanlog/organization.go +++ b/cmd/humanlog/organization.go @@ -183,7 +183,7 @@ func organizationCmd( err := huh.NewInput(). Title("How should this org be named?"). Value(&req.Name). - WithTheme(huh.ThemeCatppuccin()). + WithTheme(huhTheme). Run() if err != nil { return fmt.Errorf("requesting name from user: %v", err)