mirror of https://github.com/fluxcd/cli-utils.git
chore: reduce stuttering in cmd pkg
This commit is contained in:
parent
3843c7e122
commit
26b16473c7
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)",
|
||||
|
|
|
|||
10
cmd/main.go
10
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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue