@@ -2,6 +2,7 @@ package system
22
33import (
44 "fmt"
5+ "slices"
56 "strings"
67
78 "github.com/docker/cli/cli/command"
@@ -14,6 +15,8 @@ import (
1415 "github.com/arduino/arduino-app-cli/internal/update"
1516 "github.com/arduino/arduino-app-cli/internal/update/apt"
1617 "github.com/arduino/arduino-app-cli/internal/update/arduino"
18+ "github.com/arduino/arduino-app-cli/pkg/board"
19+ "github.com/arduino/arduino-app-cli/pkg/board/remote/local"
1720 "github.com/arduino/arduino-app-cli/pkg/x"
1821)
1922
@@ -25,6 +28,8 @@ func NewSystemCmd(cfg config.Configuration) *cobra.Command {
2528 cmd .AddCommand (newDownloadImage (cfg ))
2629 cmd .AddCommand (newUpdateCmd ())
2730 cmd .AddCommand (newCleanUpCmd (cfg , servicelocator .GetDockerClient ()))
31+ cmd .AddCommand (newNetworkMode ())
32+ cmd .AddCommand (newkeyboardSet ())
2833
2934 return cmd
3035}
@@ -152,3 +157,81 @@ func newCleanUpCmd(cfg config.Configuration, docker command.Cli) *cobra.Command
152157 }
153158 return cmd
154159}
160+
161+ func newNetworkMode () * cobra.Command {
162+ cmd := & cobra.Command {
163+ Use : "network-mode <enable|disable|status>" ,
164+ Short : "Manage the network mode of the system" ,
165+ Args : cobra .ExactArgs (1 ),
166+ RunE : func (cmd * cobra.Command , args []string ) error {
167+ switch args [0 ] {
168+ case "enable" :
169+ if err := board .EnableNetworkMode (cmd .Context (), & local.LocalConnection {}); err != nil {
170+ return fmt .Errorf ("failed to enable network mode: %w" , err )
171+ }
172+
173+ feedback .Printf ("network mode enabled and started" )
174+ case "disable" :
175+ if err := board .DisableNetworkMode (cmd .Context (), & local.LocalConnection {}); err != nil {
176+ return fmt .Errorf ("failed to disable network mode: %w" , err )
177+ }
178+ feedback .Printf ("network mode disabled and stopped" )
179+ case "status" :
180+ if isEnabled , err := board .NetworkModeStatus (cmd .Context (), & local.LocalConnection {}); err != nil {
181+ return fmt .Errorf ("failed to check network mode status: %w" , err )
182+ } else {
183+ if isEnabled {
184+ feedback .Printf ("enabled" )
185+ } else {
186+ feedback .Printf ("disabled" )
187+ }
188+ }
189+ }
190+
191+ return nil
192+ }}
193+
194+ return cmd
195+ }
196+
197+ func newkeyboardSet () * cobra.Command {
198+ cmd := & cobra.Command {
199+ Use : "keyboard [layout]" ,
200+ Short : "Manage the keyboard layout of the system" ,
201+ Args : cobra .MaximumNArgs (1 ),
202+ RunE : func (cmd * cobra.Command , args []string ) error {
203+ layouts , err := board .ListKeyboardLayouts (& local.LocalConnection {})
204+ if err != nil {
205+ return fmt .Errorf ("failed to list keyboard layouts: %w" , err )
206+ }
207+
208+ if len (args ) == 0 {
209+ feedback .Printf ("available layouts:" )
210+ for _ , l := range layouts {
211+ feedback .Printf (" - %s: %s" , l .LayoutId , l .Description )
212+ }
213+ layout , err := board .GetKeyboardLayout (cmd .Context (), & local.LocalConnection {})
214+ if err != nil {
215+ return fmt .Errorf ("failed to get keyboard layout: %w" , err )
216+ }
217+ feedback .Printf ("\n current layout: %s" , layout )
218+ } else {
219+ layout := args [0 ]
220+
221+ if ! slices .ContainsFunc (layouts , func (l board.KeyboardLayout ) bool {
222+ return l .LayoutId == layout
223+ }) {
224+ return fmt .Errorf ("invalid layout code: %s" , layout )
225+ }
226+
227+ if err := board .SetKeyboardLayout (cmd .Context (), & local.LocalConnection {}, layout ); err != nil {
228+ return fmt .Errorf ("failed to set keyboard layout: %w" , err )
229+ }
230+ feedback .Printf ("keyboard layout set to %s" , layout )
231+ }
232+
233+ return nil
234+ }}
235+
236+ return cmd
237+ }
0 commit comments