From 1661bad61b77dc84f2e6cd4b781937afac78163d Mon Sep 17 00:00:00 2001 From: Zeu Capua Date: Wed, 25 Sep 2024 15:38:08 -0700 Subject: [PATCH] remove users by email working --- cmd/offboard/offboard.go | 2 +- cmd/offboard/output.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/offboard/offboard.go b/cmd/offboard/offboard.go index ccb5fac..354a03b 100644 --- a/cmd/offboard/offboard.go +++ b/cmd/offboard/offboard.go @@ -34,7 +34,7 @@ func NewConfigCommand() *cobra.Command { Long: offboardLongDesc, Args: func(_ *cobra.Command, args []string) error { if !(len(args) > 0) { - errors.New("you must provide at least one argument: the offboarding user's email/username") + return errors.New("you must provide at least one argument: the offboarding user's email/username") } opts.offboardingUsers = args diff --git a/cmd/offboard/output.go b/cmd/offboard/output.go index f076838..3563f98 100644 --- a/cmd/offboard/output.go +++ b/cmd/offboard/output.go @@ -63,11 +63,14 @@ func generateOwnersFile(path string, offboardingUsers []string) error { lines := strings.Split(string(owners), "\n") var newLines []string for _, line := range lines { - var result string + newLine := line for _, name := range offboardingUsers { - result, _, _ = strings.Cut(line, "@"+name) + result, _, found := strings.Cut(newLine, "@"+name) + if found { + newLine = result + } } - newLines = append(newLines, result) + newLines = append(newLines, newLine) } output := strings.Join(newLines, "\n")