-
Notifications
You must be signed in to change notification settings - Fork 5
Add update command #95
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ca1cfe2
Add update command
silv-io b0a7b02
Buffer partial writes and only emit complete lines in logLineWriter
silv-io be54549
Fix windows tests
silv-io 53d8a06
Address rabbit
silv-io 8f5a9da
Improve handling of homebrew tests
silv-io a7c473a
Improve binary extraction
silv-io 77b9051
Split up into different install methods
silv-io b314159
Use github token
silv-io 1f856f9
Fix in-place update on windows
silv-io 1d862a1
Address comments
silv-io File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,32 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/localstack/lstk/internal/env" | ||
| "github.com/localstack/lstk/internal/output" | ||
| "github.com/localstack/lstk/internal/ui" | ||
| "github.com/localstack/lstk/internal/update" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newUpdateCmd(cfg *env.Env) *cobra.Command { | ||
| var checkOnly bool | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "update", | ||
| Short: "Update lstk to the latest version", | ||
| Long: "Check for and apply updates to the lstk CLI. Respects the original installation method (Homebrew, npm, or direct binary).", | ||
| PreRunE: initConfig, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if isInteractiveMode(cfg) { | ||
| return ui.RunUpdate(cmd.Context(), checkOnly, cfg.GitHubToken) | ||
| } | ||
| return update.Update(cmd.Context(), output.NewPlainSink(os.Stdout), checkOnly, cfg.GitHubToken) | ||
| }, | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| cmd.Flags().BoolVar(&checkOnly, "check", false, "Only check for updates without applying them") | ||
|
|
||
| return cmd | ||
| } | ||
|
silv-io marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| package ui | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "os" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
| "github.com/localstack/lstk/internal/output" | ||
| "github.com/localstack/lstk/internal/update" | ||
| ) | ||
|
|
||
| func RunUpdate(parentCtx context.Context, checkOnly bool, githubToken string) error { | ||
| ctx, cancel := context.WithCancel(parentCtx) | ||
| defer cancel() | ||
|
|
||
| app := NewApp("", "", "", cancel, withoutHeader()) | ||
| p := tea.NewProgram(app, tea.WithInput(os.Stdin), tea.WithOutput(os.Stdout)) | ||
| runErrCh := make(chan error, 1) | ||
|
|
||
| go func() { | ||
| err := update.Update(ctx, output.NewTUISink(programSender{p: p}), checkOnly, githubToken) | ||
| runErrCh <- err | ||
| if err != nil && !errors.Is(err, context.Canceled) { | ||
| p.Send(runErrMsg{err: err}) | ||
| return | ||
| } | ||
| p.Send(runDoneMsg{}) | ||
| }() | ||
|
|
||
| model, err := p.Run() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if app, ok := model.(App); ok && app.Err() != nil { | ||
| return output.NewSilentError(app.Err()) | ||
| } | ||
|
|
||
| runErr := <-runErrCh | ||
| if runErr != nil && !errors.Is(runErr, context.Canceled) { | ||
| return runErr | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.