Skip to content

Commit

Permalink
Hides -r messaging for shebang/main modes
Browse files Browse the repository at this point in the history
  • Loading branch information
TekWizely committed Nov 15, 2019
1 parent 8601c4b commit e1d952e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var EnableFnTrace = false
//
var ShowScriptFiles = false

// EnableRunfileOverride indicates if '-r | --runfile' arguments are supported in the current mode.
//
var EnableRunfileOverride = true

// TraceFn logs lexer transitions
//
func TraceFn(msg string, i interface{}) {
Expand Down
8 changes: 6 additions & 2 deletions internal/runfile/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,14 @@ func ListCommands() {
fmt.Fprintf(config.ErrOut, " %s%s %s\n", cmd.Name, strings.Repeat(" ", padLen-len(cmd.Name)), cmd.Title)
}
pad := strings.Repeat(" ", len(config.Me)-1)
runfileOpt := ""
if config.EnableRunfileOverride {
runfileOpt = "[-r runfile] "
}
fmt.Fprintf(config.ErrOut, "Usage:\n")
fmt.Fprintf(config.ErrOut, " %s [-r runfile] help <command>\n", config.Me)
fmt.Fprintf(config.ErrOut, " %s %shelp <command>\n", config.Me, runfileOpt)
fmt.Fprintf(config.ErrOut, " %s (show help for <command>)\n", pad)
fmt.Fprintf(config.ErrOut, " or %s [-r runfile] <command> [option ...]\n", config.Me)
fmt.Fprintf(config.ErrOut, " or %s %s<command> [option ...]\n", config.Me, runfileOpt)
fmt.Fprintf(config.ErrOut, " %s (run <command>)\n", pad)
}

Expand Down
19 changes: 13 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ var (
// showUsage exits with error code 2.
//
func showUsage() {
runfileOpt := ""
if config.EnableRunfileOverride {
runfileOpt = "[-r runfile] "
}
pad := strings.Repeat(" ", len(config.Me)-1)
fmt.Fprintf(config.ErrOut, "Usage:\n")
fmt.Fprintf(config.ErrOut, " %s -h | --help\n", config.Me)
fmt.Fprintf(config.ErrOut, " %s (show help)\n", pad)
fmt.Fprintf(config.ErrOut, " or %s [-r runfile] list\n", config.Me)
fmt.Fprintf(config.ErrOut, " or %s %slist\n", config.Me, runfileOpt)
fmt.Fprintf(config.ErrOut, " %s (list commands)\n", pad)
fmt.Fprintf(config.ErrOut, " or %s [-r runfile] help <command>\n", config.Me)
fmt.Fprintf(config.ErrOut, " or %s %shelp <command>\n", config.Me, runfileOpt)
fmt.Fprintf(config.ErrOut, " %s (show help for <command>)\n", pad)
fmt.Fprintf(config.ErrOut, " or %s [-r runfile] <command> [option ...]\n", config.Me)
fmt.Fprintf(config.ErrOut, " or %s %s<command> [option ...]\n", config.Me, runfileOpt)
fmt.Fprintf(config.ErrOut, " %s (run <command>)\n", pad)
fmt.Fprintln(config.ErrOut, "Options:")
fmt.Fprintln(config.ErrOut, " -h, --help")
fmt.Fprintln(config.ErrOut, " Show help screen")
fmt.Fprintln(config.ErrOut, " -r, --runfile <file>")
fmt.Fprintf(config.ErrOut, " Specify runfile (default='%s')\n", runfileDefault)
if config.EnableRunfileOverride {
fmt.Fprintln(config.ErrOut, " -r, --runfile <file>")
fmt.Fprintf(config.ErrOut, " Specify runfile (default='%s')\n", runfileDefault)
}
fmt.Fprintln(config.ErrOut, "Note:")
fmt.Fprintln(config.ErrOut, " Options accept '-' | '--'")
fmt.Fprintln(config.ErrOut, " Values can be given as:")
Expand Down Expand Up @@ -92,6 +98,7 @@ func main() {
if shebangMode {
config.Me = path.Base(shebangFile) // Script Name = executable Name for Help
inputFile = shebangFile // shebang file = runfile
config.EnableRunfileOverride = false
} else {
parseArgs()
}
Expand Down Expand Up @@ -200,7 +207,7 @@ func parseArgs() {
flag.BoolVar(&showHelp, "h", false, "")
// No -r/--runfile support in shebang mode
//
if !shebangMode {
if config.EnableRunfileOverride {
flag.StringVar(&inputFile, "runfile", runfileDefault, "")
flag.StringVar(&inputFile, "r", runfileDefault, "")
}
Expand Down

0 comments on commit e1d952e

Please sign in to comment.