Skip to content

Commit

Permalink
tidy up suggests for config, add field defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
runz0rd committed Jan 26, 2023
1 parent 13c5e6b commit aa0ffc9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cmd/actions/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
if err != nil {
return err
}
if err := g.Patch(c.Repository, c.Image, c.Container, nil); err != nil {
if err := g.Patch(c.Image, c.Container, nil); err != nil {
return err
}
defer g.Rollback()
Expand Down
3 changes: 1 addition & 2 deletions cmd/actions/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&flagPod, "pod", "p", "", "pod name (default most recent one)")
rootCmd.PersistentFlags().StringVarP(&flagContainer, "container", "c", "", "container name (default deployment name)")
patchCmd.Flags().StringVar(&flagImage, "image", "alpine:latest", "image to be used for patching (default alpine:latest)")
patchCmd.Flags().StringVarP(&flagRepo, "repo", "r", "", "repository to be used for pushing patched image (default none)")
patchCmd.Flags().StringArrayVarP(&flagMounts, "mount", "m", []string{}, "host path to be mounted (default none)")
patchCmd.Flags().BoolVar(&flagRollback, "rollback", false, "rollback deployment to a previous state")
delveCmd.Flags().StringVar(&flagSourcePath, "source", "", ".go file source path (default cwd)")
Expand Down Expand Up @@ -79,7 +78,7 @@ var (
if err != nil {
return err
}
return grapple.Patch(flagRepo, flagImage, flagContainer, mounts)
return grapple.Patch(flagImage, flagContainer, mounts)
},
}
shellCmd = &cobra.Command{
Expand Down
29 changes: 4 additions & 25 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ type Config struct {
Namespace string `yaml:"namespace" depends:"Cluster"`
Deployment string `yaml:"deployment" depends:"Namespace"`
Container string `yaml:"container,omitempty" depends:"Deployment"`
Repository string `yaml:"repository,omitempty" depends:"Deployment"`
LaunchVscode bool `yaml:"launch_vscode"`
ListenAddr string `yaml:"listen_addr,omitempty"`
DelveContinue bool `yaml:"delve_continue"`
Image string `yaml:"image,omitempty"`
LaunchVscode bool `yaml:"launch_vscode" default:"false"`
ListenAddr string `yaml:"listen_addr,omitempty" default:":2345"`
DelveContinue bool `yaml:"delve_continue" default:"false"`
Image string `yaml:"image,omitempty" default:"alpine:latest"`
}

func (c Config) MarshalYAML() (interface{}, error) {
Expand Down Expand Up @@ -75,12 +74,6 @@ func (c Config) ContainerSuggest(d prompt.Document) []prompt.Suggest {
}))
}

func (c Config) RepositorySuggest(d prompt.Document) []prompt.Suggest {
return suggest.Completer(d, suggest.MustList(func() ([]string, error) {
return kubectl.ListRepositories(c.Namespace, c.Deployment)
}))
}

func (c Config) LaunchVscodeSuggest(d prompt.Document) []prompt.Suggest {
return []prompt.Suggest{{Text: "true"}, {Text: "false"}}
}
Expand All @@ -93,20 +86,6 @@ func (c Config) DelveContinueSuggest(d prompt.Document) []prompt.Suggest {
return []prompt.Suggest{{Text: "true"}, {Text: "false"}}
}

func (c Config) DockerfileSuggest(d prompt.Document) []prompt.Suggest {
completer := completer.FilePathCompleter{
IgnoreCase: true,
Filter: func(fi os.FileInfo) bool {
return fi.IsDir() || strings.Contains(fi.Name(), "Dockerfile")
},
}
return completer.Complete(d)
}

func (c Config) PlatformSuggest(d prompt.Document) []prompt.Suggest {
return []prompt.Suggest{{Text: "linux/amd64"}, {Text: "linux/arm64"}}
}

func (c Config) ImageSuggest(d prompt.Document) []prompt.Suggest {
suggestions := suggest.Completer(d, suggest.MustList(func() ([]string, error) {
return kubectl.ListImages(c.Namespace, c.Deployment)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-delve/delve v1.8.2
github.com/life4/genesis v1.0.3
github.com/pkg/errors v0.9.1
github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f
github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f h1:w9uHnUrlWShGgi/7Th1bQa59iJ40rFxD+P7lSZXUJq4=
github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f/go.mod h1:dKjHe/Q3Fjfv5PNg/ssEhKXlZR9zfl+K7uMk8SxdmKE=
github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194 h1:PNDnfufSiFUVszrE9blUjXN11Nc7c3lGOwJJPuNjKX4=
github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194/go.mod h1:dKjHe/Q3Fjfv5PNg/ssEhKXlZR9zfl+K7uMk8SxdmKE=
github.com/runz0rd/go-prompt v0.2.51 h1:XnDT/A+m/omQw4V91UcnywdmW+OXjf9ndsT3pe3e50s=
github.com/runz0rd/go-prompt v0.2.51/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
2 changes: 1 addition & 1 deletion patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g Grapple) newPatchValues(deployment, container, image string, mounts []Mo
}
}

func (g Grapple) Patch(repo, image, container string, mounts []Mount) error {
func (g Grapple) Patch(image, container string, mounts []Mount) error {
ctx := context.Background()
if g.isPatched() {
g.l.Warn("deployment already patched, rolling back first")
Expand Down
2 changes: 1 addition & 1 deletion patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGrapple_Patch(t *testing.T) {
g := testGrapple(t, "example")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := g.Patch(tt.args.repo, tt.args.dockerfile, tt.args.container, tt.args.mounts); (err != nil) != tt.wantErr {
if err := g.Patch(tt.args.dockerfile, tt.args.container, tt.args.mounts); (err != nil) != tt.wantErr {
t.Errorf("Grapple.Patch() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
9 changes: 9 additions & 0 deletions test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source_path: /Users/mpejanovic/Documents/dev/gograpple/test/app/main.go
cluster: k3d-local
namespace: default
deployment: example
container: example
launch_vscode: true
listen_addr: :2345
delve_continue: false
image: alpine:latest

0 comments on commit aa0ffc9

Please sign in to comment.