@@ -37,28 +37,34 @@ where you can filter and browse well formatted application output.
37
37
verbose , _ := cmd .Flags ().GetBool ("verbose" )
38
38
utils .SetLoggerLevel (verbose )
39
39
},
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
+ },
40
48
}
41
49
42
50
var listenStdCmd = & cobra.Command {
43
51
Use : "stdin [command]" ,
44
52
Short : "Listens to STDOUT/STDERR of a provided command. Example `logdy stdin \" npm run dev\" `" ,
45
53
Long : `` ,
46
54
Run : func (cmd * cobra.Command , args []string ) {
47
-
48
55
if len (args ) == 0 {
49
56
utils .Logger .Info ("Listen to stdin (from pipe)" )
50
57
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 :])
52
64
}
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 :])
59
65
},
60
66
PersistentPostRun : func (cmd * cobra.Command , args []string ) {
61
- startWebServer (cmd , args )
67
+ startWebServer (cmd )
62
68
},
63
69
}
64
70
@@ -78,7 +84,7 @@ var followCmd = &cobra.Command{
78
84
modes .FollowFiles (http .Ch , args )
79
85
},
80
86
PersistentPostRun : func (cmd * cobra.Command , args []string ) {
81
- startWebServer (cmd , args )
87
+ startWebServer (cmd )
82
88
},
83
89
}
84
90
@@ -145,7 +151,7 @@ var listenSocketCmd = &cobra.Command{
145
151
go modes .StartSocketServers (http .Ch , ip , args )
146
152
},
147
153
PersistentPostRun : func (cmd * cobra.Command , args []string ) {
148
- startWebServer (cmd , args )
154
+ startWebServer (cmd )
149
155
},
150
156
}
151
157
@@ -167,21 +173,18 @@ var demoSocketCmd = &cobra.Command{
167
173
go modes .GenerateRandomData (produceJson , num , http .Ch , context .Background ())
168
174
},
169
175
PersistentPostRun : func (cmd * cobra.Command , args []string ) {
170
- startWebServer (cmd , args )
176
+ startWebServer (cmd )
171
177
},
172
178
}
173
179
174
- func startWebServer (cmd * cobra.Command , args []string ) {
180
+ func startWebServer (cmd * cobra.Command ) {
181
+ utils .Logger .Debug ("Starting webserver" )
182
+
175
183
noupdates , _ := cmd .Flags ().GetBool ("no-updates" )
176
184
if ! noupdates && Version != "0.0.0" {
177
185
go utils .CheckUpdatesAndPrintInfo (Version )
178
186
}
179
187
180
- if len (args ) == 0 {
181
- utils .Logger .Info ("Listen to stdin (from pipe)" )
182
- go modes .ConsumeStdin (http .Ch )
183
- }
184
-
185
188
if ! config .AnalyticsEnabled {
186
189
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." )
187
190
}
0 commit comments