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 Nov 9, 2022
1 parent 825da9f commit c01507a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 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
3 changes: 1 addition & 2 deletions pkg/cmd/target/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ 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"))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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())

return cmd
Expand Down

0 comments on commit c01507a

Please sign in to comment.