99 "strings"
1010
1111 "github.com/monster0506/meshexec/internal"
12- "github.com/monster0506/meshexec/internal/config"
1312 "github.com/spf13/cobra"
1413)
1514
@@ -19,6 +18,18 @@ var configCmd = &cobra.Command{
1918 Long : `Manage MeshExec CLI configuration files and settings.` ,
2019}
2120
21+ // indirections for testability
22+ var (
23+ // configNewManagerWithLevel is declared in network.go for package-wide reuse
24+ configRunEditor = func (editor string , argsWithFile []string ) error {
25+ c := exec .Command (editor , argsWithFile ... )
26+ c .Stdin = os .Stdin
27+ c .Stdout = os .Stdout
28+ c .Stderr = os .Stderr
29+ return c .Run ()
30+ }
31+ )
32+
2233var configShowCmd = & cobra.Command {
2334 Use : "show" ,
2435 Short : "Show current configuration" ,
@@ -28,7 +39,7 @@ var configShowCmd = &cobra.Command{
2839 if verbose {
2940 logLevel = "debug"
3041 }
31- manager := config . NewManagerWithLevel (logLevel )
42+ manager := configNewManagerWithLevel (logLevel )
3243
3344 // Get config path from global flags
3445 configPath , _ := cmd .Root ().PersistentFlags ().GetString ("config" )
@@ -64,7 +75,7 @@ var configInitCmd = &cobra.Command{
6475 if verbose {
6576 logLevel = "debug"
6677 }
67- manager := config . NewManagerWithLevel (logLevel )
78+ manager := configNewManagerWithLevel (logLevel )
6879
6980 // Get config path from global flags
7081 configPath , _ := cmd .Root ().PersistentFlags ().GetString ("config" )
@@ -92,7 +103,7 @@ var configEditCmd = &cobra.Command{
92103 if verbose {
93104 logLevel = "debug"
94105 }
95- manager := config . NewManagerWithLevel (logLevel )
106+ manager := configNewManagerWithLevel (logLevel )
96107
97108 // Respect global --config path
98109 if configPath , _ := cmd .Root ().PersistentFlags ().GetString ("config" ); configPath != "" {
@@ -157,11 +168,7 @@ var configEditCmd = &cobra.Command{
157168 logger .Info ("config edit: opening editor" , map [string ]interface {}{"editor" : editor , "args" : strings .Join (editorArgs , " " ), "path" : cfgPath })
158169 }
159170
160- c := exec .Command (editor , argsWithFile ... )
161- c .Stdin = os .Stdin
162- c .Stdout = os .Stdout
163- c .Stderr = os .Stderr
164- if err := c .Run (); err != nil {
171+ if err := configRunEditor (editor , argsWithFile ); err != nil {
165172 me := internal .NewConfigError ("editor_failed" , "failed to open editor" , map [string ]interface {}{"editor" : editor , "error" : err .Error ()})
166173 fmt .Fprintln (os .Stderr , internal .FormatUserError (me ))
167174 os .Exit (1 )
@@ -188,7 +195,7 @@ var configValidateCmd = &cobra.Command{
188195 if verbose {
189196 logLevel = "debug"
190197 }
191- manager := config . NewManagerWithLevel (logLevel )
198+ manager := configNewManagerWithLevel (logLevel )
192199 configPath , _ := cmd .Root ().PersistentFlags ().GetString ("config" )
193200 if configPath != "" {
194201 manager .SetConfigPath (configPath )
0 commit comments