Skip to content

Commit

Permalink
command fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr committed Dec 10, 2024
1 parent fe82b70 commit af944c5
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,34 @@ where you can filter and browse well formatted application output.
verbose, _ := cmd.Flags().GetBool("verbose")
utils.SetLoggerLevel(verbose)
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
// by default, `stdin` mode will run if [command] is not provided
if len(args) == 0 {
utils.Logger.Info("Listen to stdin (from pipe)")
go modes.ConsumeStdin(http.Ch)
startWebServer(cmd)
}
},
}

var listenStdCmd = &cobra.Command{
Use: "stdin [command]",
Short: "Listens to STDOUT/STDERR of a provided command. Example `logdy stdin \"npm run dev\"`",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {

if len(args) == 0 {
utils.Logger.Info("Listen to stdin (from pipe)")
go modes.ConsumeStdin(http.Ch)
return
} else {
utils.Logger.WithFields(logrus.Fields{
"cmd": args[0],
}).Info("Listen to command stdout")
arg := strings.Split(args[0], " ")
modes.StartCmd(http.Ch, arg[0], arg[1:])
}

utils.Logger.WithFields(logrus.Fields{
"cmd": args[0],
}).Info("Listen to command stdout")
arg := strings.Split(args[0], " ")
modes.StartCmd(http.Ch, arg[0], arg[1:])
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
startWebServer(cmd, args)
startWebServer(cmd)
},
}

Expand All @@ -78,7 +84,7 @@ var followCmd = &cobra.Command{
modes.FollowFiles(http.Ch, args)
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
startWebServer(cmd, args)
startWebServer(cmd)
},
}

Expand Down Expand Up @@ -145,7 +151,7 @@ var listenSocketCmd = &cobra.Command{
go modes.StartSocketServers(http.Ch, ip, args)
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
startWebServer(cmd, args)
startWebServer(cmd)
},
}

Expand All @@ -167,21 +173,18 @@ var demoSocketCmd = &cobra.Command{
go modes.GenerateRandomData(produceJson, num, http.Ch, context.Background())
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
startWebServer(cmd, args)
startWebServer(cmd)
},
}

func startWebServer(cmd *cobra.Command, args []string) {
func startWebServer(cmd *cobra.Command) {
utils.Logger.Debug("Starting webserver")

noupdates, _ := cmd.Flags().GetBool("no-updates")
if !noupdates && Version != "0.0.0" {
go utils.CheckUpdatesAndPrintInfo(Version)
}

if len(args) == 0 {
utils.Logger.Info("Listen to stdin (from pipe)")
go modes.ConsumeStdin(http.Ch)
}

if !config.AnalyticsEnabled {
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.")
}
Expand Down

0 comments on commit af944c5

Please sign in to comment.