From abda2a4ae1c288456d7cda274b84bdab3fcd7be4 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Mon, 23 Dec 2019 18:18:21 -0500 Subject: [PATCH] Hide --tail argument altogether for Unix builds. This flag is hidden, but is only needed for Windows because on Unix OSes we can rely on the standard tail command. With this change, even with knowledge of the hidden --tail switch, termshark --tail=foo will not work except on Windows. --- cli/all.go | 8 ++++---- cli/flags.go | 14 +++++++++++--- cli/flags_windows.go | 16 ++++++++++++++-- cmd/termshark/termshark.go | 6 +++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/cli/all.go b/cli/all.go index 1104276..f1909ac 100644 --- a/cli/all.go +++ b/cli/all.go @@ -11,9 +11,9 @@ import "github.com/jessevdk/go-flags" // Used to determine if we should run tshark instead e.g. stdout is not a tty type Tshark struct { - PassThru string `long:"pass-thru" default:"auto" optional:"true" optional-value:"true" choice:"yes" choice:"no" choice:"auto" choice:"true" choice:"false" description:"Run tshark instead (auto => if stdout is not a tty)."` - PrintIfaces bool `short:"D" optional:"true" optional-value:"true" description:"Print a list of the interfaces on which termshark can capture."` - Tail flags.Filename `value-name:"" long:"tail" hidden:"true" description:"Tail a file (private)."` + PassThru string `long:"pass-thru" default:"auto" optional:"true" optional-value:"true" choice:"yes" choice:"no" choice:"auto" choice:"true" choice:"false" description:"Run tshark instead (auto => if stdout is not a tty)."` + PrintIfaces bool `short:"D" optional:"true" optional-value:"true" description:"Print a list of the interfaces on which termshark can capture."` + TailSwitch } // Termshark's own command line arguments. Used if we don't pass through to tshark. @@ -25,7 +25,7 @@ type Termshark struct { DisplayFilter string `short:"Y" description:"Apply display filter." value-name:""` 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:""` - PlatformSpecific + 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."` diff --git a/cli/flags.go b/cli/flags.go index 70f8195..c374b91 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -9,12 +9,20 @@ package cli //====================================================================== // Embedded in the CLI options struct. -type PlatformSpecific struct { +type PlatformSwitches struct { Tty string `long:"tty" description:"Display the UI on this terminal." value-name:""` } -func TtySwitchValue(opts *Termshark) string { - return opts.Tty +func (p PlatformSwitches) TtyValue() string { + return p.Tty +} + +//====================================================================== + +type TailSwitch struct{} + +func (t TailSwitch) TailFileValue() string { + return "" } //====================================================================== diff --git a/cli/flags_windows.go b/cli/flags_windows.go index d108bec..acfabbc 100644 --- a/cli/flags_windows.go +++ b/cli/flags_windows.go @@ -4,14 +4,26 @@ package cli +import "github.com/jessevdk/go-flags" + //====================================================================== -type PlatformSpecific struct{} +type PlatformSwitches struct{} -func TtySwitchValue(opts *Termshark) string { +func (p PlatformSwitches) TtyValue() string { return "" } +//====================================================================== + +type TailSwitch struct { + Tail flags.Filename `value-name:"" long:"tail" hidden:"true" description:"Tail a file (private)."` +} + +func (t TailSwitch) TailFileValue() string { + return string(t.Tail) +} + //====================================================================== // Local Variables: // mode: Go diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 364d415..aeb773c 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -134,8 +134,8 @@ func cmain() int { } } - if tsopts.Tail != "" { - err = termshark.TailFile(string(tsopts.Tail)) + if tsopts.TailFileValue() != "" { + err = termshark.TailFile(tsopts.TailFileValue()) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v", err) return 1 @@ -232,7 +232,7 @@ func cmain() int { return res } - usetty := cli.TtySwitchValue(&opts) + usetty := opts.TtyValue() if usetty != "" { if ttyf, err := os.Open(usetty); err != nil { fmt.Fprintf(os.Stderr, "Could not open terminal %s: %v.\n", usetty, err)