diff --git a/cli/all.go b/cli/all.go index a248e9a..50e356f 100644 --- a/cli/all.go +++ b/cli/all.go @@ -26,11 +26,11 @@ type Termshark struct { CaptureFilter string `short:"f" description:"Apply capture filter." value-name:""` TimestampFormat string `short:"t" description:"Set the format of the packet timestamp printed in summary lines." choice:"a" choice:"ad" choice:"adoy" choice:"d" choice:"dd" choice:"e" choice:"r" choice:"u" choice:"ud" choice:"udoy" value-name:""` PlatformSwitches - PassThru string `long:"pass-thru" default:"auto" optional:"true" optional-value:"true" choice:"auto" choice:"true" choice:"false" description:"Run tshark instead (auto => if stdout is not a tty)."` - LogTty bool `long:"log-tty" optional:"true" optional-value:"true" choice:"true" choice:"false" description:"Log to the terminal."` - Debug string `long:"debug" default:"false" hidden:"true" optional:"true" optional-value:"true" choice:"true" choice:"false" description:"Enable termshark debugging. See https://termshark.io/userguide."` - Help bool `long:"help" short:"h" optional:"true" optional-value:"true" description:"Show this help message."` - Version []bool `long:"version" short:"v" optional:"true" optional-value:"true" description:"Show version information."` + PassThru string `long:"pass-thru" default:"auto" optional:"true" optional-value:"true" choice:"auto" choice:"true" choice:"false" description:"Run tshark instead (auto => if stdout is not a tty)."` + LogTty bool `long:"log-tty" optional:"true" optional-value:"true" choice:"true" choice:"false" description:"Log to the terminal."` + Debug TriState `long:"debug" default:"unset" hidden:"true" optional:"true" optional-value:"true" description:"Enable termshark debugging. See https://termshark.io/userguide."` + Help bool `long:"help" short:"h" optional:"true" optional-value:"true" description:"Show this help message."` + Version []bool `long:"version" short:"v" optional:"true" optional-value:"true" description:"Show version information."` Args struct { FilterOrPcap string `value-name:"" description:"Filter (capture for iface, display for pcap), or pcap to read."` diff --git a/cli/tristate.go b/cli/tristate.go new file mode 100644 index 0000000..a4ee789 --- /dev/null +++ b/cli/tristate.go @@ -0,0 +1,45 @@ +// Copyright 2019-2020 Graham Clark. All rights reserved. Use of this source +// code is governed by the MIT license that can be found in the LICENSE +// file. +// + +package cli + +//====================================================================== + +type TriState struct { + Set bool + Val bool +} + +func (b *TriState) UnmarshalFlag(value string) error { + switch value { + case "true", "TRUE", "t", "T", "1", "y", "Y", "yes", "Yes", "YES": + b.Set = true + b.Val = true + case "false", "FALSE", "f", "F", "0", "n", "N", "no", "No", "NO": + b.Set = true + b.Val = false + default: + b.Set = false + } + return nil +} + +func (b TriState) MarshalFlag() string { + if b.Set { + if b.Val { + return "true" + } else { + return "false" + } + } else { + return "unset" + } +} + +//====================================================================== +// Local Variables: +// mode: Go +// fill-column: 78 +// End: diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index beb589c..f12301d 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -271,6 +271,7 @@ func cmain() int { // terminal emumlator supports 256 colors. termVar := termshark.ConfString("main.term", "") if termVar != "" { + log.Infof("Configuration file overrides TERM setting, using TERM=%s", termVar) os.Setenv("TERM", termVar) } @@ -468,7 +469,12 @@ func cmain() int { log.SetOutput(logfd) } - if cli.FlagIsTrue(opts.Debug) { + debug := false + if (opts.Debug.Set && opts.Debug.Val == true) || (!opts.Debug.Set && termshark.ConfBool("main.debug", false)) { + debug = true + } + + if debug { for _, addr := range termshark.LocalIPs() { log.Infof("Starting debug web server at http://%s:6060/debug/pprof/", addr) } @@ -1134,14 +1140,14 @@ Loop: uiSuspended = false } } else if system.IsSigUSR1(sig) { - if cli.FlagIsTrue(opts.Debug) { + if debug { termshark.ProfileCPUFor(20) } else { log.Infof("SIGUSR1 ignored by termshark - see the --debug flag") } } else if system.IsSigUSR2(sig) { - if cli.FlagIsTrue(opts.Debug) { + if debug { termshark.ProfileHeap() } else { log.Infof("SIGUSR2 ignored by termshark - see the --debug flag")