Skip to content

Commit d688754

Browse files
committed
options and history tmpl
1 parent 03691e3 commit d688754

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

pkg/cmd/env/templates/history.tmpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{{define "bash"}}
2-
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | bash
2+
{{template "eval-cmd" dict "shell" .shell "cmd" "gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal"}}
33
{{template "usage-hint" .__meta}}{{end}}
44

55
{{define "zsh"}}
6-
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | zsh
6+
{{template "eval-cmd" dict "shell" .shell "cmd" "gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal"}}
77
{{template "usage-hint" .__meta}}{{end}}
88

99
{{define "fish"}}
10-
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | fish
10+
{{template "eval-cmd" dict "shell" .shell "cmd" "gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal"}}
1111
{{template "usage-hint" .__meta}}{{end}}
1212

1313
{{define "powershell"}}
14-
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | Out-String | Invoke-Expression
14+
{{"gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | Out-String | Invoke-Expression" }}
1515
{{template "usage-hint" .__meta}}{{end}}

pkg/cmd/target/history.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ const (
2323
)
2424

2525
// NewCmdHistory returns a new target history command
26-
func NewCmdHistory(f util.Factory, o *HistoryOptions) *cobra.Command {
26+
func NewCmdHistory(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
27+
o := &HistoryOptions{
28+
Options: base.Options{
29+
IOStreams: ioStreams,
30+
},
31+
}
2732
cmd := &cobra.Command{
2833
Use: "history",
2934
Short: "Print the target history",
@@ -47,15 +52,6 @@ type HistoryWriteOptions struct {
4752
path string
4853
}
4954

50-
// NewHistoryOptions returns initialized HistoryOptions
51-
func NewHistoryOptions(ioStreams util.IOStreams) *HistoryOptions {
52-
return &HistoryOptions{
53-
Options: base.Options{
54-
IOStreams: ioStreams,
55-
},
56-
}
57-
}
58-
5955
// NewHistoryWriteOptions returns initialized HistoryWriteOptions
6056
func NewHistoryWriteOptions(ioStreams util.IOStreams) *HistoryWriteOptions {
6157
return &HistoryWriteOptions{
@@ -147,12 +143,12 @@ func (o *HistoryWriteOptions) Run(f util.Factory) error {
147143
return fmt.Errorf("failed to get current target: %w", err)
148144
}
149145

150-
toCommand, err := toCommand(currentTarget)
146+
command, err := toCommand(currentTarget)
151147
if err != nil {
152148
return err
153149
}
154150

155-
return historyWrite(o.path, toCommand)
151+
return historyWrite(o.path, command)
156152
}
157153

158154
// Complete adapts from the command line args to the data required.

pkg/cmd/target/history_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ var _ = Describe("history Command", func() {
7373

7474
Describe("#ToHistoryOutput", func() {
7575
It("should print history output from command level", func() {
76-
o := cmdtarget.NewHistoryOptions(streams)
77-
cmd := cmdtarget.NewCmdHistory(factory, o)
76+
cmd := cmdtarget.NewCmdHistory(factory, streams)
7877
Expect(cmd.RunE(cmd, nil)).To(Succeed())
7978
Expect(out.String()).Should(ContainSubstring("target --garden mygarden --project myproject --shoot myshoot"))
8079
})
8180
})
8281

8382
Describe("#toCommand", func() {
8483
It("should succeed execute history parse", func() {
85-
string, err := cmdtarget.ToCommand(currentTarget)
84+
currentTarget, err := cmdtarget.ToCommand(currentTarget)
8685
Expect(err).NotTo(HaveOccurred())
87-
Expect(string).Should((ContainSubstring("target --garden mygarden --project myproject --shoot myshoot")))
86+
Expect(currentTarget).Should((ContainSubstring("target --garden mygarden --project myproject --shoot myshoot")))
8887
})
8988
})
9089
})

pkg/cmd/target/target.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ gardenctl target value/that/matches/pattern --control-plane`,
5151

5252
cmd.AddCommand(NewCmdUnset(f, ioStreams))
5353
cmd.AddCommand(NewCmdView(f, ioStreams))
54-
cmd.AddCommand(NewCmdHistory(f, o.Options))
54+
cmd.AddCommand(NewCmdHistory(f, ioStreams))
5555
o.AddFlags(cmd.Flags())
5656

5757
manager, err := f.Manager()

0 commit comments

Comments
 (0)