From f3cc19b09ca81bab236960858a485e69c375b085 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Wed, 30 Nov 2022 19:03:35 +0100 Subject: [PATCH] GODT-2150: fixed initial implementation that filtered --no-window in gui instead of bridge. --- .../bridge-gui/bridge-gui/CommandLine.cpp | 2 +- pkg/restarter/restarter.go | 6 +++++- pkg/restarter/restarter_test.go | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp b/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp index 431b3ae1..7aca050a 100644 --- a/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/CommandLine.cpp @@ -108,7 +108,7 @@ void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QStrin { outNoWindow = true; } - else if (arg == launcherFlag) + if (arg == launcherFlag) { args.append(arg); launcher = QString::fromLocal8Bit(argv[++i]); diff --git a/pkg/restarter/restarter.go b/pkg/restarter/restarter.go index 07918795..98d9e7a6 100644 --- a/pkg/restarter/restarter.go +++ b/pkg/restarter/restarter.go @@ -77,7 +77,7 @@ func (restarter *Restarter) Restart() { //nolint:gosec cmd := execabs.Command( restarter.exe, - xslices.Join(removeFlagWithValue(os.Args[1:], "parent-pid"), restarter.flags)..., + xslices.Join(removeFlagWithValue(removeFlag(os.Args[1:], "no-window"), "parent-pid"), restarter.flags)..., ) l := logrus.WithFields(logrus.Fields{ @@ -156,3 +156,7 @@ func removeFlagWithValue(argList []string, flag string) []string { return result } + +func removeFlag(argList []string, flag string) []string { + return xslices.Filter(argList, func(arg string) bool { return (arg != "-"+flag) && (arg != "--"+flag) }) +} diff --git a/pkg/restarter/restarter_test.go b/pkg/restarter/restarter_test.go index dc1e6be3..0a5dd7db 100644 --- a/pkg/restarter/restarter_test.go +++ b/pkg/restarter/restarter_test.go @@ -41,3 +41,20 @@ func TestRemoveFlagWithValue(t *testing.T) { require.Equal(t, removeFlagWithValue(tt.argList, tt.flag), tt.expected) } } + +func TestRemoveFlag(t *testing.T) { + tests := []struct { + argList []string + flag string + expected []string + }{ + {[]string{}, "b", []string{}}, + {[]string{"-a", "-b", "-c"}, "b", []string{"-a", "-c"}}, + {[]string{"-a", "--b", "-b"}, "b", []string{"-a"}}, + {[]string{"-a", "-c"}, "b", []string{"-a", "-c"}}, + } + + for _, tt := range tests { + require.Equal(t, removeFlag(tt.argList, tt.flag), tt.expected) + } +}