Skip to content

Commit

Permalink
dev --verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
teintinu authored Sep 3, 2021
1 parent 7e4aab0 commit 12f7ee1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func init() {
rootCmd.AddCommand(buildCmd)
internal.Logger.FlagDeclare(buildCmd)
internal.Logger.LogFlagDeclare(buildCmd)
}

var buildCmd = &cobra.Command{
Expand All @@ -17,7 +17,7 @@ var buildCmd = &cobra.Command{
Long: "Builds all packages on workspace",
Args: cobra.RangeArgs(0, 0),
RunE: func(cmd *cobra.Command, args []string) error {
internal.Logger.FlagInit()
internal.Logger.LogFlagInit()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var DevOpts = internal.TestOptions{}

func init() {
rootCmd.AddCommand(devCmd)
internal.Logger.FlagDeclare(devCmd)
internal.Logger.LogFlagDeclare(devCmd)
}

var devCmd = &cobra.Command{
Expand All @@ -18,7 +18,7 @@ var devCmd = &cobra.Command{
Long: `Test libraries and run executables in watch mode`,
Args: cobra.RangeArgs(0, 0),
RunE: func(cmd *cobra.Command, args []string) error {
internal.Logger.FlagInit()
internal.Logger.LogFlagInit()
repo := mustLoadRepository(true)
if err := internal.CheckEngines(repo); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func init() {
rootCmd.AddCommand(runCmd)
internal.Logger.FlagDeclare(runCmd)
internal.Logger.LogFlagDeclare(runCmd)
}

var runCmd = &cobra.Command{
Expand All @@ -20,7 +20,7 @@ var runCmd = &cobra.Command{
// DisableFlagsInUseLine: true,
// SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
internal.Logger.FlagInit()
internal.Logger.LogFlagInit()
repo := mustLoadRepository(true)
var packagesToRun []string = []string{}

Expand Down
5 changes: 3 additions & 2 deletions internal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func devTestApps(repo *Repository, wg *sync.WaitGroup, webterm *WebTerm) {
if strings.Contains(lineWithColors, "\x1b[K") {
wtts.setRunning()
resultLine = ""
total = ""
total = "0"
failed = ""
return
}
Expand All @@ -74,7 +74,8 @@ func devTestApps(repo *Repository, wg *sync.WaitGroup, webterm *WebTerm) {
total = testResult[3]
failed = testResult[1]
} else if strings.Contains(line, "Ran all test suites") ||
strings.Contains(line, "No tests found related to files changed since last commit") {
strings.Contains(line, "No tests found related to files changed since last commit") ||
strings.Contains(line, "Press Enter to trigger a test run") {
if total == "0" {
wtts.setUnknow()
} else if failed == "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ type InternalLogger struct {
var flagVerbose bool
var flagQuiet bool

func (logger *InternalLogger) FlagDeclare(cmd *cobra.Command, args ...interface{}) {
func (logger *InternalLogger) LogFlagDeclare(cmd *cobra.Command, args ...interface{}) {
cmd.Flags().BoolVar(&flagVerbose, "verbose", false, "")
cmd.Flags().BoolVar(&flagQuiet, "quit", false, "")
}

func (logger *InternalLogger) FlagInit(args ...interface{}) {
func (logger *InternalLogger) LogFlagInit(args ...interface{}) {
if flagVerbose {
logger.logging = int(LoggingDebug)
} else if flagQuiet {
Expand Down
4 changes: 4 additions & 0 deletions internal/webterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (webterm *WebTerm) Start(port int32) {
func (webterm *WebTerm) processCommand(command []string) {
tabId := command[0]
actionId := command[1]
Logger.Debug("<" + strings.Join(command, " "))
if tabId == "*" {
if actionId == "exit" {
os.Exit(0)
Expand All @@ -88,6 +89,9 @@ func (webterm *WebTerm) sendToFrontEnd(tabId string, action string, args ...stri
webterm.toFrontend = nil
}
}
if Logger.logging >= int(LoggingDebug) {
Logger.Debug(">" + tabId + "." + action + "(" + strings.Join(args, ", ") + ")")
}
}

var RegRemoveANSI = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
12 changes: 7 additions & 5 deletions internal/webtermTabShell.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (tab *WebTermTab) startPty(

cmd, err := getCommand()
if err != nil {
tab.consoleOutput(fmt.Sprintf("Error getting pty command: %s\r\n", err))
tab.consoleOutput(fmt.Sprintf("Error getting pty on tab %s command: %s\r\n", tab.title, err))
return
}

Expand All @@ -126,12 +126,12 @@ func (tab *WebTermTab) startPty(

func (tab *WebTermTab) runInPty(cmd *exec.Cmd) {
if tab.pty != nil {
tab.consoleOutput("duplicated pty")
tab.consoleOutput("duplicated pty tab: " + tab.title)
return
}
pty, err := pty.Start(cmd)
if err != nil {
tab.consoleOutput(fmt.Sprintf("Error creating pty: %s\r\n", err))
tab.consoleOutput(fmt.Sprintf("Error creating pty on tab %s : %s\r\n", tab.title, err))
return
}
tab.pty = pty
Expand All @@ -140,7 +140,7 @@ func (tab *WebTermTab) runInPty(cmd *exec.Cmd) {
for !tab.webterm.IsClosed() {
line, err := cmdConsole.ReadString(linefeedDelimiter)
if err != nil {
tab.consoleOutput(fmt.Sprintf("Error reading from pty: %s\r\n", err))
tab.consoleOutput(fmt.Sprintf("Error reading from pty tab %s: %s\r\n", tab.title, err))
tab.pty = nil
return
}
Expand All @@ -161,7 +161,9 @@ func (tab *WebTermTab) consoleOutput(line string) {
}
b := append(tab.lastConsoleOutputLines, line)[limit:]
tab.lastConsoleOutputLines = b
Logger.Debug("consoleOutput ", tab.title, ":", line)
if Logger.logging >= int(LoggingDebug) {
Logger.Debug(tab.title+":", strings.TrimSpace(RegRemoveANSI.ReplaceAllString(line, "")))
}
}

func (tab *WebTermTab) tabHandlerForWS(
Expand Down

0 comments on commit 12f7ee1

Please sign in to comment.