Skip to content

Commit cc8b494

Browse files
committed
Handle conflicts
1 parent fccc9d8 commit cc8b494

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
7171
newVolumeCmd(cfg),
7272
newUpdateCmd(cfg),
7373
newDocsCmd(),
74-
newAWSCmd(cfg, tel),
75-
newSnapshotCmd(cfg, tel),
74+
newAWSCmd(cfg),
75+
newSnapshotCmd(cfg),
7676
)
7777

7878
return root

cmd/snapshot.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ import (
1111
"github.com/localstack/lstk/internal/output"
1212
"github.com/localstack/lstk/internal/runtime"
1313
"github.com/localstack/lstk/internal/snapshot"
14-
"github.com/localstack/lstk/internal/telemetry"
1514
"github.com/localstack/lstk/internal/ui"
1615
"github.com/spf13/cobra"
1716
)
1817

19-
func newSnapshotCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
18+
func newSnapshotCmd(cfg *env.Env) *cobra.Command {
2019
cmd := &cobra.Command{
2120
Use: "snapshot",
2221
Short: "Manage emulator snapshots",
2322
}
24-
cmd.AddCommand(newSnapshotSaveCmd(cfg, tel))
23+
cmd.AddCommand(newSnapshotSaveCmd(cfg))
2524
return cmd
2625
}
2726

28-
func newSnapshotSaveCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
27+
func newSnapshotSaveCmd(cfg *env.Env) *cobra.Command {
2928
return &cobra.Command{
3029
Use: "save [destination]",
3130
Short: "Save a snapshot of the emulator state",
@@ -40,7 +39,7 @@ The destination must be a file path. Use a path prefix to save locally:
4039
Cloud destinations are not yet supported.`,
4140
Args: cobra.MaximumNArgs(1),
4241
PreRunE: initConfig,
43-
RunE: commandWithTelemetry("snapshot save", tel, func(cmd *cobra.Command, args []string) error {
42+
RunE: func(cmd *cobra.Command, args []string) error {
4443
var destArg string
4544
if len(args) > 0 {
4645
destArg = args[0]
@@ -80,6 +79,6 @@ Cloud destinations are not yet supported.`,
8079
return ui.RunSnapshotSave(cmd.Context(), rt, containers, exporter, dest)
8180
}
8281
return snapshot.Save(cmd.Context(), rt, containers, exporter, dest, output.NewPlainSinkSplit(os.Stdout, os.Stderr))
83-
}),
82+
},
8483
}
8584
}

internal/snapshot/save.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Save(ctx context.Context, rt runtime.Runtime, containers []config.Container
2424
return fmt.Errorf("checking emulator status: %w", err)
2525
}
2626
if !running {
27-
output.EmitError(sink, output.ErrorEvent{
27+
sink.Emit(output.ErrorEvent{
2828
Title: "LocalStack is not running",
2929
Actions: []output.ErrorAction{
3030
{Label: "Start LocalStack:", Value: "lstk"},
@@ -34,33 +34,33 @@ func Save(ctx context.Context, rt runtime.Runtime, containers []config.Container
3434
return output.NewSilentError(fmt.Errorf("LocalStack is not running"))
3535
}
3636

37-
output.EmitSpinnerStart(sink, "Saving snapshot...")
37+
sink.Emit(output.SpinnerStart("Saving snapshot..."))
3838

3939
body, err := exporter.ExportState(ctx)
4040
if err != nil {
41-
output.EmitSpinnerStop(sink)
41+
sink.Emit(output.SpinnerStop())
4242
return fmt.Errorf("export state from LocalStack: %w", err)
4343
}
4444
defer func() { _ = body.Close() }()
4545

4646
w, err := os.Create(dest)
4747
if err != nil {
48-
output.EmitSpinnerStop(sink)
48+
sink.Emit(output.SpinnerStop())
4949
return fmt.Errorf("save to %s: %w", dest, err)
5050
}
5151

5252
if _, err := io.Copy(w, body); err != nil {
5353
_ = w.Close()
54-
output.EmitSpinnerStop(sink)
54+
sink.Emit(output.SpinnerStop())
5555
return fmt.Errorf("write snapshot: %w", err)
5656
}
5757

5858
if err := w.Close(); err != nil {
59-
output.EmitSpinnerStop(sink)
59+
sink.Emit(output.SpinnerStop())
6060
return fmt.Errorf("close snapshot: %w", err)
6161
}
6262

63-
output.EmitSpinnerStop(sink)
64-
output.EmitSuccess(sink, fmt.Sprintf("Snapshot saved to %s", dest))
63+
sink.Emit(output.SpinnerStop())
64+
sink.Emit(output.MessageEvent{Severity: output.SeveritySuccess, Text: fmt.Sprintf("Snapshot saved to %s", dest)})
6565
return nil
6666
}

internal/snapshot/save_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func (f *fakeExporter) ExportState(_ context.Context) (io.ReadCloser, error) {
3131
return io.NopCloser(bytes.NewReader(f.body)), nil
3232
}
3333

34-
func captureEvents(t *testing.T) (output.Sink, func() []any) {
34+
func captureEvents(t *testing.T) (output.Sink, func() []output.Event) {
3535
t.Helper()
36-
var events []any
37-
sink := output.SinkFunc(func(event any) {
36+
var events []output.Event
37+
sink := output.SinkFunc(func(event output.Event) {
3838
events = append(events, event)
3939
})
40-
return sink, func() []any { return events }
40+
return sink, func() []output.Event { return events }
4141
}
4242

4343
func healthyRunningMock(t *testing.T) *runtime.MockRuntime {

0 commit comments

Comments
 (0)