Skip to content

Commit

Permalink
feat(onboarding): ask for sign-up when onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Oct 22, 2024
1 parent a6e06db commit 34de708
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/humanlog/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ensureLoggedIn(
Affirmative("Yes!").
Negative("No.").
Value(&confirms).
WithTheme(huh.ThemeCatppuccin()).
WithTheme(huhTheme).
Run()
if err != nil {
return nil, err
Expand Down Expand Up @@ -82,7 +82,7 @@ func ensureLoggedIn(
Affirmative("Yes!").
Negative("No.").
Value(&confirms).
WithTheme(huh.ThemeCatppuccin()).
WithTheme(huhTheme).
Run()
if err != nil {
return nil, err
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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),
Expand Down
59 changes: 59 additions & 0 deletions cmd/humanlog/onboarding.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
2 changes: 1 addition & 1 deletion cmd/humanlog/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 34de708

Please sign in to comment.