Skip to content

Commit af944c5

Browse files
author
Piotr
committed
command fixes
1 parent fe82b70 commit af944c5

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

main.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,34 @@ where you can filter and browse well formatted application output.
3737
verbose, _ := cmd.Flags().GetBool("verbose")
3838
utils.SetLoggerLevel(verbose)
3939
},
40+
PersistentPostRun: func(cmd *cobra.Command, args []string) {
41+
// by default, `stdin` mode will run if [command] is not provided
42+
if len(args) == 0 {
43+
utils.Logger.Info("Listen to stdin (from pipe)")
44+
go modes.ConsumeStdin(http.Ch)
45+
startWebServer(cmd)
46+
}
47+
},
4048
}
4149

4250
var listenStdCmd = &cobra.Command{
4351
Use: "stdin [command]",
4452
Short: "Listens to STDOUT/STDERR of a provided command. Example `logdy stdin \"npm run dev\"`",
4553
Long: ``,
4654
Run: func(cmd *cobra.Command, args []string) {
47-
4855
if len(args) == 0 {
4956
utils.Logger.Info("Listen to stdin (from pipe)")
5057
go modes.ConsumeStdin(http.Ch)
51-
return
58+
} else {
59+
utils.Logger.WithFields(logrus.Fields{
60+
"cmd": args[0],
61+
}).Info("Listen to command stdout")
62+
arg := strings.Split(args[0], " ")
63+
modes.StartCmd(http.Ch, arg[0], arg[1:])
5264
}
53-
54-
utils.Logger.WithFields(logrus.Fields{
55-
"cmd": args[0],
56-
}).Info("Listen to command stdout")
57-
arg := strings.Split(args[0], " ")
58-
modes.StartCmd(http.Ch, arg[0], arg[1:])
5965
},
6066
PersistentPostRun: func(cmd *cobra.Command, args []string) {
61-
startWebServer(cmd, args)
67+
startWebServer(cmd)
6268
},
6369
}
6470

@@ -78,7 +84,7 @@ var followCmd = &cobra.Command{
7884
modes.FollowFiles(http.Ch, args)
7985
},
8086
PersistentPostRun: func(cmd *cobra.Command, args []string) {
81-
startWebServer(cmd, args)
87+
startWebServer(cmd)
8288
},
8389
}
8490

@@ -145,7 +151,7 @@ var listenSocketCmd = &cobra.Command{
145151
go modes.StartSocketServers(http.Ch, ip, args)
146152
},
147153
PersistentPostRun: func(cmd *cobra.Command, args []string) {
148-
startWebServer(cmd, args)
154+
startWebServer(cmd)
149155
},
150156
}
151157

@@ -167,21 +173,18 @@ var demoSocketCmd = &cobra.Command{
167173
go modes.GenerateRandomData(produceJson, num, http.Ch, context.Background())
168174
},
169175
PersistentPostRun: func(cmd *cobra.Command, args []string) {
170-
startWebServer(cmd, args)
176+
startWebServer(cmd)
171177
},
172178
}
173179

174-
func startWebServer(cmd *cobra.Command, args []string) {
180+
func startWebServer(cmd *cobra.Command) {
181+
utils.Logger.Debug("Starting webserver")
182+
175183
noupdates, _ := cmd.Flags().GetBool("no-updates")
176184
if !noupdates && Version != "0.0.0" {
177185
go utils.CheckUpdatesAndPrintInfo(Version)
178186
}
179187

180-
if len(args) == 0 {
181-
utils.Logger.Info("Listen to stdin (from pipe)")
182-
go modes.ConsumeStdin(http.Ch)
183-
}
184-
185188
if !config.AnalyticsEnabled {
186189
utils.Logger.Warn("No opt-out from analytics, we'll be receiving anonymous usage data, which will be used to improve the product. To opt-out use the flag --no-analytics.")
187190
}

0 commit comments

Comments
 (0)