Allow multiple -command flags (#552)

This commit is contained in:
Marius authored and GitHub committed 2021-01-07 01:10:54 +03:00
1 parent b5f6f6edee
commit 8e09df5969
2 files changed
+16 -5

No files matched your search

+2 -2
View File
@@ -183,8 +183,8 @@ func (app *app) loop() {
} }
} }
if gCommand != "" { for _, cmd := range gCommands {
p := newParser(strings.NewReader(gCommand)) p := newParser(strings.NewReader(cmd))
for p.parse() { for p.parse() {
p.expr.eval(app, nil) p.expr.eval(app, nil)
+14 -3
View File
@@ -11,6 +11,7 @@ import (
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"strconv" "strconv"
"strings"
) )
var ( var (
@@ -18,6 +19,8 @@ var (
envLevel = os.Getenv("LF_LEVEL") envLevel = os.Getenv("LF_LEVEL")
) )
type arrayFlag []string
var ( var (
gClientID int gClientID int
gHostname string gHostname string
@@ -28,10 +31,19 @@ var (
gLogPath string gLogPath string
gServerLogPath string gServerLogPath string
gSelect string gSelect string
gCommand string gCommands arrayFlag
gVersion string gVersion string
) )
func (a *arrayFlag) Set(v string) error {
*a = append(*a, v)
return nil
}
func (a *arrayFlag) String() string {
return strings.Join(*a, ", ")
}
func init() { func init() {
h, err := os.Hostname() h, err := os.Hostname()
if err != nil { if err != nil {
@@ -205,9 +217,8 @@ func main() {
"", "",
"path to the file to write selected files on open (to use as open file dialog)") "path to the file to write selected files on open (to use as open file dialog)")
flag.StringVar(&gCommand, flag.Var(&gCommands,
"command", "command",
"",
"command to execute on client initialization") "command to execute on client initialization")
flag.Parse() flag.Parse()