Skip to content

Commit

Permalink
chore: reduce stuttering in cmd pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed Feb 15, 2022
1 parent 3843c7e commit 26b1647
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
14 changes: 7 additions & 7 deletions cmd/apply/cmdapply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions cmd/destroy/cmddestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/diff/cmddiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
10 changes: 5 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions cmd/preview/cmdpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions cmd/status/cmdstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/status/cmdstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ metadata:
}
)

func TestStatusCommand(t *testing.T) {
func TestCommand(t *testing.T) {
testCases := map[string]struct {
pollUntil string
printer string
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 26b1647

Please sign in to comment.