The goal of this PR is to normalize the cli packages in a way that 1/ showcases clear ownership of data, 2/ minimizes package bloat, and 3/ helps avoid circular import issues. To achieve this, two primary changes were made. First, the cli/options package was folded into cli/utils, so that all "shared functionality" is owned by a single package. Second, all flag values, globals, declarations, and mutator funcs (in the cli layer, logging package was not changed) were extracted from cli/utils and placed into cli/flags. This divides ownership between the declaration and population of the flags (cli/flags) from the utilization of values derived from flags in command processing (cli/utils). This PR contains zero logical changes. Only code movement and renaming. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #3664 #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
41 lines
875 B
Go
41 lines
875 B
Go
package flags
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
UserFN = "user"
|
|
MailBoxFN = "mailbox"
|
|
)
|
|
|
|
var UserFV []string
|
|
|
|
// AddUserFlag adds the --user flag.
|
|
func AddUserFlag(cmd *cobra.Command) {
|
|
cmd.Flags().StringSliceVar(
|
|
&UserFV,
|
|
UserFN, nil,
|
|
"Backup a specific user's data; accepts '"+Wildcard+"' to select all users.")
|
|
cobra.CheckErr(cmd.MarkFlagRequired(UserFN))
|
|
}
|
|
|
|
// AddMailBoxFlag adds the --user and --mailbox flag.
|
|
func AddMailBoxFlag(cmd *cobra.Command) {
|
|
flags := cmd.Flags()
|
|
|
|
flags.StringSliceVar(
|
|
&UserFV,
|
|
UserFN, nil,
|
|
"Backup a specific user's data; accepts '"+Wildcard+"' to select all users.")
|
|
|
|
cobra.CheckErr(flags.MarkDeprecated(UserFN, fmt.Sprintf("use --%s instead", MailBoxFN)))
|
|
|
|
flags.StringSliceVar(
|
|
&UserFV,
|
|
MailBoxFN, nil,
|
|
"Backup a specific mailbox's data; accepts '"+Wildcard+"' to select all mailbox.")
|
|
}
|