From 26b16473c732dde29e40c2dbfd323f48bdb4c5f4 Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Wed, 9 Feb 2022 12:50:47 -0800 Subject: [PATCH] chore: reduce stuttering in cmd pkg --- cmd/apply/cmdapply.go | 14 +++++++------- cmd/destroy/cmddestroy.go | 20 ++++++++++---------- cmd/diff/cmddiff.go | 4 ++-- cmd/main.go | 10 +++++----- cmd/preview/cmdpreview.go | 20 ++++++++++---------- cmd/status/cmdstatus.go | 14 +++++++------- cmd/status/cmdstatus_test.go | 4 ++-- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/cmd/apply/cmdapply.go b/cmd/apply/cmdapply.go index 512525ee..0105a3b0 100644 --- a/cmd/apply/cmdapply.go +++ b/cmd/apply/cmdapply.go @@ -21,9 +21,9 @@ import ( "sigs.k8s.io/cli-utils/pkg/printers" ) -func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, - loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *ApplyRunner { - r := &ApplyRunner{ +func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, + loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner { + r := &Runner{ ioStreams: ioStreams, factory: factory, invFactory: invFactory, @@ -67,12 +67,12 @@ func GetApplyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClien 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 { - return GetApplyRunner(f, invFactory, loader, ioStreams).Command + return GetRunner(f, invFactory, loader, ioStreams).Command } -type ApplyRunner struct { +type Runner struct { Command *cobra.Command ioStreams genericclioptions.IOStreams factory cmdutil.Factory @@ -91,7 +91,7 @@ type ApplyRunner struct { 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() // If specified, cancel with timeout. if r.timeout != 0 { diff --git a/cmd/destroy/cmddestroy.go b/cmd/destroy/cmddestroy.go index 88f02c95..592f9f31 100644 --- a/cmd/destroy/cmddestroy.go +++ b/cmd/destroy/cmddestroy.go @@ -21,10 +21,10 @@ import ( "sigs.k8s.io/cli-utils/pkg/printers" ) -// GetDestroyRunner creates and returns the DestroyRunner which stores the cobra command. -func GetDestroyRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, - loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *DestroyRunner { - r := &DestroyRunner{ +// GetRunner creates and returns the Runner which stores the cobra command. +func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, + loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner { + r := &Runner{ ioStreams: ioStreams, factory: factory, invFactory: invFactory, @@ -55,14 +55,14 @@ func GetDestroyRunner(factory cmdutil.Factory, invFactory inventory.InventoryCli return r } -// DestroyCommand creates the DestroyRunner, returning the cobra command associated with it. -func DestroyCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, +// Command creates the Runner, returning the cobra command associated with it. +func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, 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. -type DestroyRunner struct { +// Runner encapsulates data necessary to run the destroy command. +type Runner struct { Command *cobra.Command ioStreams genericclioptions.IOStreams factory cmdutil.Factory @@ -77,7 +77,7 @@ type DestroyRunner struct { 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() // If specified, cancel with timeout. if r.timeout != 0 { diff --git a/cmd/diff/cmddiff.go b/cmd/diff/cmddiff.go index 8a5c4189..bd77bd4e 100644 --- a/cmd/diff/cmddiff.go +++ b/cmd/diff/cmddiff.go @@ -19,10 +19,10 @@ import ( 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 // 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) cmd := &cobra.Command{ Use: "diff (DIRECTORY | STDIN)", diff --git a/cmd/main.go b/cmd/main.go index ee1369f7..f7e476c3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -57,15 +57,15 @@ func main() { updateHelp(names, initCmd) loader := manifestreader.NewManifestLoader(f) invFactory := inventory.ClusterInventoryClientFactory{} - applyCmd := apply.ApplyCommand(f, invFactory, loader, ioStreams) + applyCmd := apply.Command(f, invFactory, loader, ioStreams) updateHelp(names, applyCmd) - previewCmd := preview.PreviewCommand(f, invFactory, loader, ioStreams) + previewCmd := preview.Command(f, invFactory, loader, ioStreams) updateHelp(names, previewCmd) - diffCmd := diff.NewCmdDiff(f, ioStreams) + diffCmd := diff.NewCommand(f, ioStreams) updateHelp(names, diffCmd) - destroyCmd := destroy.DestroyCommand(f, invFactory, loader, ioStreams) + destroyCmd := destroy.Command(f, invFactory, loader, ioStreams) updateHelp(names, destroyCmd) - statusCmd := status.StatusCommand(f, invFactory, loader) + statusCmd := status.Command(f, invFactory, loader) updateHelp(names, statusCmd) cmd.AddCommand(initCmd, applyCmd, diffCmd, destroyCmd, previewCmd, statusCmd) diff --git a/cmd/preview/cmdpreview.go b/cmd/preview/cmdpreview.go index 916239f1..5cd9faeb 100644 --- a/cmd/preview/cmdpreview.go +++ b/cmd/preview/cmdpreview.go @@ -27,10 +27,10 @@ var ( previewDestroy = false ) -// GetPreviewRunner creates and returns the PreviewRunner which stores the cobra command. -func GetPreviewRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, - loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *PreviewRunner { - r := &PreviewRunner{ +// GetRunner creates and returns the Runner which stores the cobra command. +func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, + loader manifestreader.ManifestLoader, ioStreams genericclioptions.IOStreams) *Runner { + r := &Runner{ factory: factory, invFactory: invFactory, loader: loader, @@ -64,14 +64,14 @@ func GetPreviewRunner(factory cmdutil.Factory, invFactory inventory.InventoryCli return r } -// PreviewCommand creates the PreviewRunner, returning the cobra command associated with it. -func PreviewCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, +// Command creates the Runner, returning the cobra command associated with it. +func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader, 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. -type PreviewRunner struct { +// Runner encapsulates data necessary to run the preview command. +type Runner struct { Command *cobra.Command factory cmdutil.Factory invFactory inventory.InventoryClientFactory @@ -85,7 +85,7 @@ type PreviewRunner struct { } // 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() // If specified, cancel with timeout. if r.timeout != 0 { diff --git a/cmd/status/cmdstatus.go b/cmd/status/cmdstatus.go index 0e781951..b76476d0 100644 --- a/cmd/status/cmdstatus.go +++ b/cmd/status/cmdstatus.go @@ -24,8 +24,8 @@ import ( "sigs.k8s.io/cli-utils/pkg/manifestreader" ) -func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *StatusRunner { - r := &StatusRunner{ +func GetRunner(factory cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *Runner { + r := &Runner{ factory: factory, invFactory: invFactory, loader: loader, @@ -47,13 +47,13 @@ func GetStatusRunner(factory cmdutil.Factory, invFactory inventory.InventoryClie return r } -func StatusCommand(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *cobra.Command { - return GetStatusRunner(f, invFactory, loader).Command +func Command(f cmdutil.Factory, invFactory inventory.InventoryClientFactory, loader manifestreader.ManifestLoader) *cobra.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. -type StatusRunner struct { +type Runner struct { Command *cobra.Command factory cmdutil.Factory invFactory inventory.InventoryClientFactory @@ -70,7 +70,7 @@ type StatusRunner struct { // 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 // 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) if err != nil { return err diff --git a/cmd/status/cmdstatus_test.go b/cmd/status/cmdstatus_test.go index 2365d0c2..e2dda881 100644 --- a/cmd/status/cmdstatus_test.go +++ b/cmd/status/cmdstatus_test.go @@ -53,7 +53,7 @@ metadata: } ) -func TestStatusCommand(t *testing.T) { +func TestCommand(t *testing.T) { testCases := map[string]struct { pollUntil string printer string @@ -219,7 +219,7 @@ deployment.apps/foo is InProgress: inProgress defer tf.Cleanup() loader := manifestreader.NewFakeLoader(tf, tc.inventory) - runner := &StatusRunner{ + runner := &Runner{ factory: tf, invFactory: inventory.FakeInventoryClientFactory(tc.inventory), loader: loader,