Skip to content

Commit

Permalink
refactor: rename HalkyonEntityOptions to GenericOperationOptions
Browse files Browse the repository at this point in the history
Also simplify method names.
  • Loading branch information
metacosm committed Oct 7, 2019
1 parent 7c3f32e commit 1cf7fe0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pkg/cmdutil/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
const deleteCommandName = "delete"

type DeleteOptions struct {
*HalkyonEntityOptions
*GenericOperationOptions
}

func NewDeleteOptions(resourceType string, client HalkyonEntity) *DeleteOptions {
d := &DeleteOptions{}
d.HalkyonEntityOptions = &HalkyonEntityOptions{
d.GenericOperationOptions = &GenericOperationOptions{
ResourceType: resourceType,
Client: client,
operationName: deleteCommandName,
Expand Down Expand Up @@ -77,5 +77,5 @@ func (o *DeleteOptions) Run() error {
}

func NewGenericDelete(fullParentName string, o *DeleteOptions) *cobra.Command {
return NewGenericOperation(fullParentName, o.HalkyonEntityOptions)
return NewGenericOperation(fullParentName, o.GenericOperationOptions)
}
22 changes: 11 additions & 11 deletions pkg/cmdutil/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ import (
"strings"
)

type HalkyonEntityOptions struct {
type GenericOperationOptions struct {
ResourceType string
Name string
Client HalkyonEntity
operationName string
delegate Runnable
}

func (o *HalkyonEntityOptions) Complete(name string, cmd *cobra.Command, args []string) error {
func (o *GenericOperationOptions) Complete(name string, cmd *cobra.Command, args []string) error {
return o.delegate.Complete(name, cmd, args)
}

func (o *HalkyonEntityOptions) Validate() error {
func (o *GenericOperationOptions) Validate() error {
return o.delegate.Validate()
}

func (o *HalkyonEntityOptions) Run() error {
func (o *GenericOperationOptions) Run() error {
return o.delegate.Run()
}

func (o *HalkyonEntityOptions) genericExample(fullParentName string) string {
func (o *GenericOperationOptions) example(fullParentName string) string {
tmpl := ktemplates.Examples(` # %[1]s the %[2]s named 'foo'
%[3]s foo`)
return fmt.Sprintf(tmpl, strings.Title(o.operationName), o.ResourceType, CommandName(o.operationName, fullParentName))
}

func (o *HalkyonEntityOptions) genericUse() string {
func (o *GenericOperationOptions) use() string {
return fmt.Sprintf("%s <name of the %s to %s>", o.operationName, o.ResourceType, o.operationName)
}

func (o *HalkyonEntityOptions) genericShort() string {
func (o *GenericOperationOptions) short() string {
return fmt.Sprintf("%s the named %s", strings.Title(o.operationName), o.ResourceType)
}

func NewGenericOperation(fullParentName string, o *HalkyonEntityOptions) *cobra.Command {
func NewGenericOperation(fullParentName string, o *GenericOperationOptions) *cobra.Command {
cmd := &cobra.Command{
Use: o.genericUse(),
Short: o.genericUse(),
Example: o.genericExample(fullParentName),
Use: o.use(),
Short: o.short(),
Example: o.example(fullParentName),
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
GenericRun(o, cmd, args)
Expand Down

0 comments on commit 1cf7fe0

Please sign in to comment.