Skip to content

Commit

Permalink
run on start
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsq committed Nov 3, 2023
1 parent 1bf1951 commit 67b0996
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ USAGE:
wtc [[flags] [regex command]]
e.g.: wtc
// will read [.]wtc.y[a]ml
e.g.: wtc "_test\.go$" "go test -cover {PKG}"
e.g.: wtc -r -sfmt "_test\.go$" "go test -cover {PKG}"
wtc [flags]] [rule-name]
e.g.: wtc -t rule-name
Expand All @@ -54,6 +54,9 @@ FLAGS:
or export WTC_IGNORE_RULES=ruleA,ruleB)
-no-trace
disable messages.
-r run on start
-sfmt
simple format(stderr red)
-t string
trig one or more rules by name
e.g.: wtc -t ruleA
Expand Down
24 changes: 23 additions & 1 deletion pkg/wtc/wtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ var (
TypeFail = "\u001b[38;5;244m[{{.Time}}] \u001b[38;5;1m[{{.Title}}] \u001b[38;5;238m{{.Message}}\u001b[0m\n"
TypeCommandOK = "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[0m{{.Message}}\n"
TypeCommandErr = "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[38;5;1m{{.Message}}\u001b[0m\n"

SimpleTypeOK = "{{.Message}}\n"
SimpleTypeFail = "\u001b[38;5;238m{{.Message}}\u001b[0m\n"
SimpleTypeCommandOK = "\u001b[0m{{.Message}}\n"
SimpleTypeCommandErr = "\u001b[38;5;1m{{.Message}}\u001b[0m\n"
)

type Rune struct {
Expand Down Expand Up @@ -86,7 +91,7 @@ func ParseArgs() *Config {
flag.CommandLine.Output(),
"USAGE:\nwtc [[flags] [regex command]]\n"+
"\te.g.: wtc\n\t // will read [.]wtc.y[a]ml\n"+
"\te.g.: wtc \"_test\\.go$\" \"go test -cover {PKG}\"\n\n"+
"\te.g.: wtc -r -sfmt \"_test\\.go$\" \"go test -cover {PKG}\"\n\n"+
"wtc [flags]] [rule-name]\n\te.g.: wtc -t rule-name\n\t wtc --no-trace \"rule ruleb\"\n\t"+
" wtc -arg-pkg any/path rule\n\t"+
" wtc -arg-file path/to/file.ext rule\n"+
Expand Down Expand Up @@ -118,6 +123,12 @@ func ParseArgs() *Config {
flag.StringVar(&config.PkgArgument, "arg-pkg", "", "wtc -arg-pkg path/to/folder rule-name")
flag.StringVar(&config.FileArgument, "arg-file", "", "wtc -arg-file path/to/file rule-name")

var shouldRun bool
flag.BoolVar(&shouldRun, "r", false, "run on start")

var simpleFormat bool
flag.BoolVar(&simpleFormat, "sfmt", false, "simple format(stderr red)")

flag.Parse()

if raw := os.Getenv("WTC_IGNORE_RULES"); raw != "" {
Expand Down Expand Up @@ -146,6 +157,10 @@ func ParseArgs() *Config {
Match: flag.Arg(0),
Command: flag.Arg(1),
})

if shouldRun {
config.Trig = []string{"run"}
}
}

if trigs != "" {
Expand All @@ -172,6 +187,13 @@ func ParseArgs() *Config {
TimeFormat = config.Format.Time
}

if simpleFormat {
TypeOK = SimpleTypeOK
TypeFail = SimpleTypeFail
TypeCommandOK = SimpleTypeCommandOK
TypeCommandErr = SimpleTypeCommandErr
}

return config
}

Expand Down

0 comments on commit 67b0996

Please sign in to comment.