mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
feat(GODT-2666): feat(GODT-2667): introduce sessionID in bridge.
This commit is contained in:
@ -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) })
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user