-
Notifications
You must be signed in to change notification settings - Fork 0
Add styled CLI output with spinner for logout command #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,11 +56,23 @@ func (a *Auth) GetToken(ctx context.Context) (string, error) { | |
| return token, nil | ||
| } | ||
|
|
||
| // Logout removes the stored auth token from the keyring | ||
| var ErrNotLoggedIn = errors.New("not currently logged in") | ||
|
|
||
| // Logout removes the stored auth token from the keyring. | ||
| // Returns ErrNotLoggedIn if no token was stored. | ||
| // Emits success/note events through the sink if one is configured. | ||
| func (a *Auth) Logout() error { | ||
| output.EmitLog(a.sink, "Logging out...") | ||
|
|
||
| err := a.tokenStorage.DeleteAuthToken() | ||
| if errors.Is(err, keyring.ErrKeyNotFound) { | ||
| return nil | ||
| output.EmitNote(a.sink, "Not currently logged in.") | ||
| return ErrNotLoggedIn | ||
| } | ||
| return err | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| output.EmitSuccess(a.sink, "Logged out successfully.") | ||
|
Comment on lines
+65
to
+76
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: We should do these events in a way so that the TUI can handle them in it's update flow. The success looks fine here. Not sure about the other ones yet :D |
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package output | ||
|
|
||
| type Event interface { | ||
| LogEvent | WarningEvent | ContainerStatusEvent | ProgressEvent | UserInputRequestEvent | ContainerLogLineEvent | ||
| LogEvent | WarningEvent | SuccessEvent | NoteEvent | ContainerStatusEvent | ProgressEvent | UserInputRequestEvent | ContainerLogLineEvent | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: I think we'll need to document a bit which event should be used for which kind of message, and what the difference is in how they're going to be displayed. |
||
| } | ||
|
|
||
| type Sink interface { | ||
|
|
@@ -26,6 +26,14 @@ type WarningEvent struct { | |
| Message string | ||
| } | ||
|
|
||
| type SuccessEvent struct { | ||
| Message string | ||
| } | ||
|
|
||
| type NoteEvent struct { | ||
| Message string | ||
| } | ||
|
|
||
| type ContainerStatusEvent struct { | ||
| Phase string // e.g., "pulling", "starting", "waiting", "ready" | ||
| Container string | ||
|
|
@@ -76,6 +84,14 @@ func EmitWarning(sink Sink, message string) { | |
| Emit(sink, WarningEvent{Message: message}) | ||
| } | ||
|
|
||
| func EmitSuccess(sink Sink, message string) { | ||
| Emit(sink, SuccessEvent{Message: message}) | ||
| } | ||
|
|
||
| func EmitNote(sink Sink, message string) { | ||
| Emit(sink, NoteEvent{Message: message}) | ||
| } | ||
|
|
||
| func EmitStatus(sink Sink, phase, container, detail string) { | ||
| Emit(sink, ContainerStatusEvent{Phase: phase, Container: container, Detail: detail}) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought: It looks a bit funny that we're passing a nil sink in interactive mode, and that we basically have to define the output in 2 different places:
ui/run_logout.go): strings "Logging out", "Not currently logged in.", "Logged out successfully."cmd/logout.go): the same strings in output.Emit*() callsWhat do you think @silv-io ? Not sure how this could be improved...
Maybe in the future we can implement something like a FileSink to capture everything in a log file when running in interactive mode.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, rebased to keep fresh, and waiting for @silv-io to take a second look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks funny because it's using the sinks wrong :P
The model defines own messages for success and failure even though we already emit those in the internal logout package.
What we need to do here is use a TUISink and handle the actual Logout success messages in the model