-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onboarding): ask for sign-up when onboarding
- Loading branch information
Showing
4 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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 | ||
}, | ||
} | ||
} |
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