Skip to content

Commit

Permalink
options and history tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
tedteng committed Jan 16, 2023
1 parent 03691e3 commit d688754
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
8 changes: 4 additions & 4 deletions pkg/cmd/env/templates/history.tmpl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{define "bash"}}
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | bash
{{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"}}
{{template "usage-hint" .__meta}}{{end}}

{{define "zsh"}}
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | zsh
{{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"}}
{{template "usage-hint" .__meta}}{{end}}

{{define "fish"}}
gardenctl target history | fzf --tac --no-sort --height 40% --layout reverse --info inline --border --preview 'echo {}' --preview-window up,1,border-horizontal | fish
{{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"}}
{{template "usage-hint" .__meta}}{{end}}

{{define "powershell"}}
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
{{"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" }}
{{template "usage-hint" .__meta}}{{end}}
20 changes: 8 additions & 12 deletions pkg/cmd/target/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ const (
)

// NewCmdHistory returns a new target history command
func NewCmdHistory(f util.Factory, o *HistoryOptions) *cobra.Command {
func NewCmdHistory(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &HistoryOptions{
Options: base.Options{
IOStreams: ioStreams,
},
}
cmd := &cobra.Command{
Use: "history",
Short: "Print the target history",
Expand All @@ -47,15 +52,6 @@ type HistoryWriteOptions struct {
path string
}

// NewHistoryOptions returns initialized HistoryOptions
func NewHistoryOptions(ioStreams util.IOStreams) *HistoryOptions {
return &HistoryOptions{
Options: base.Options{
IOStreams: ioStreams,
},
}
}

// NewHistoryWriteOptions returns initialized HistoryWriteOptions
func NewHistoryWriteOptions(ioStreams util.IOStreams) *HistoryWriteOptions {
return &HistoryWriteOptions{
Expand Down Expand Up @@ -147,12 +143,12 @@ func (o *HistoryWriteOptions) Run(f util.Factory) error {
return fmt.Errorf("failed to get current target: %w", err)
}

toCommand, err := toCommand(currentTarget)
command, err := toCommand(currentTarget)
if err != nil {
return err
}

return historyWrite(o.path, toCommand)
return historyWrite(o.path, command)
}

// Complete adapts from the command line args to the data required.
Expand Down
7 changes: 3 additions & 4 deletions pkg/cmd/target/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ var _ = Describe("history Command", func() {

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

Describe("#toCommand", func() {
It("should succeed execute history parse", func() {
string, err := cmdtarget.ToCommand(currentTarget)
currentTarget, err := cmdtarget.ToCommand(currentTarget)
Expect(err).NotTo(HaveOccurred())
Expect(string).Should((ContainSubstring("target --garden mygarden --project myproject --shoot myshoot")))
Expect(currentTarget).Should((ContainSubstring("target --garden mygarden --project myproject --shoot myshoot")))
})
})
})
2 changes: 1 addition & 1 deletion pkg/cmd/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ gardenctl target value/that/matches/pattern --control-plane`,

cmd.AddCommand(NewCmdUnset(f, ioStreams))
cmd.AddCommand(NewCmdView(f, ioStreams))
cmd.AddCommand(NewCmdHistory(f, o.Options))
cmd.AddCommand(NewCmdHistory(f, ioStreams))
o.AddFlags(cmd.Flags())

manager, err := f.Manager()
Expand Down

0 comments on commit d688754

Please sign in to comment.