-color more similar to grep
This commit is contained in:
parent
86243bf464
commit
ef4059c144
1 changed files with 36 additions and 9 deletions
|
@ -20,6 +20,39 @@ import (
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BoolAuto uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
BoolAuto_NO BoolAuto = iota
|
||||||
|
BoolAuto_YES BoolAuto = iota
|
||||||
|
BoolAuto_AUTO BoolAuto = iota
|
||||||
|
)
|
||||||
|
|
||||||
|
func (b *BoolAuto) String() string {
|
||||||
|
switch *b {
|
||||||
|
case BoolAuto_NO:
|
||||||
|
return "no"
|
||||||
|
case BoolAuto_YES:
|
||||||
|
return "always"
|
||||||
|
case BoolAuto_AUTO:
|
||||||
|
return "auto"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
func (b *BoolAuto) Set(s string) error {
|
||||||
|
switch s {
|
||||||
|
case "auto":
|
||||||
|
*b = BoolAuto_AUTO
|
||||||
|
case "always":
|
||||||
|
*b = BoolAuto_YES
|
||||||
|
case "no":
|
||||||
|
*b = BoolAuto_NO
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Invalid value %s", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("addr", "localhost:9080", "http service address")
|
addr := flag.String("addr", "localhost:9080", "http service address")
|
||||||
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
|
||||||
|
@ -27,17 +60,11 @@ func main() {
|
||||||
var filter filtering.ExprValue
|
var filter filtering.ExprValue
|
||||||
flag.Var(&filter, "where", "sql-like query to filter logs")
|
flag.Var(&filter, "where", "sql-like query to filter logs")
|
||||||
// TODO: change to color-mode=auto/no/always
|
// TODO: change to color-mode=auto/no/always
|
||||||
noColor := flag.Bool("no-color", false, "disable colors")
|
hasColor := BoolAuto_AUTO
|
||||||
forceColor := flag.Bool("force-color", false, "force colors even on TTY")
|
flag.Var(&hasColor, "color", "dis/enable colors")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *noColor && *forceColor {
|
if hasColor == BoolAuto_NO || (!isatty.IsTerminal(os.Stdout.Fd()) && hasColor != BoolAuto_YES) {
|
||||||
fmt.Fprintln(os.Stderr, "Can't use both -no-color and -force-color")
|
|
||||||
flag.Usage()
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *noColor || (!isatty.IsTerminal(os.Stdout.Fd()) && !*forceColor) {
|
|
||||||
ansi.DisableColors(true)
|
ansi.DisableColors(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue