From b95238708b244e6b15b1a67c7e03a33ad00521b9 Mon Sep 17 00:00:00 2001 From: Ted Teng Date: Thu, 27 Oct 2022 09:18:52 +0800 Subject: [PATCH] options and history tmpl --- pkg/cmd/env/templates/history.tmpl | 8 ++++---- pkg/cmd/target/history.go | 20 ++++++++------------ pkg/cmd/target/history_test.go | 3 +-- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pkg/cmd/env/templates/history.tmpl b/pkg/cmd/env/templates/history.tmpl index d94cc43d..caa86bcd 100644 --- a/pkg/cmd/env/templates/history.tmpl +++ b/pkg/cmd/env/templates/history.tmpl @@ -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}} \ No newline at end of file diff --git a/pkg/cmd/target/history.go b/pkg/cmd/target/history.go index e1ba3fdf..992c81bf 100644 --- a/pkg/cmd/target/history.go +++ b/pkg/cmd/target/history.go @@ -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", @@ -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{ @@ -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. diff --git a/pkg/cmd/target/history_test.go b/pkg/cmd/target/history_test.go index a11cfc41..ed678658 100644 --- a/pkg/cmd/target/history_test.go +++ b/pkg/cmd/target/history_test.go @@ -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")) })