Skip to content

Commit

Permalink
feat: make HalkyonEntity.Get actually return target, add GetTyped
Browse files Browse the repository at this point in the history
Fixes #82
  • Loading branch information
metacosm committed Mar 23, 2020
1 parent a0fd5ab commit b527994
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
5 changes: 2 additions & 3 deletions pkg/cmdutil/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"halkyon.io/hal/pkg/log"
"halkyon.io/hal/pkg/ui"
"halkyon.io/hal/pkg/validation"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record/util"
"os"
Expand Down Expand Up @@ -116,7 +115,7 @@ func (o *CreateOptions) Complete(name string, cmd *cobra.Command, args []string)
ui.OutputError(fmt.Sprintf("Invalid name: '%s', please select another one", o.Name))
o.Name = ""
}
err = o.Client.Get(o.Name, v1.GetOptions{})
_, err = o.Client.Get(o.Name)
if err != nil {
if util.IsKeyNotFoundError(errors.Cause(err)) {
break // resource is not found which is what we want
Expand All @@ -133,7 +132,7 @@ func (o *CreateOptions) Complete(name string, cmd *cobra.Command, args []string)
}

func (o *CreateOptions) Exists() (bool, error) {
err := o.Client.Get(o.Name, v1.GetOptions{})
_, err := o.Client.Get(o.Name)
if err != nil {
if util.IsKeyNotFoundError(errors.Cause(err)) {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (o *DeleteOptions) Complete(name string, cmd *cobra.Command, args []string)
func (o *DeleteOptions) Validate() error {
needName := len(o.Name) == 0
if !needName {
err := o.Client.Get(o.Name, v1.GetOptions{})
_, err := o.Client.Get(o.Name)
if err != nil {
if util.IsKeyNotFoundError(errors.Cause(err)) {
needName = true
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewGenericOperation(fullParentName string, o *GenericOperationOptions) *cob
}

type HalkyonEntity interface {
Get(string, v1.GetOptions) error
Get(name string) (runtime.Object, error)
Create(runtime.Object) error
Delete(string, *v1.DeleteOptions) error
GetKnown() ui.DisplayableMap
Expand Down
9 changes: 6 additions & 3 deletions pkg/hal/cli/capability/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ func (lc client) Create(toCreate runtime.Object) error {
return err
}

func (lc client) Get(name string, options v1.GetOptions) error {
_, err := lc.client.Get(name, options)
return err
func (lc client) Get(name string) (runtime.Object, error) {
return lc.GetTyped(name)
}

func (lc client) GetTyped(name string) (*v1beta12.Capability, error) {
return lc.client.Get(name, v1.GetOptions{})
}

func (lc client) GetKnown() ui.DisplayableMap {
Expand Down
9 changes: 6 additions & 3 deletions pkg/hal/cli/component/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ func (lc client) Create(toCreate runtime.Object) error {
return err
}

func (lc client) Get(name string, options v1.GetOptions) error {
_, err := lc.client.Get(name, options)
return err
func (lc client) Get(name string) (runtime.Object, error) {
return lc.GetTyped(name)
}

func (lc client) GetTyped(name string) (*v1beta12.Component, error) {
return lc.client.Get(name, v1.GetOptions{})
}

type displayableCapability struct {
Expand Down

0 comments on commit b527994

Please sign in to comment.