@@ -11,34 +11,27 @@ import (
1111 "strings"
1212
1313 "github.com/arduino/go-paths-helper"
14- dockerClient "github.com/docker/docker/client"
1514 "github.com/spf13/cobra"
1615 "mkuznets.com/go/tabwriter"
1716
17+ "github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
1818 "github.com/bcmi-labs/orchestrator/internal/orchestrator"
1919 "github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
20- "github.com/bcmi-labs/orchestrator/internal/orchestrator/bricksindex"
21- "github.com/bcmi-labs/orchestrator/internal/orchestrator/modelsindex"
2220)
2321
24- func newAppCmd (
25- docker * dockerClient.Client ,
26- provisioner * orchestrator.Provision ,
27- modelsIndex * modelsindex.ModelsIndex ,
28- bricksIndex * bricksindex.BricksIndex ,
29- ) * cobra.Command {
22+ func newAppCmd () * cobra.Command {
3023 appCmd := & cobra.Command {
3124 Use : "app" ,
3225 Short : "Manage Arduino Apps" ,
3326 Long : "A CLI tool to manage Arduino Apps, including starting, stopping, logging, and provisioning." ,
3427 }
3528
3629 appCmd .AddCommand (newCreateCmd ())
37- appCmd .AddCommand (newStartCmd (docker , provisioner , modelsIndex , bricksIndex ))
30+ appCmd .AddCommand (newStartCmd ())
3831 appCmd .AddCommand (newStopCmd ())
39- appCmd .AddCommand (newRestartCmd (docker , provisioner , modelsIndex , bricksIndex ))
32+ appCmd .AddCommand (newRestartCmd ())
4033 appCmd .AddCommand (newLogsCmd ())
41- appCmd .AddCommand (newListCmd (docker ))
34+ appCmd .AddCommand (newListCmd ())
4235 appCmd .AddCommand (newPsCmd ())
4336 appCmd .AddCommand (newMonitorCmd ())
4437
@@ -75,12 +68,7 @@ func newCreateCmd() *cobra.Command {
7568 return cmd
7669}
7770
78- func newStartCmd (
79- docker * dockerClient.Client ,
80- provisioner * orchestrator.Provision ,
81- modelsIndex * modelsindex.ModelsIndex ,
82- bricksIndex * bricksindex.BricksIndex ,
83- ) * cobra.Command {
71+ func newStartCmd () * cobra.Command {
8472 return & cobra.Command {
8573 Use : "start app_path" ,
8674 Short : "Start an Arduino app" ,
@@ -93,7 +81,7 @@ func newStartCmd(
9381 if err != nil {
9482 return err
9583 }
96- return startHandler (cmd .Context (), docker , provisioner , app , modelsIndex , bricksIndex )
84+ return startHandler (cmd .Context (), app )
9785 },
9886 }
9987}
@@ -116,12 +104,7 @@ func newStopCmd() *cobra.Command {
116104 }
117105}
118106
119- func newRestartCmd (
120- docker * dockerClient.Client ,
121- provisioner * orchestrator.Provision ,
122- modelsIndex * modelsindex.ModelsIndex ,
123- bricksIndex * bricksindex.BricksIndex ,
124- ) * cobra.Command {
107+ func newRestartCmd () * cobra.Command {
125108 cmd := & cobra.Command {
126109 Use : "restart app_path" ,
127110 Short : "Restart or Start an Arduino app" ,
@@ -137,7 +120,7 @@ func newRestartCmd(
137120 if err := stopHandler (cmd .Context (), app ); err != nil {
138121 slog .Warn ("failed to stop app" , "error" , err )
139122 }
140- return startHandler (cmd .Context (), docker , provisioner , app , modelsIndex , bricksIndex )
123+ return startHandler (cmd .Context (), app )
141124 },
142125 }
143126 return cmd
@@ -175,14 +158,14 @@ func newMonitorCmd() *cobra.Command {
175158
176159}
177160
178- func newListCmd (docker * dockerClient. Client ) * cobra.Command {
161+ func newListCmd () * cobra.Command {
179162 var jsonFormat bool
180163
181164 cmd := & cobra.Command {
182165 Use : "list" ,
183166 Short : "List all running Python apps" ,
184167 RunE : func (cmd * cobra.Command , args []string ) error {
185- return listHandler (cmd .Context (), docker , jsonFormat )
168+ return listHandler (cmd .Context (), jsonFormat )
186169 },
187170 }
188171
@@ -263,15 +246,16 @@ func newPropertiesCmd() *cobra.Command {
263246 return cmd
264247}
265248
266- func startHandler (
267- ctx context.Context ,
268- docker * dockerClient.Client ,
269- provisioner * orchestrator.Provision ,
270- app app.ArduinoApp ,
271- modelsIndex * modelsindex.ModelsIndex ,
272- bricksIndex * bricksindex.BricksIndex ,
273- ) error {
274- for message := range orchestrator .StartApp (ctx , docker , provisioner , modelsIndex , bricksIndex , app ) {
249+ func startHandler (ctx context.Context , app app.ArduinoApp ) error {
250+ stream := orchestrator .StartApp (
251+ ctx ,
252+ servicelocator .GetDockerClient (),
253+ servicelocator .GetProvisioner (),
254+ servicelocator .GetModelsIndex (),
255+ servicelocator .GetBricksIndex (),
256+ app ,
257+ )
258+ for message := range stream {
275259 switch message .GetType () {
276260 case orchestrator .ProgressType :
277261 slog .Info ("progress" , slog .Float64 ("progress" , float64 (message .GetProgress ().Progress )))
@@ -317,12 +301,15 @@ func logsHandler(ctx context.Context, app app.ArduinoApp, tail *uint64) error {
317301 return nil
318302}
319303
320- func listHandler (ctx context.Context , docker * dockerClient.Client , jsonFormat bool ) error {
321- res , err := orchestrator .ListApps (ctx , docker , orchestrator.ListAppRequest {
322- ShowExamples : true ,
323- ShowApps : true ,
324- IncludeNonStandardLocationApps : true ,
325- })
304+ func listHandler (ctx context.Context , jsonFormat bool ) error {
305+ res , err := orchestrator .ListApps (ctx ,
306+ servicelocator .GetDockerClient (),
307+ orchestrator.ListAppRequest {
308+ ShowExamples : true ,
309+ ShowApps : true ,
310+ IncludeNonStandardLocationApps : true ,
311+ },
312+ )
326313 if err != nil {
327314 return nil
328315 }
0 commit comments