- Add no-x options to disable options
This commit is contained in:
mjshariati98 2022-02-04 18:16:58 +03:30
parent a32a1c05ea
commit c691514a41
3 changed files with 43 additions and 0 deletions

View File

@ -67,17 +67,23 @@ func parseArgs() error {
version := opflag.BoolP("version", "v", false, tr.Value("args.version")) version := opflag.BoolP("version", "v", false, tr.Value("args.version"))
versioN := opflag.BoolP("", "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.PercpuLoad, "percpu", "p", conf.PercpuLoad, tr.Value("args.percpu"))
opflag.BoolVar(&conf.NoPercpuLoad, "no-percpu", conf.NoPercpuLoad, tr.Value("args.no-percpu"))
opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, tr.Value("args.cpuavg")) opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, tr.Value("args.cpuavg"))
opflag.BoolVar(&conf.NoAverageLoad, "no-averagecpu", conf.NoAverageLoad, tr.Value("args.no-cpuavg"))
fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', tr.Value("args.temp")) 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.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, tr.Value("args.statusbar"))
opflag.BoolVar(&conf.NoStatusbar, "no-statusbar", conf.NoStatusbar, tr.Value("args.no-statusbar"))
opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, tr.Value("args.rate")) 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.Layout, "layout", "l", conf.Layout, tr.Value("args.layout"))
opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", tr.Value("args.net")) opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", tr.Value("args.net"))
opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, tr.Value("args.export")) opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, tr.Value("args.export"))
opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps")) opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps"))
opflag.BoolVar(&conf.NoMbps, "no-mbps", conf.NoMbps, tr.Value("args.no-mbps"))
opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test")) opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test"))
opflag.BoolVar(&conf.NoTest, "no-test", conf.NoTest, tr.Value("args.no-test"))
opflag.StringP("", "C", "", tr.Value("args.conffile")) opflag.StringP("", "C", "", tr.Value("args.conffile"))
opflag.BoolVarP(&conf.Nvidia, "nvidia", "", conf.Nvidia, "Enable NVidia GPU support") opflag.BoolVarP(&conf.Nvidia, "nvidia", "", conf.Nvidia, "Enable NVidia GPU support")
opflag.BoolVarP(&conf.NoNvidia, "no-nvidia", "", conf.NoNvidia, "Disable NVidia GPU support")
list := opflag.String("list", "", tr.Value("args.list")) list := opflag.String("list", "", tr.Value("args.list"))
wc := opflag.Bool("write-config", false, tr.Value("args.write")) wc := opflag.Bool("write-config", false, tr.Value("args.write"))
opflag.SortFlags = false opflag.SortFlags = false
@ -161,6 +167,26 @@ func parseArgs() error {
fmt.Println(tr.Value("help.written", path)) fmt.Println(tr.Value("help.written", path))
os.Exit(0) os.Exit(0)
} }
if conf.NoStatusbar {
conf.Statusbar = false
}
if conf.NoPercpuLoad {
conf.PercpuLoad = false
}
if conf.NoAverageLoad {
conf.AverageLoad = false
}
if conf.NoMbps {
conf.Mbps = false
}
if conf.NoTest {
conf.Test = false
}
if conf.NoNvidia {
conf.Nvidia = false
}
return nil return nil
} }

View File

@ -34,20 +34,26 @@ type Config struct {
Colorscheme colorschemes.Colorscheme Colorscheme colorschemes.Colorscheme
UpdateInterval time.Duration UpdateInterval time.Duration
AverageLoad bool AverageLoad bool
NoAverageLoad bool
PercpuLoad bool PercpuLoad bool
NoPercpuLoad bool
Statusbar bool Statusbar bool
NoStatusbar bool
TempScale widgets.TempScale TempScale widgets.TempScale
NetInterface string NetInterface string
Layout string Layout string
MaxLogSize int64 MaxLogSize int64
ExportPort string ExportPort string
Mbps bool Mbps bool
NoMbps bool
Temps []string Temps []string
Test bool Test bool
NoTest bool
ExtensionVars map[string]string ExtensionVars map[string]string
ConfigFile string ConfigFile string
Tr lingo.Translations Tr lingo.Translations
Nvidia bool Nvidia bool
NoNvidia bool
NvidiaRefresh time.Duration NvidiaRefresh time.Duration
} }
@ -61,9 +67,15 @@ func NewConfig() Config {
HelpVisible: false, HelpVisible: false,
UpdateInterval: time.Second, UpdateInterval: time.Second,
AverageLoad: false, AverageLoad: false,
NoAverageLoad: false,
PercpuLoad: true, PercpuLoad: true,
NoPercpuLoad: false,
TempScale: widgets.Celsius, TempScale: widgets.Celsius,
Statusbar: false, Statusbar: false,
NoStatusbar: false,
NoMbps: false,
NoTest: false,
NoNvidia: false,
NetInterface: widgets.NetInterfaceAll, NetInterface: widgets.NetInterfaceAll,
MaxLogSize: 5000000, MaxLogSize: 5000000,
Layout: "default", Layout: "default",

View File

@ -77,15 +77,20 @@ color="Set a colorscheme."
scale="Graph scale factor, >0" scale="Graph scale factor, >0"
version="Print version and exit." version="Print version and exit."
percpu="Show each CPU in the CPU widget." percpu="Show each CPU in the CPU widget."
no-percpu="Disable show each CPU in the CPU widget."
cpuavg="Show average CPU in the CPU widget." cpuavg="Show average CPU in the CPU widget."
no-cpuavg="Disable show average CPU in the CPU widget."
temp="Show temperatures in fahrenheit." temp="Show temperatures in fahrenheit."
statusbar="Show a statusbar with the time." statusbar="Show a statusbar with the time."
no-statusbar="Disable statusbar."
rate="Refresh frequency. Most time units accepted. \"1m\" = refresh every minute. \"100ms\" = refresh every 100ms." 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." 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 \"!\"" 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." export="Enable metrics for export on the specified port."
mbps="Show network rate as mbps." mbps="Show network rate as mbps."
no-mbps="Disable show network rate as mbps."
test="Runs tests and exits with success/failure code." test="Runs tests and exits with success/failure code."
no-test="Disable tests."
conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)" conffile="Config file to use instead of default (MUST BE FIRST ARGUMENT)"
nvidia="Enable NVidia GPU metrics" nvidia="Enable NVidia GPU metrics"
nvidiarefresh="Refresh frequency. Most time units accepted." nvidiarefresh="Refresh frequency. Most time units accepted."