chore: reduce stuttering in cmd pkg

This commit is contained in:
Karl Isenberg 2022-02-09 12:50:47 -08:00
parent 3843c7e122
commit 26b16473c7
7 changed files with 43 additions and 43 deletions

View File

@ -21,9 +21,9 @@ import (
"sigs.k8s.io/cli-utils/pkg/printers" "sigs.k8s.io/cli-utils/pkg/printers"
) )
func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *ApplyRunner { loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner {
r := &ApplyRunner{ r := &Runner{
ioStreams: ioStreams, ioStreams: ioStreams,
factory: factory, factory: factory,
invFactory: invFactory, invFactory: invFactory,
@ -67,12 +67,12 @@ func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClien
return r return r
} }
func ApplyCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command { ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetApplyRunner(f, invFactory, loader, ioStreams).Command return GetRunner(f, invFactory, loader, ioStreams).Command
} }
type ApplyRunner struct { type Runner struct {
Command *cobra.Command Command *cobra.Command
ioStreams genericclioptions.IOStreams ioStreams genericclioptions.IOStreams
factory cmdutil.Factory factory cmdutil.Factory
@ -91,7 +91,7 @@ type ApplyRunner struct {
printStatusEvents bool printStatusEvents bool
} }
func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error { func (r *Runner) RunE(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
// If specified, cancel with timeout. // If specified, cancel with timeout.
if r.timeout != 0 { if r.timeout != 0 {

View File

@ -21,10 +21,10 @@ import (
"sigs.k8s.io/cli-utils/pkg/printers" "sigs.k8s.io/cli-utils/pkg/printers"
) )
// GetDestroyRunner creates and returns the DestroyRunner which stores the cobra command. // GetRunner creates and returns the Runner which stores the cobra command.
func GetDestroyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *DestroyRunner { loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner {
r := &DestroyRunner{ r := &Runner{
ioStreams: ioStreams, ioStreams: ioStreams,
factory: factory, factory: factory,
invFactory: invFactory, invFactory: invFactory,
@ -55,14 +55,14 @@ func GetDestroyRunner(factory cmdutil.Factory, invFactory inventory.InventoryCli
return r return r
} }
// DestroyCommand creates the DestroyRunner, returning the cobra command associated with it. // Command creates the Runner, returning the cobra command associated with it.
func DestroyCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command { ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetDestroyRunner(f, invFactory, loader, ioStreams).Command return GetRunner(f, invFactory, loader, ioStreams).Command
} }
// DestroyRunner encapsulates data necessary to run the destroy command. // Runner encapsulates data necessary to run the destroy command.
type DestroyRunner struct { type Runner struct {
Command *cobra.Command Command *cobra.Command
ioStreams genericclioptions.IOStreams ioStreams genericclioptions.IOStreams
factory cmdutil.Factory factory cmdutil.Factory
@ -77,7 +77,7 @@ type DestroyRunner struct {
printStatusEvents bool printStatusEvents bool
} }
func (r *DestroyRunner) RunE(cmd *cobra.Command, args []string) error { func (r *Runner) RunE(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
// If specified, cancel with timeout. // If specified, cancel with timeout.
if r.timeout != 0 { if r.timeout != 0 {

View File

@ -19,10 +19,10 @@ import (
const tmpDirPrefix = "diff-cmd" const tmpDirPrefix = "diff-cmd"
// NewCmdDiff returns cobra command to implement client-side diff of package // NewCommand returns cobra command to implement client-side diff of package
// directory. For each local config file, get the resource in the cluster // directory. For each local config file, get the resource in the cluster
// and diff the local config resource against the resource in the cluster. // and diff the local config resource against the resource in the cluster.
func NewCmdDiff(f util.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCommand(f util.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
options := diff.NewDiffOptions(ioStreams) options := diff.NewDiffOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "diff (DIRECTORY | STDIN)", Use: "diff (DIRECTORY | STDIN)",

View File

@ -57,15 +57,15 @@ func main() {
updateHelp(names, initCmd) updateHelp(names, initCmd)
loader := manifestreader.NewManifestLoader(f) loader := manifestreader.NewManifestLoader(f)
invFactory := inventory.ClusterInventoryClientFactory{} invFactory := inventory.ClusterInventoryClientFactory{}
applyCmd := apply.ApplyCommand(f, invFactory, loader, ioStreams) applyCmd := apply.Command(f, invFactory, loader, ioStreams)
updateHelp(names, applyCmd) updateHelp(names, applyCmd)
previewCmd := preview.PreviewCommand(f, invFactory, loader, ioStreams) previewCmd := preview.Command(f, invFactory, loader, ioStreams)
updateHelp(names, previewCmd) updateHelp(names, previewCmd)
diffCmd := diff.NewCmdDiff(f, ioStreams) diffCmd := diff.NewCommand(f, ioStreams)
updateHelp(names, diffCmd) updateHelp(names, diffCmd)
destroyCmd := destroy.DestroyCommand(f, invFactory, loader, ioStreams) destroyCmd := destroy.Command(f, invFactory, loader, ioStreams)
updateHelp(names, destroyCmd) updateHelp(names, destroyCmd)
statusCmd := status.StatusCommand(f, invFactory, loader) statusCmd := status.Command(f, invFactory, loader)
updateHelp(names, statusCmd) updateHelp(names, statusCmd)
cmd.AddCommand(initCmd, applyCmd, diffCmd, destroyCmd, previewCmd, statusCmd) cmd.AddCommand(initCmd, applyCmd, diffCmd, destroyCmd, previewCmd, statusCmd)

View File

@ -27,10 +27,10 @@ var (
previewDestroy = false previewDestroy = false
) )
// GetPreviewRunner creates and returns the PreviewRunner which stores the cobra command. // GetRunner creates and returns the Runner which stores the cobra command.
func GetPreviewRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory,
loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *PreviewRunner { loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner {
r := &PreviewRunner{ r := &Runner{
factory: factory, factory: factory,
invFactory: invFactory, invFactory: invFactory,
loader: loader, loader: loader,
@ -64,14 +64,14 @@ func GetPreviewRunner(factory cmdutil.Factory, invFactory inventory.InventoryCli
return r return r
} }
// PreviewCommand creates the PreviewRunner, returning the cobra command associated with it. // Command creates the Runner, returning the cobra command associated with it.
func PreviewCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader,
ioStreams genericclioptions.IOStreams) *cobra.Command { ioStreams genericclioptions.IOStreams) *cobra.Command {
return GetPreviewRunner(f, invFactory, loader, ioStreams).Command return GetRunner(f, invFactory, loader, ioStreams).Command
} }
// PreviewRunner encapsulates data necessary to run the preview command. // Runner encapsulates data necessary to run the preview command.
type PreviewRunner struct { type Runner struct {
Command *cobra.Command Command *cobra.Command
factory cmdutil.Factory factory cmdutil.Factory
invFactory inventory.InventoryClientFactory invFactory inventory.InventoryClientFactory
@ -85,7 +85,7 @@ type PreviewRunner struct {
} }
// RunE is the function run from the cobra command. // RunE is the function run from the cobra command.
func (r *PreviewRunner) RunE(cmd *cobra.Command, args []string) error { func (r *Runner) RunE(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
// If specified, cancel with timeout. // If specified, cancel with timeout.
if r.timeout != 0 { if r.timeout != 0 {

View File

@ -24,8 +24,8 @@ import (
"sigs.k8s.io/cli-utils/pkg/manifestreader" "sigs.k8s.io/cli-utils/pkg/manifestreader"
) )
func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *StatusRunner { func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *Runner {
r := &StatusRunner{ r := &Runner{
factory: factory, factory: factory,
invFactory: invFactory, invFactory: invFactory,
loader: loader, loader: loader,
@ -47,13 +47,13 @@ func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClie
return r return r
} }
func StatusCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *cobra.Command { func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *cobra.Command {
return GetStatusRunner(f, invFactory, loader).Command return GetRunner(f, invFactory, loader).Command
} }
// StatusRunner captures the parameters for the command and contains // Runner captures the parameters for the command and contains
// the run function. // the run function.
type StatusRunner struct { type Runner struct {
Command *cobra.Command Command *cobra.Command
factory cmdutil.Factory factory cmdutil.Factory
invFactory inventory.InventoryClientFactory invFactory inventory.InventoryClientFactory
@ -70,7 +70,7 @@ type StatusRunner struct {
// runE implements the logic of the command and will delegate to the // runE implements the logic of the command and will delegate to the
// poller to compute status for each of the resources. One of the printer // poller to compute status for each of the resources. One of the printer
// implementations takes care of printing the output. // implementations takes care of printing the output.
func (r *StatusRunner) runE(cmd *cobra.Command, args []string) error { func (r *Runner) runE(cmd *cobra.Command, args []string) error {
_, err := common.DemandOneDirectory(args) _, err := common.DemandOneDirectory(args)
if err != nil { if err != nil {
return err return err

View File

@ -53,7 +53,7 @@ metadata:
} }
) )
func TestStatusCommand(t *testing.T) { func TestCommand(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
pollUntil string pollUntil string
printer string printer string
@ -219,7 +219,7 @@ deployment.apps/foo is InProgress: inProgress
defer tf.Cleanup() defer tf.Cleanup()
loader := manifestreader.NewFakeLoader(tf, tc.inventory) loader := manifestreader.NewFakeLoader(tf, tc.inventory)
runner := &StatusRunner{ runner := &Runner{
factory: tf, factory: tf,
invFactory: inventory.FakeInventoryClientFactory(tc.inventory), invFactory: inventory.FakeInventoryClientFactory(tc.inventory),
loader: loader, loader: loader,