mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
all: do not print usage info for all the flags when incorrect command-line flag is passed
This should improve usability for VictoriaMetrics apps that have big number of command-line flags, i.e. all the apps.
This commit is contained in:
parent
66379cc69f
commit
9d787f9edd
7 changed files with 48 additions and 21 deletions
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
||||||
graphiteserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/graphite"
|
graphiteserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/graphite"
|
||||||
influxserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/influx"
|
influxserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/influx"
|
||||||
|
@ -275,8 +276,5 @@ vmagent collects metrics data via popular data ingestion protocols and routes it
|
||||||
|
|
||||||
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmagent/README.md .
|
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmagent/README.md .
|
||||||
`
|
`
|
||||||
|
flagutil.Usage(s)
|
||||||
f := flag.CommandLine.Output()
|
|
||||||
fmt.Fprintf(f, "%s\n", s)
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,8 +219,5 @@ vmalert processes alerts and recording rules.
|
||||||
|
|
||||||
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md .
|
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md .
|
||||||
`
|
`
|
||||||
|
flagutil.Usage(s)
|
||||||
f := flag.CommandLine.Output()
|
|
||||||
fmt.Fprintf(f, "%s\n", s)
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -12,6 +11,7 @@ import (
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
|
||||||
|
@ -100,8 +100,5 @@ vmauth authenticates and authorizes incoming requests and proxies them to Victor
|
||||||
|
|
||||||
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmauth/README.md .
|
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmauth/README.md .
|
||||||
`
|
`
|
||||||
|
flagutil.Usage(s)
|
||||||
f := flag.CommandLine.Output()
|
|
||||||
fmt.Fprintf(f, "%s\n", s)
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,10 +103,7 @@ or local filesystem. Backed up data can be restored with vmrestore.
|
||||||
|
|
||||||
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmbackup/README.md .
|
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmbackup/README.md .
|
||||||
`
|
`
|
||||||
|
flagutil.Usage(s)
|
||||||
f := flag.CommandLine.Output()
|
|
||||||
fmt.Fprintf(f, "%s\n", s)
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSrcFS() (*fslocal.FS, error) {
|
func newSrcFS() (*fslocal.FS, error) {
|
||||||
|
|
|
@ -62,10 +62,7 @@ vmrestore restores VictoriaMetrics data from backups made by vmbackup.
|
||||||
|
|
||||||
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmrestore/README.md .
|
See the docs at https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmrestore/README.md .
|
||||||
`
|
`
|
||||||
|
flagutil.Usage(s)
|
||||||
f := flag.CommandLine.Output()
|
|
||||||
fmt.Fprintf(f, "%s\n", s)
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDstFS() (*fslocal.FS, error) {
|
func newDstFS() (*fslocal.FS, error) {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* FEATURE: optimize Consul service discovery speed when discovering big number of services. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/574
|
* FEATURE: optimize Consul service discovery speed when discovering big number of services. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/574
|
||||||
* FEATURE: add `label_uppercase(q, label1, ... labelN)` and `label_lowercase(q, label1, ... labelN)` function to [MetricsQL](https://victoriametrics.github.io/MetricsQL.html)
|
* FEATURE: add `label_uppercase(q, label1, ... labelN)` and `label_lowercase(q, label1, ... labelN)` function to [MetricsQL](https://victoriametrics.github.io/MetricsQL.html)
|
||||||
for uppercasing and lowercasing values for the given labels. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/936
|
for uppercasing and lowercasing values for the given labels. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/936
|
||||||
|
* FEATURE: do not print usage info for all the command-line flags when incorrect command-line flag is passed. Previously it could be hard reading the error message
|
||||||
|
about incorrect command-line flag because of too big usage info for all the flags.
|
||||||
|
|
||||||
* BUGFIX: properly parse timestamps in OpenMetrics format - they are exposed as floating-point number in seconds instead of integer milliseconds
|
* BUGFIX: properly parse timestamps in OpenMetrics format - they are exposed as floating-point number in seconds instead of integer milliseconds
|
||||||
unlike in Prometheus exposition format. See [the docs](https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md#timestamps).
|
unlike in Prometheus exposition format. See [the docs](https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md#timestamps).
|
||||||
|
|
39
lib/flagutil/usage.go
Normal file
39
lib/flagutil/usage.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package flagutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Usage prints s and optional description for all the flags if -h or -help flag is passed to the app.
|
||||||
|
func Usage(s string) {
|
||||||
|
f := flag.CommandLine.Output()
|
||||||
|
fmt.Fprintf(f, "%s\n", s)
|
||||||
|
if hasHelpFlag(os.Args[1:]) {
|
||||||
|
flag.PrintDefaults()
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(f, `Run "%s -help" in order to see the description for all the available flags`+"\n", os.Args[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasHelpFlag(args []string) bool {
|
||||||
|
for _, arg := range args {
|
||||||
|
if isHelpArg(arg) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isHelpArg(arg string) bool {
|
||||||
|
if !strings.HasPrefix(arg, "-") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
arg = arg[1:]
|
||||||
|
if strings.HasPrefix(arg, "-") {
|
||||||
|
arg = arg[1:]
|
||||||
|
}
|
||||||
|
return arg == "h" || arg == "help"
|
||||||
|
}
|
Loading…
Reference in a new issue