Skip to content

Commit

Permalink
rename and lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
jklaw90 committed Jul 26, 2023
1 parent 33d9b4b commit b0a0dae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pod:
- |
Other Cool Dashboards:
- "https://example.com/dashboards/xyz1?name={.metadata.name}&namespace={.metadata.namespace}"
extraCommands:
commands:
meta:
kinds: ["*"]
urls:
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cmd

type Config struct {
KindAndTemplates KindAndTemplates `mapstructure:",remain"`
ExtraCommands map[string]ExtraCommand `yaml:"extraCommands"`
KindAndTemplates KindAndTemplates `mapstructure:",remain"`
Commands map[string]Command `yaml:"commands"`
}

type KindAndTemplates map[string]Tmpl

type ExtraCommand struct {
type Command struct {
Tmpl `mapstructure:",squash"`
Kinds []string `yaml:"kinds"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/k8url.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func initConfig() {
cobra.CheckErr(fmt.Errorf("failed to unmsrshal config: %s", err.Error()))
}

for k, v := range config.ExtraCommands {
for k, v := range config.Commands {
k, v := k, v
dynamicCmd := &cobra.Command{
Use: k,
Expand Down Expand Up @@ -106,7 +106,7 @@ func output(obj runtime.Object, templates []string, urlTemplates []string) {
// TODO cleanup - template will be a single string we need to split somehow...
allUrls := strings.Split(url, "https://")
for _, u := range allUrls {
browser.OpenURL(fmt.Sprintf("https://%s", u))
browser.OpenURL(fmt.Sprintf("https://%s", u)) // nolint: errcheck
}
}
}
23 changes: 5 additions & 18 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package parser

import (
"bytes"
"fmt"
"io"
"os"
"strings"

"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/util/jsonpath"
)

func Decode(reader io.Reader) (runtime.Object, string, error) {
Expand Down Expand Up @@ -44,25 +45,11 @@ func RenderTemplates(object runtime.Object, templates []string) ([]string, error
return nil, err
}
buf := new(bytes.Buffer)
p.PrintObj(object, buf)
if err := p.PrintObj(object, buf); err != nil {
fmt.Fprintf(os.Stderr, "error printing object: %v", err.Error())
}
resp = append(resp, buf.String())

}
return resp, nil
}

func Parse(template string, input interface{}) (string, error) {
j := jsonpath.New("").AllowMissingKeys(true)

if err := j.Parse(template); err != nil {
return "", err
}

buf := new(bytes.Buffer)
err := j.Execute(buf, input)
if err != nil {
return "", err
}

return buf.String(), nil
}
47 changes: 0 additions & 47 deletions pkg/parser/parser_test.go

This file was deleted.

0 comments on commit b0a0dae

Please sign in to comment.