feat(GODT-2666): feat(GODT-2667): introduce sessionID in bridge.

This commit is contained in:
Xavier Michelon
2023-06-06 15:44:33 +02:00
parent 1e9a77c7b2
commit ac00ef1b64
24 changed files with 550 additions and 138 deletions

View File

@ -77,7 +77,7 @@ func (restarter *Restarter) Restart() {
//nolint:gosec
cmd := execabs.Command(
restarter.exe,
xslices.Join(removeFlagWithValue(removeFlag(os.Args[1:], "no-window"), "parent-pid"), restarter.flags)...,
xslices.Join(removeFlagsWithValue(removeFlag(os.Args[1:], "no-window"), "parent-pid", "session-id"), restarter.flags)...,
)
l := logrus.WithFields(logrus.Fields{
@ -157,6 +157,16 @@ func removeFlagWithValue(argList []string, flag string) []string {
return result
}
// removeFlagWithValue removes flags that require a value from a list of command line parameters.
// The flags can be of the following form `-flag value`, `--flag value`, `-flag=value` or `--flags=value`.
func removeFlagsWithValue(argList []string, flags ...string) []string {
for _, flag := range flags {
argList = removeFlagWithValue(argList, flag)
}
return argList
}
func removeFlag(argList []string, flag string) []string {
return xslices.Filter(argList, func(arg string) bool { return (arg != "-"+flag) && (arg != "--"+flag) })
}

View File

@ -42,6 +42,23 @@ func TestRemoveFlagWithValue(t *testing.T) {
}
}
func TestRemoveFlagsWithValue(t *testing.T) {
tests := []struct {
argList []string
flags []string
expected []string
}{
{[]string{}, []string{"a", "b"}, nil},
{[]string{"-a", "-b=value", "-c"}, []string{"b"}, []string{"-a", "-c"}},
{[]string{"-a", "--b=value", "-c"}, []string{"b", "c"}, []string{"-a"}},
{[]string{"-a", "-b", "value", "-c"}, []string{"c", "b"}, []string{"-a"}},
}
for _, tt := range tests {
require.Equal(t, removeFlagsWithValue(tt.argList, tt.flags...), tt.expected)
}
}
func TestRemoveFlag(t *testing.T) {
tests := []struct {
argList []string