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
114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
package flags
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const (
|
|
LibraryFN = "library"
|
|
ListFolderFN = "list"
|
|
ListItemFN = "list-item"
|
|
PageFolderFN = "page-folder"
|
|
PageFN = "page"
|
|
SiteFN = "site" // site only accepts WebURL values
|
|
SiteIDFN = "site-id" // site-id accepts actual site ids
|
|
)
|
|
|
|
var (
|
|
LibraryFV string
|
|
ListFolderFV []string
|
|
ListItemFV []string
|
|
PageFolderFV []string
|
|
PageFV []string
|
|
SiteIDFV []string
|
|
WebURLFV []string
|
|
)
|
|
|
|
// AddSharePointDetailsAndRestoreFlags adds flags that are common to both the
|
|
// details and restore commands.
|
|
func AddSharePointDetailsAndRestoreFlags(cmd *cobra.Command) {
|
|
fs := cmd.Flags()
|
|
|
|
// libraries
|
|
|
|
fs.StringVar(
|
|
&LibraryFV,
|
|
LibraryFN, "",
|
|
"Select only this library; defaults to all libraries.")
|
|
fs.StringSliceVar(
|
|
&FolderPathFV,
|
|
FolderFN, nil,
|
|
"Select by folder; defaults to root.")
|
|
fs.StringSliceVar(
|
|
&FileNameFV,
|
|
FileFN, nil,
|
|
"Select by file name.")
|
|
fs.StringVar(
|
|
&FileCreatedAfterFV,
|
|
FileCreatedAfterFN, "",
|
|
"Select files created after this datetime.")
|
|
fs.StringVar(
|
|
&FileCreatedBeforeFV,
|
|
FileCreatedBeforeFN, "",
|
|
"Select files created before this datetime.")
|
|
fs.StringVar(
|
|
&FileModifiedAfterFV,
|
|
FileModifiedAfterFN, "",
|
|
"Select files modified after this datetime.")
|
|
fs.StringVar(
|
|
&FileModifiedBeforeFV,
|
|
FileModifiedBeforeFN, "",
|
|
"Select files modified before this datetime.")
|
|
|
|
// lists
|
|
|
|
fs.StringSliceVar(
|
|
&ListFolderFV,
|
|
ListFolderFN, nil,
|
|
"Select lists by name; accepts '"+Wildcard+"' to select all lists.")
|
|
cobra.CheckErr(fs.MarkHidden(ListFolderFN))
|
|
fs.StringSliceVar(
|
|
&ListItemFV,
|
|
ListItemFN, nil,
|
|
"Select lists by item name; accepts '"+Wildcard+"' to select all lists.")
|
|
cobra.CheckErr(fs.MarkHidden(ListItemFN))
|
|
|
|
// pages
|
|
|
|
fs.StringSliceVar(
|
|
&PageFolderFV,
|
|
PageFolderFN, nil,
|
|
"Select pages by folder name; accepts '"+Wildcard+"' to select all pages.")
|
|
cobra.CheckErr(fs.MarkHidden(PageFolderFN))
|
|
fs.StringSliceVar(
|
|
&PageFV,
|
|
PageFN, nil,
|
|
"Select pages by item name; accepts '"+Wildcard+"' to select all pages.")
|
|
cobra.CheckErr(fs.MarkHidden(PageFN))
|
|
}
|
|
|
|
// AddSiteIDFlag adds the --site-id flag, which accepts site ID values.
|
|
// This flag is hidden, since we expect users to prefer the --site url
|
|
// and do not want to encourage confusion.
|
|
func AddSiteIDFlag(cmd *cobra.Command) {
|
|
fs := cmd.Flags()
|
|
|
|
// note string ARRAY var. IDs naturally contain commas, so we cannot accept
|
|
// duplicate values within a flag declaration. ie: --site-id a,b,c does not
|
|
// work. Users must call --site-id a --site-id b --site-id c.
|
|
fs.StringArrayVar(
|
|
&SiteIDFV,
|
|
SiteIDFN, nil,
|
|
//nolint:lll
|
|
"Backup data by site ID; accepts '"+Wildcard+"' to select all sites. Args cannot be comma-delimited and must use multiple flags.")
|
|
cobra.CheckErr(fs.MarkHidden(SiteIDFN))
|
|
}
|
|
|
|
// AddSiteFlag adds the --site flag, which accepts webURL values.
|
|
func AddSiteFlag(cmd *cobra.Command) {
|
|
cmd.Flags().StringSliceVar(
|
|
&WebURLFV,
|
|
SiteFN, nil,
|
|
"Backup data by site URL; accepts '"+Wildcard+"' to select all sites.")
|
|
}
|