Translations for main.go, so mainly help
This commit is contained in:
parent
1419dbd75c
commit
82f308de93
|
@ -5,6 +5,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -17,9 +18,11 @@ import (
|
|||
|
||||
//_ "net/http/pprof"
|
||||
|
||||
jj "github.com/cloudfoundry-attic/jibber_jabber"
|
||||
ui "github.com/gizak/termui/v3"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/shibukawa/configdir"
|
||||
"github.com/xxxserxxx/lingo"
|
||||
"github.com/xxxserxxx/opflag"
|
||||
|
||||
"github.com/xxxserxxx/gotop/v4"
|
||||
|
@ -50,6 +53,7 @@ var (
|
|||
bar *w.StatusBar
|
||||
statusbar bool
|
||||
stderrLogger = log.New(os.Stderr, "", 0)
|
||||
tr lingo.Translations
|
||||
)
|
||||
|
||||
func parseArgs() error {
|
||||
|
@ -58,35 +62,27 @@ func parseArgs() error {
|
|||
for i, p := range cds {
|
||||
cpaths[i] = p.Path
|
||||
}
|
||||
help := opflag.BoolP("help", "h", false, "Show this screen.")
|
||||
color := opflag.StringP("color", "c", conf.Colorscheme.Name, "Set a colorscheme.")
|
||||
opflag.IntVarP(&conf.GraphHorizontalScale, "graphscale", "S", conf.GraphHorizontalScale, "Graph scale factor, >0")
|
||||
version := opflag.BoolP("version", "v", false, "Print version and exit.")
|
||||
versioN := opflag.BoolP("", "V", false, "Print version and exit.")
|
||||
opflag.BoolVarP(&conf.PercpuLoad, "percpu", "p", conf.PercpuLoad, "Show each CPU in the CPU widget.")
|
||||
opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, "Show average CPU in the CPU widget.")
|
||||
fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', "Show temperatures in fahrenheit.Show temperatures in fahrenheit.")
|
||||
opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, "Show a statusbar with the time.")
|
||||
opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, "Refresh frequency. Most time units accepted. `1m` = refresh every minute. `100ms` = refresh every 100ms.")
|
||||
opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, `Name of layout spec file for the UI. Use "-" to pipe.`)
|
||||
opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", "Select network interface. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using `!`")
|
||||
opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, "Enable metrics for export on the specified port.")
|
||||
opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, "Show network rate as mbps.")
|
||||
// FIXME Where did this go??
|
||||
//conf.Band = opflag.IntP("bandwidth", "B", 100, "Specify the number of bits per seconds.")
|
||||
opflag.BoolVar(&conf.Test, "test", conf.Test, "Runs tests and exits with success/failure code.")
|
||||
opflag.StringP("", "C", "", "Config file to use instead of default (MUST BE FIRST ARGUMENT)")
|
||||
list := opflag.String("list", "", `List <devices|layouts|colorschemes|paths|keys>
|
||||
devices: Prints out device names for filterable widgets
|
||||
layouts: Lists build-in layouts
|
||||
colorschemes: Lists built-in colorschemes
|
||||
paths: List out configuration file search paths
|
||||
widgets: Widgets that can be used in a layout
|
||||
keys: Show the keyboard bindings.`)
|
||||
wc := opflag.Bool("write-config", false, "Write out a default config file.")
|
||||
help := opflag.BoolP("help", "h", false, tr.Value("args.help"))
|
||||
color := opflag.StringP("color", "c", conf.Colorscheme.Name, tr.Value("args.color"))
|
||||
opflag.IntVarP(&conf.GraphHorizontalScale, "graphscale", "S", conf.GraphHorizontalScale, tr.Value("args.scale"))
|
||||
version := opflag.BoolP("version", "v", false, tr.Value("args.version"))
|
||||
versioN := opflag.BoolP("", "V", false, tr.Value("args.version"))
|
||||
opflag.BoolVarP(&conf.PercpuLoad, "percpu", "p", conf.PercpuLoad, tr.Value("args.percpu"))
|
||||
opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, tr.Value("args.cpuavg"))
|
||||
fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', tr.Value("args.temp"))
|
||||
opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, tr.Value("args.statusbar"))
|
||||
opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, tr.Value("args.rate"))
|
||||
opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, tr.Value("args.layout"))
|
||||
opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", tr.Value("args.net"))
|
||||
opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, tr.Value("args.export"))
|
||||
opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps"))
|
||||
opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test"))
|
||||
opflag.StringP("", "C", "", tr.Value("args.conffile"))
|
||||
list := opflag.String("list", "", tr.Value("args.list"))
|
||||
wc := opflag.Bool("write-config", false, tr.Value("args.write"))
|
||||
opflag.SortFlags = false
|
||||
opflag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\nOptions:\n", os.Args[0])
|
||||
fmt.Fprintf(os.Stderr, tr.Value("usage", os.Args[0]))
|
||||
opflag.PrintDefaults()
|
||||
}
|
||||
opflag.Parse()
|
||||
|
@ -115,13 +111,14 @@ func parseArgs() error {
|
|||
case "colorschemes":
|
||||
fmt.Println(_colorschemes)
|
||||
case "paths":
|
||||
fmt.Println("Loadable colorschemes & layouts, and the config file, are searched for, in order:")
|
||||
fmt.Println(tr.Value("help.paths"))
|
||||
paths := make([]string, 0)
|
||||
for _, d := range conf.ConfigDir.QueryFolders(configdir.All) {
|
||||
paths = append(paths, d.Path)
|
||||
}
|
||||
fmt.Println(strings.Join(paths, "\n"))
|
||||
fmt.Printf("\nThe log file is in %s\n", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE))
|
||||
fmt.Println()
|
||||
fmt.Println(tr.Value("help.log", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE)))
|
||||
case "devices":
|
||||
listDevices()
|
||||
case "keys":
|
||||
|
@ -129,7 +126,7 @@ func parseArgs() error {
|
|||
case "widgets":
|
||||
fmt.Println(_widgets)
|
||||
default:
|
||||
fmt.Printf("Unknown option \"%s\"; try layouts, colorschemes, keys, paths, or devices\n", *list)
|
||||
fmt.Printf(tr.Value("errors.unknownopt", *list))
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
@ -137,10 +134,10 @@ func parseArgs() error {
|
|||
if *wc {
|
||||
path, err := conf.Write()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to write configuration file: %s\n", err)
|
||||
fmt.Println(tr.Value("errors.writefail", err.Error()))
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Config written to %s\n", path)
|
||||
fmt.Println(tr.Value("help.written", path))
|
||||
os.Exit(0)
|
||||
}
|
||||
return nil
|
||||
|
@ -348,38 +345,53 @@ func main() {
|
|||
ec := run()
|
||||
if ec > 0 {
|
||||
if ec < 2 {
|
||||
fmt.Printf("errors encountered; check the log file %s\n", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE))
|
||||
logpath := filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE)
|
||||
fmt.Println(tr.Value("errors.checklog", logpath))
|
||||
fmt.Println(ioutil.ReadFile(logpath))
|
||||
}
|
||||
}
|
||||
os.Exit(ec)
|
||||
}
|
||||
|
||||
func run() int {
|
||||
ling, err := lingo.New("en_US", "translations", nil)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to load language files: %s\n", err)
|
||||
return 2
|
||||
}
|
||||
lang, err := jj.DetectIETF()
|
||||
if err != nil {
|
||||
fmt.Printf("failed to get language setting from environment: %s\n", err)
|
||||
return 2
|
||||
}
|
||||
lang = strings.Replace(lang, "-", "_", -1)
|
||||
// Get the locale from the os
|
||||
tr = ling.TranslationsForLocale(lang)
|
||||
conf = gotop.NewConfig()
|
||||
// Find the config file; look in (1) local, (2) user, (3) global
|
||||
// Check the last argument first
|
||||
fs := flag.NewFlagSet("config", flag.ContinueOnError)
|
||||
cfg := fs.String("C", "", "Config file")
|
||||
cfg := fs.String("C", "", tr.Value("configfile"))
|
||||
fs.SetOutput(bufio.NewWriter(nil))
|
||||
fs.Parse(os.Args[1:])
|
||||
if *cfg != "" {
|
||||
conf.ConfigFile = *cfg
|
||||
}
|
||||
err := conf.Load()
|
||||
err = conf.Load()
|
||||
if err != nil {
|
||||
fmt.Printf("failed to parse config file: %s\n", err)
|
||||
fmt.Println(tr.Value("errors.configparse", err.Error()))
|
||||
return 2
|
||||
}
|
||||
// Override with command line arguments
|
||||
err = parseArgs()
|
||||
if err != nil {
|
||||
fmt.Printf("parsing CLI args: %s\n", err)
|
||||
fmt.Println(tr.Value("errors.cliparse", err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
logfile, err := logging.New(conf)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to setup log file: %v\n", err)
|
||||
fmt.Println(tr.Value("logsetup", err.Error()))
|
||||
return 2
|
||||
}
|
||||
defer logfile.Close()
|
||||
|
|
2
go.mod
2
go.mod
|
@ -2,6 +2,7 @@ module github.com/xxxserxxx/gotop/v4
|
|||
|
||||
require (
|
||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
|
||||
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
||||
github.com/distatus/battery v0.9.0
|
||||
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815
|
||||
github.com/gizak/termui/v3 v3.0.0
|
||||
|
@ -14,6 +15,7 @@ require (
|
|||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/xxxserxxx/iSMC v1.0.1
|
||||
github.com/xxxserxxx/lingo v1.0.1
|
||||
github.com/xxxserxxx/opflag v1.0.5
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
|
||||
golang.org/x/tools v0.0.0-20200425043458-8463f397d07c // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -14,6 +14,8 @@ github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+
|
|||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd h1:XtfPmj9tQRilnrEmI1HjQhxXWRhEM+m8CACtaMJE/kM=
|
||||
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd/go.mod h1:vjcQJUZJYD3MeVGhtZXSMnCHfUNZxsyYzJt90eCYxK4=
|
||||
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 h1:Yg2hDs4b13Evkpj42FU2idX2cVXVFqQSheXYKM86Qsk=
|
||||
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21/go.mod h1:MgJyK38wkzZbiZSKeIeFankxxSA8gayko/nr5x5bgBA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -40,6 +42,8 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
|||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/jdkeke142/lingo-toml v0.0.0-20181017194727-b6051718cb18 h1:LBrIpegfXvxuUKys1QUbjkStyoQgOMocUu2MFcKXHek=
|
||||
github.com/jdkeke142/lingo-toml v0.0.0-20181017194727-b6051718cb18/go.mod h1:jOyiHA3tuXflvGIObzfVCShTPCceouP/e6aTo6fvi3s=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
|
@ -115,6 +119,10 @@ github.com/xxxserxxx/gotop/v3 v3.5.1 h1:aBf++Oxg7qCZpKqYpPPnXKFOxT1KYLPtiEXRh57y
|
|||
github.com/xxxserxxx/gotop/v3 v3.5.1/go.mod h1:DGPTiAmUhqE21xvokK64BuMxW+EmnOptaxpdOlqiH6s=
|
||||
github.com/xxxserxxx/iSMC v1.0.1 h1:M9Gkwnnkl+evvnugoB5yRYrbUP+cRIVOPM+xrHZc3Hs=
|
||||
github.com/xxxserxxx/iSMC v1.0.1/go.mod h1:TGgNjU7BF2DZSuxiTft+BdzxzcujFJYqFfMCzcTl/aY=
|
||||
github.com/xxxserxxx/lingo v1.0.1 h1:lPexOb0HEqYB50EaJdjaYFNATT8JhTcXljbQmCuXygE=
|
||||
github.com/xxxserxxx/lingo v1.0.1/go.mod h1:C2teIFiBLAmEhpLzRkwk7wP5R0eOoveXVYqD+5KOkAs=
|
||||
github.com/xxxserxxx/lingo-toml v0.0.0-20181017194727-b6051718cb18 h1:e00RDq5Gm5m22IuDG9/A7yF6AjAzoKbmQ+viQw5MUmI=
|
||||
github.com/xxxserxxx/lingo-toml v0.0.0-20181017194727-b6051718cb18/go.mod h1:QStBWvZx2oKk5HLYs3xrxAFvCdn8poBdB4uhZTF6yrw=
|
||||
github.com/xxxserxxx/opflag v1.0.0 h1:NabxbubvejqcdzQUHnsU8pBMAiWM+a/Rh2IJe56moiU=
|
||||
github.com/xxxserxxx/opflag v1.0.0/go.mod h1:Zf9bGkOcA35ypGfN25KX0iujVpZB5XwauEFjcfSKcBo=
|
||||
github.com/xxxserxxx/opflag v1.0.2 h1:TanW4Ck/RNal4fP2VVAvhEu7eBq4z+9hhGq9Q8OTq68=
|
||||
|
|
44
translations/de_DE.toml
Normal file
44
translations/de_DE.toml
Normal file
|
@ -0,0 +1,44 @@
|
|||
configfile="Config file"
|
||||
usage="Usage: {0} [options]\n\nOptions:\n"
|
||||
|
||||
|
||||
[help]
|
||||
paths="Loadable colorschemes & layouts, and the config file, are searched for, in order:"
|
||||
log="The log file is in {0}"
|
||||
written="Config written to {0}"
|
||||
|
||||
|
||||
[args]
|
||||
help="Hilfetext anzeigen."
|
||||
color="Ein Farbschema feststellen."
|
||||
scale="Stellen den Skalierungsfaktor ein, >0"
|
||||
version="Zeigen die Version aus und beenden."
|
||||
percpu="Show each CPU in the CPU widget."
|
||||
cpuavg="Show average CPU in the CPU widget."
|
||||
temp="Show temperatures in fahrenheit.Show temperatures in fahrenheit."
|
||||
statusbar="Show a statusbar with the time."
|
||||
rate="Refresh frequency. Most time units accepted. \"1m\" = refresh every minute. \"100ms\" = refresh every 100ms."
|
||||
layout="Name of layout spec file for the UI. Use \"-\" to pipe."
|
||||
net="Select network interface. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using \"!\""
|
||||
export="Enable metrics for export on the specified port."
|
||||
mbps="Show network rate as mbps."
|
||||
test="Runs tests and exits with success/failure code."
|
||||
conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)"
|
||||
list="""
|
||||
List <devices|layouts|colorschemes|paths|keys>
|
||||
devices: Prints out device names for filterable widgets
|
||||
layouts: Lists build-in layouts
|
||||
colorschemes: Lists built-in colorschemes
|
||||
paths: List out configuration file search paths
|
||||
widgets: Widgets that can be used in a layout
|
||||
keys: Show the keyboard bindings."""
|
||||
write="Write out a default config file."
|
||||
|
||||
|
||||
[errors]
|
||||
configparse="failed to parse config file: {0}"
|
||||
cliparse="parsing CLI args: {0}"
|
||||
logsetup="failed to setup log file: {0}"
|
||||
unknownopt="Unknown option \"{0}\"; try layouts, colorschemes, keys, paths, or devices\n"
|
||||
writefail="Failed to write configuration file: {0}"
|
||||
checklog="errors encountered; from {0}:"
|
44
translations/en_US.toml
Normal file
44
translations/en_US.toml
Normal file
|
@ -0,0 +1,44 @@
|
|||
configfile="Config file"
|
||||
usage="Usage: {0} [options]\n\nOptions:\n"
|
||||
|
||||
|
||||
[help]
|
||||
paths="Loadable colorschemes & layouts, and the config file, are searched for, in order:"
|
||||
log="The log file is in {0}"
|
||||
written="Config written to {0}"
|
||||
|
||||
|
||||
[args]
|
||||
help="Show this screen."
|
||||
color="Set a colorscheme."
|
||||
scale="Graph scale factor, >0"
|
||||
version="Print version and exit."
|
||||
percpu="Show each CPU in the CPU widget."
|
||||
cpuavg="Show average CPU in the CPU widget."
|
||||
temp="Show temperatures in fahrenheit.Show temperatures in fahrenheit."
|
||||
statusbar="Show a statusbar with the time."
|
||||
rate="Refresh frequency. Most time units accepted. \"1m\" = refresh every minute. \"100ms\" = refresh every 100ms."
|
||||
layout="Name of layout spec file for the UI. Use \"-\" to pipe."
|
||||
net="Select network interface. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using \"!\""
|
||||
export="Enable metrics for export on the specified port."
|
||||
mbps="Show network rate as mbps."
|
||||
test="Runs tests and exits with success/failure code."
|
||||
conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)"
|
||||
list="""
|
||||
List <devices|layouts|colorschemes|paths|keys>
|
||||
devices: Prints out device names for filterable widgets
|
||||
layouts: Lists build-in layouts
|
||||
colorschemes: Lists built-in colorschemes
|
||||
paths: List out configuration file search paths
|
||||
widgets: Widgets that can be used in a layout
|
||||
keys: Show the keyboard bindings."""
|
||||
write="Write out a default config file."
|
||||
|
||||
|
||||
[errors]
|
||||
configparse="failed to parse config file: {0}"
|
||||
cliparse="parsing CLI args: {0}"
|
||||
logsetup="failed to setup log file: {0}"
|
||||
unknownopt="Unknown option \"{0}\"; try layouts, colorschemes, keys, paths, or devices\n"
|
||||
writefail="Failed to write configuration file: {0}"
|
||||
checklog="errors encountered; from {0}:"
|
Loading…
Reference in New Issue
Block a user