Skip to content

Commit 9762c45

Browse files
refactor: decouple config (#535)
1 parent 8b1df7c commit 9762c45

39 files changed

+485
-394
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- unconvert
1717
- unparam
1818
- forbidigo
19+
- gochecknoinits
1920
settings:
2021
forbidigo:
2122
forbid:

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ tasks:
347347
mv "$OUTPUT_DIR"/arduino/app_bricks/static "$DST_DIR"
348348
rm -r "$OUTPUT_DIR" "$ZIP_NAME"
349349
# Bumps the default pinned latest base python image tag
350-
sed -i "s#RunnerVersion = \".*#RunnerVersion = \"${semver_tag}\"#" cmd/arduino-app-cli/internal/servicelocator/servicelocator.go
350+
sed -i "s#runnerVersion = \".*#runnerVersion = \"${semver_tag}\"#" cmd/arduino-app-cli/internal/servicelocator/servicelocator.go
351351
352352
update-deb-copyright:
353353
desc: Extract project and dependency licenses into asd copyright

cmd/arduino-app-cli/app/app.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@ import (
55

66
"github.com/spf13/cobra"
77

8-
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
8+
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
99
"github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
10+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1011
)
1112

12-
func NewAppCmd() *cobra.Command {
13+
func NewAppCmd(cfg config.Configuration) *cobra.Command {
1314
appCmd := &cobra.Command{
1415
Use: "app",
1516
Short: "Manage Arduino Apps",
1617
Long: "A CLI tool to manage Arduino Apps, including starting, stopping, logging, and provisioning.",
1718
}
1819

19-
appCmd.AddCommand(newCreateCmd())
20-
appCmd.AddCommand(newStartCmd())
21-
appCmd.AddCommand(newStopCmd())
22-
appCmd.AddCommand(newRestartCmd())
23-
appCmd.AddCommand(newLogsCmd())
24-
appCmd.AddCommand(newListCmd())
20+
appCmd.AddCommand(newCreateCmd(cfg))
21+
appCmd.AddCommand(newStartCmd(cfg))
22+
appCmd.AddCommand(newStopCmd(cfg))
23+
appCmd.AddCommand(newRestartCmd(cfg))
24+
appCmd.AddCommand(newLogsCmd(cfg))
25+
appCmd.AddCommand(newListCmd(cfg))
2526
appCmd.AddCommand(newPsCmd())
26-
appCmd.AddCommand(newMonitorCmd())
27+
appCmd.AddCommand(newMonitorCmd(cfg))
2728

2829
return appCmd
2930
}
3031

3132
func Load(idOrPath string) (app.ArduinoApp, error) {
32-
id, err := orchestrator.ParseID(idOrPath)
33+
id, err := servicelocator.GetAppIDProvider().ParseID(idOrPath)
3334
if err != nil {
3435
return app.ArduinoApp{}, fmt.Errorf("invalid app path: %s", idOrPath)
3536
}

cmd/arduino-app-cli/app/list.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@ import (
1111
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
1212
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1313
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
14+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1415
"github.com/bcmi-labs/orchestrator/pkg/tablestyle"
1516
)
1617

17-
func newListCmd() *cobra.Command {
18+
func newListCmd(cfg config.Configuration) *cobra.Command {
1819
var showBrokenApps bool
1920

2021
cmd := &cobra.Command{
2122
Use: "list",
2223
Short: "List all running Python apps",
2324
Run: func(cmd *cobra.Command, args []string) {
24-
listHandler(cmd.Context(), showBrokenApps)
25+
listHandler(cmd.Context(), cfg, showBrokenApps)
2526
},
2627
}
2728

2829
cmd.Flags().BoolVarP(&showBrokenApps, "show-broken-apps", "", false, "Output a list of broken apps")
2930
return cmd
3031
}
3132

32-
func listHandler(ctx context.Context, showBrokenApps bool) {
33+
func listHandler(ctx context.Context, cfg config.Configuration, showBrokenApps bool) {
3334
res, err := orchestrator.ListApps(ctx,
3435
servicelocator.GetDockerClient(),
3536
orchestrator.ListAppRequest{
3637
ShowExamples: true,
3738
ShowApps: true,
3839
IncludeNonStandardLocationApps: true,
3940
},
41+
servicelocator.GetAppIDProvider(),
42+
cfg,
4043
)
4144
if err != nil {
4245
feedback.Fatal(err.Error(), feedback.ErrGeneric)

cmd/arduino-app-cli/app/logs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1212
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
1313
"github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
14+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1415
)
1516

16-
func newLogsCmd() *cobra.Command {
17+
func newLogsCmd(cfg config.Configuration) *cobra.Command {
1718
var (
1819
tail uint64
1920
follow bool
@@ -33,7 +34,7 @@ func newLogsCmd() *cobra.Command {
3334
}
3435
return logsHandler(cmd.Context(), app, &tail, follow, all)
3536
},
36-
ValidArgsFunction: completion.ApplicationNames(),
37+
ValidArgsFunction: completion.ApplicationNames(cfg),
3738
}
3839
cmd.Flags().Uint64Var(&tail, "tail", 100, "Tail the last N logs")
3940
cmd.Flags().BoolVar(&follow, "follow", false, "Follow the logs")

cmd/arduino-app-cli/app/monitor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"github.com/spf13/cobra"
55

66
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/completion"
7+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
78
)
89

9-
func newMonitorCmd() *cobra.Command {
10+
func newMonitorCmd(cfg config.Configuration) *cobra.Command {
1011
return &cobra.Command{
1112
Use: "monitor",
1213
Short: "Monitor the Python app",
1314
RunE: func(cmd *cobra.Command, args []string) error {
1415
panic("not implemented")
1516
},
16-
ValidArgsFunction: completion.ApplicationNames(),
17+
ValidArgsFunction: completion.ApplicationNames(cfg),
1718
}
1819
}

cmd/arduino-app-cli/app/new.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
910
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1011
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
12+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1113
)
1214

13-
func newCreateCmd() *cobra.Command {
15+
func newCreateCmd(cfg config.Configuration) *cobra.Command {
1416
var (
1517
icon string
1618
bricks []string
@@ -26,7 +28,7 @@ func newCreateCmd() *cobra.Command {
2628
RunE: func(cmd *cobra.Command, args []string) error {
2729
cobra.MinimumNArgs(1)
2830
name := args[0]
29-
return createHandler(cmd.Context(), name, icon, noPyton, noSketch, fromApp)
31+
return createHandler(cmd.Context(), cfg, name, icon, noPyton, noSketch, fromApp)
3032
},
3133
}
3234

@@ -40,9 +42,9 @@ func newCreateCmd() *cobra.Command {
4042
return cmd
4143
}
4244

43-
func createHandler(ctx context.Context, name string, icon string, noPython, noSketch bool, fromApp string) error {
45+
func createHandler(ctx context.Context, cfg config.Configuration, name string, icon string, noPython, noSketch bool, fromApp string) error {
4446
if fromApp != "" {
45-
id, err := orchestrator.ParseID(fromApp)
47+
id, err := servicelocator.GetAppIDProvider().ParseID(fromApp)
4648
if err != nil {
4749
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
4850
return nil
@@ -51,7 +53,7 @@ func createHandler(ctx context.Context, name string, icon string, noPython, noSk
5153
resp, err := orchestrator.CloneApp(ctx, orchestrator.CloneAppRequest{
5254
Name: &name,
5355
FromID: id,
54-
})
56+
}, servicelocator.GetAppIDProvider(), cfg)
5557
if err != nil {
5658
feedback.Fatal(err.Error(), feedback.ErrGeneric)
5759
return nil
@@ -70,7 +72,7 @@ func createHandler(ctx context.Context, name string, icon string, noPython, noSk
7072
Icon: icon,
7173
SkipPython: noPython,
7274
SkipSketch: noSketch,
73-
})
75+
}, servicelocator.GetAppIDProvider(), cfg)
7476
if err != nil {
7577
feedback.Fatal(err.Error(), feedback.ErrGeneric)
7678
return nil

cmd/arduino-app-cli/app/restart.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77

88
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/completion"
99
"github.com/bcmi-labs/orchestrator/cmd/feedback"
10+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1011
)
1112

12-
func newRestartCmd() *cobra.Command {
13+
func newRestartCmd(cfg config.Configuration) *cobra.Command {
1314
cmd := &cobra.Command{
1415
Use: "restart app_path",
1516
Short: "Restart or Start an Arduino app",
@@ -26,9 +27,9 @@ func newRestartCmd() *cobra.Command {
2627
if err := stopHandler(cmd.Context(), app); err != nil {
2728
feedback.Warning(fmt.Sprintf("failed to stop app: %s", err.Error()))
2829
}
29-
return startHandler(cmd.Context(), app)
30+
return startHandler(cmd.Context(), cfg, app)
3031
},
31-
ValidArgsFunction: completion.ApplicationNames(),
32+
ValidArgsFunction: completion.ApplicationNames(cfg),
3233
}
3334
return cmd
3435
}

cmd/arduino-app-cli/app/start.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1212
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
1313
"github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
14+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1415
)
1516

16-
func newStartCmd() *cobra.Command {
17+
func newStartCmd(cfg config.Configuration) *cobra.Command {
1718
return &cobra.Command{
1819
Use: "start app_path",
1920
Short: "Start an Arduino app",
@@ -26,13 +27,13 @@ func newStartCmd() *cobra.Command {
2627
if err != nil {
2728
return err
2829
}
29-
return startHandler(cmd.Context(), app)
30+
return startHandler(cmd.Context(), cfg, app)
3031
},
31-
ValidArgsFunction: completion.ApplicationNames(),
32+
ValidArgsFunction: completion.ApplicationNames(cfg),
3233
}
3334
}
3435

35-
func startHandler(ctx context.Context, app app.ArduinoApp) error {
36+
func startHandler(ctx context.Context, cfg config.Configuration, app app.ArduinoApp) error {
3637
out, _, getResult := feedback.OutputStreams()
3738

3839
stream := orchestrator.StartApp(
@@ -42,6 +43,7 @@ func startHandler(ctx context.Context, app app.ArduinoApp) error {
4243
servicelocator.GetModelsIndex(),
4344
servicelocator.GetBricksIndex(),
4445
app,
46+
cfg,
4547
)
4648
for message := range stream {
4749
switch message.GetType() {

cmd/arduino-app-cli/app/stop.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1111
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
1212
"github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
13+
"github.com/bcmi-labs/orchestrator/internal/orchestrator/config"
1314
)
1415

15-
func newStopCmd() *cobra.Command {
16+
func newStopCmd(cfg config.Configuration) *cobra.Command {
1617
return &cobra.Command{
1718
Use: "stop app_path",
1819
Short: "Stop an Arduino app",
@@ -27,7 +28,7 @@ func newStopCmd() *cobra.Command {
2728
}
2829
return stopHandler(cmd.Context(), app)
2930
},
30-
ValidArgsFunction: completion.ApplicationNames(),
31+
ValidArgsFunction: completion.ApplicationNames(cfg),
3132
}
3233
}
3334

0 commit comments

Comments
 (0)