Skip to content

Commit

Permalink
ask user to login for recording
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Aug 23, 2024
1 parent 46e206d commit b4f32c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions client/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (g *guest) SaveRunbook(ctx context.Context, runbook *Runbook) (*GeneratedRu
return cl.SaveRunbook(ctx, runbook)
}

func GetLoggedInClient() (Client, error) {
return getLoggedInClient()
}

func getLoggedInClient() (Client, error) {
cl, err := New()
if err == nil {
Expand Down
6 changes: 5 additions & 1 deletion cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ func init() {
func recordHistory(cmd *cobra.Command, _ []string) {
ctx := cmd.Context()
logger := loggerFromCtx(ctx).With("command", "history")
cl, err := client.New()

cl, err := client.GetLoggedInClient()
if err != nil && errors.Is(err, client.ErrInvalidClient) {
display.Error(errors.New("You must be logged in to record a runbook. Please run `savvy login`"))
os.Exit(1)
} else if err != nil {
display.ErrorWithSupportCTA(err)
os.Exit(1)
}

historyCmds, err := selectAndExpandHistory(ctx, logger)
Expand Down
5 changes: 4 additions & 1 deletion cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ var recordCmd = &cobra.Command{
var programOutput = termenv.NewOutput(os.Stdout, termenv.WithColorCache(true))

func runRecordCmd(cmd *cobra.Command, _ []string) {
cl, err := client.New()
cl, err := client.GetLoggedInClient()
if err != nil && errors.Is(err, client.ErrInvalidClient) {
display.Error(errors.New("You must be logged in to record a runbook. Please run `savvy login`"))
os.Exit(1)
} else if err != nil {
display.ErrorWithSupportCTA(err)
os.Exit(1)
}
ctx := cmd.Context()

Expand Down

0 comments on commit b4f32c9

Please sign in to comment.