Skip to content

Commit

Permalink
move inventory-policy flags and values to package level constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Jan 27, 2021
1 parent b62349a commit 4efc889
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/apply/cmdapply.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func GetApplyRunner(provider provider.Provider, loader manifestreader.ManifestLo
"Background", "Propagation policy for pruning")
cmd.Flags().DurationVar(&r.pruneTimeout, "prune-timeout", time.Duration(0),
"Timeout threshold for waiting for all pruned resources to be deleted")
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
"It determines the behavior when the resources don't belong to current inventory. Available options "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))

r.Command = cmd
return r
Expand Down
4 changes: 2 additions & 2 deletions cmd/destroy/cmddestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func GetDestroyRunner(provider provider.Provider, loader manifestreader.Manifest

cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
"It determines the behavior when the resources don't belong to current inventory. Available options "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))

r.Command = cmd
return r
Expand Down
10 changes: 8 additions & 2 deletions cmd/flagutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import (
"sigs.k8s.io/cli-utils/pkg/inventory"
)

const (
InventoryPolicyFlag = "inventory-policy"
InventoryPolicyStrict = "strict"
InventoryPolicyAdopt = "adopt"
)

func ConvertInventoryPolicy(policy string) (inventory.InventoryPolicy, error) {
switch policy {
case "strict":
case InventoryPolicyStrict:
return inventory.InventoryPolicyMustMatch, nil
case "adopt":
case InventoryPolicyAdopt:
return inventory.AdoptIfNoInventory, nil
default:
return inventory.InventoryPolicyMustMatch, fmt.Errorf(
Expand Down
4 changes: 2 additions & 2 deletions cmd/preview/cmdpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func GetPreviewRunner(provider provider.Provider, loader manifestreader.Manifest
cmd.Flags().BoolVar(&previewDestroy, "destroy", previewDestroy, "If true, preview of destroy operations will be displayed.")
cmd.Flags().StringVar(&r.output, "output", printers.DefaultPrinter(),
fmt.Sprintf("Output format, must be one of %s", strings.Join(printers.SupportedPrinters(), ",")))
cmd.Flags().StringVar(&r.inventoryPolicy, "inventory-policy", "strict",
cmd.Flags().StringVar(&r.inventoryPolicy, flagutils.InventoryPolicyFlag, flagutils.InventoryPolicyStrict,
"It determines the behavior when the resources don't belong to current inventory. Available options "+
"\"strict\" and \"adopt\".")
fmt.Sprintf("%q and %q.", flagutils.InventoryPolicyStrict, flagutils.InventoryPolicyAdopt))

r.Command = cmd
return r
Expand Down

0 comments on commit 4efc889

Please sign in to comment.