Skip to content

Commit

Permalink
Hide --tail argument altogether for Unix builds.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gcla committed Dec 23, 2019
1 parent c39f55a commit abda2a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cli/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"<tail-file>" 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.
Expand All @@ -25,7 25,7 @@ type Termshark struct {
DisplayFilter string `short:"Y" description:"Apply display filter." value-name:"<displaY filter>"`
CaptureFilter string `short:"f" description:"Apply capture filter." value-name:"<capture filter>"`
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:"<timestamp format>"`
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."`
Expand Down
14 changes: 11 additions & 3 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"<tty>"`
}

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 ""
}

//======================================================================
Expand Down
16 changes: 14 additions & 2 deletions cli/flags_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"<tail-file>" long:"tail" hidden:"true" description:"Tail a file (private)."`
}

func (t TailSwitch) TailFileValue() string {
return string(t.Tail)
}

//======================================================================
// Local Variables:
// mode: Go
Expand Down
6 changes: 3 additions & 3 deletions cmd/termshark/termshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit abda2a4

Please sign in to comment.