Skip to content

Commit 5d727e3

Browse files
committed
Correctly hide logging when run with no logging flags
1 parent 6a99258 commit 5d727e3

6 files changed

Lines changed: 50 additions & 14 deletions

File tree

cmd/meshexec/config.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ var configShowCmd = &cobra.Command{
1818
Use: "show",
1919
Short: "Show current configuration",
2020
Run: func(cmd *cobra.Command, args []string) {
21-
manager := config.NewManager()
21+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
22+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
23+
if verbose {
24+
logLevel = "debug"
25+
}
26+
manager := config.NewManagerWithLevel(logLevel)
2227

2328
// Get config path from global flags
2429
configPath, _ := cmd.Root().PersistentFlags().GetString("config")
@@ -47,7 +52,12 @@ var configInitCmd = &cobra.Command{
4752
Use: "init",
4853
Short: "Initialize default configuration file",
4954
Run: func(cmd *cobra.Command, args []string) {
50-
manager := config.NewManager()
55+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
56+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
57+
if verbose {
58+
logLevel = "debug"
59+
}
60+
manager := config.NewManagerWithLevel(logLevel)
5161

5262
// Get config path from global flags
5363
configPath, _ := cmd.Root().PersistentFlags().GetString("config")
@@ -78,7 +88,12 @@ var configValidateCmd = &cobra.Command{
7888
Use: "validate",
7989
Short: "Validate configuration file",
8090
Run: func(cmd *cobra.Command, args []string) {
81-
manager := config.NewManager()
91+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
92+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
93+
if verbose {
94+
logLevel = "debug"
95+
}
96+
manager := config.NewManagerWithLevel(logLevel)
8297
configPath, _ := cmd.Root().PersistentFlags().GetString("config")
8398
if configPath != "" {
8499
manager.SetConfigPath(configPath)

cmd/meshexec/daemon.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ var daemonCmd = &cobra.Command{
2424
}
2525

2626
// Load configuration (if present) so we honor user/device settings early
27-
manager := config.NewManager()
27+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
28+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
29+
if verbose {
30+
logLevel = "debug"
31+
}
32+
manager := config.NewManagerWithLevel(logLevel)
2833
cfgPath, _ := cmd.Root().PersistentFlags().GetString("config")
2934
if cfgPath != "" {
3035
manager.SetConfigPath(cfgPath)

cmd/meshexec/network.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ var joinCmd = &cobra.Command{
1717
Use: "join",
1818
Short: "Join the mesh network",
1919
Run: func(cmd *cobra.Command, args []string) {
20-
cfgMgr := config.NewManager()
20+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
21+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
22+
if verbose {
23+
logLevel = "debug"
24+
}
25+
cfgMgr := config.NewManagerWithLevel(logLevel)
2126
cfgPath, _ := cmd.Root().PersistentFlags().GetString("config")
2227
if cfgPath != "" {
2328
cfgMgr.SetConfigPath(cfgPath)
@@ -75,7 +80,12 @@ var listCmd = &cobra.Command{
7580
timeout = 5000 * time.Millisecond
7681
}
7782

78-
cfgMgr := config.NewManager()
83+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
84+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
85+
if verbose {
86+
logLevel = "debug"
87+
}
88+
cfgMgr := config.NewManagerWithLevel(logLevel)
7989
cfgPath, _ := cmd.Root().PersistentFlags().GetString("config")
8090
if cfgPath != "" {
8191
cfgMgr.SetConfigPath(cfgPath)
@@ -143,7 +153,12 @@ var statusCmd = &cobra.Command{
143153
}
144154

145155
// Load configuration
146-
cfgMgr := config.NewManager()
156+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
157+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
158+
if verbose {
159+
logLevel = "debug"
160+
}
161+
cfgMgr := config.NewManagerWithLevel(logLevel)
147162
cfgPath, _ := cmd.Root().PersistentFlags().GetString("config")
148163
if cfgPath != "" {
149164
cfgMgr.SetConfigPath(cfgPath)

cmd/meshexec/run.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ var runCmd = &cobra.Command{
3030
Example: "meshexec run -t \"os=linux && role=worker\" -- echo hello\nmeshexec run --target all -- uptime\nmeshexec run --dry-run -t 'arch=arm' -- cat /proc/cpuinfo",
3131
Run: func(cmd *cobra.Command, args []string) {
3232
// Load configuration
33-
cfgMgr := config.NewManager()
33+
logLevel, _ := cmd.Root().PersistentFlags().GetString("log-level")
34+
verbose, _ := cmd.Root().PersistentFlags().GetBool("verbose")
35+
if verbose {
36+
logLevel = "debug"
37+
}
38+
cfgMgr := config.NewManagerWithLevel(logLevel)
3439
cfgPath, _ := cmd.Root().PersistentFlags().GetString("config")
3540
if cfgPath != "" {
3641
cfgMgr.SetConfigPath(cfgPath)

internal/ble/manager.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ func NewManager(transport core.BLETransport, logger *logging.Logger) *Manager {
4747

4848
// getTransportType returns a string representation of the transport type
4949
func getTransportType(transport core.BLETransport) string {
50-
// Prefer precise identification via type switches on known implementations
50+
// Prefer precise identification for the in-package simulated transport
5151
switch transport.(type) {
5252
case *Transport:
5353
return "simulated"
54-
case *SidecarTransport:
55-
return "sidecar"
56-
case *tgTransport:
57-
return "tinygo"
5854
}
5955

6056
// Fallback: use type name heuristics

internal/config/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,4 @@ func (m *Manager) CreateDefaultConfig() error {
403403
m.logger.Info("Creating default configuration file", nil)
404404
config := internal.DefaultConfig()
405405
return m.Save(config)
406-
}
406+
}

0 commit comments

Comments
 (0)