Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target history feature #162

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/help/gardenctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Find more information at: https://github.com/gardener/gardenctl-v2/blob/master/R
### SEE ALSO

* [gardenctl config](gardenctl_config.md) - Modify gardenctl configuration file using subcommands
* [gardenctl history-env](gardenctl_history-env.md) - Generate a script Fuzzy search the target history
* [gardenctl kubeconfig](gardenctl_kubeconfig.md) - Print the kubeconfig for the current target
* [gardenctl kubectl-env](gardenctl_kubectl-env.md) - Generate a script that points KUBECONFIG to the targeted cluster for the specified shell
* [gardenctl provider-env](gardenctl_provider-env.md) - Generate the cloud provider CLI configuration script for the specified shell
Expand Down
50 changes: 50 additions & 0 deletions docs/help/gardenctl_history-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## gardenctl history-env

Generate a script Fuzzy search the target history

### Synopsis

Generate a script Fuzzy search the target history

The fuzzy finder must be installed.
Please refer to the installation instructions of the 3rd party tools:
* fuzzy finder - https://github.com/junegunn/fzf,

Generate a script that fuzzy search the target history for the specified shell.
See each sub-command's help for details on how to use the generated script.



### Options

```
-h, --help help for history-env
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl](gardenctl.md) - Gardenctl is a utility to interact with Gardener installations
* [gardenctl history-env bash](gardenctl_history-env_bash.md) - Generate a script that fuzzy search the target history for bash
* [gardenctl history-env fish](gardenctl_history-env_fish.md) - Generate a script that fuzzy search the target history for fish
* [gardenctl history-env powershell](gardenctl_history-env_powershell.md) - Generate a script that fuzzy search the target history for powershell
* [gardenctl history-env zsh](gardenctl_history-env_zsh.md) - Generate a script that fuzzy search the target history for zsh

45 changes: 45 additions & 0 deletions docs/help/gardenctl_history-env_bash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## gardenctl history-env bash

Generate a script that fuzzy search the target history for bash

### Synopsis

Generate a script that fuzzy search the target history for bash.

To load the fuzzy search the target history script in your current shell session:
$ eval "$(gardenctl history-env bash)"


```
gardenctl history-env bash [flags]
```

### Options

```
-h, --help help for bash
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl history-env](gardenctl_history-env.md) - Generate a script Fuzzy search the target history

45 changes: 45 additions & 0 deletions docs/help/gardenctl_history-env_fish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## gardenctl history-env fish

Generate a script that fuzzy search the target history for fish

### Synopsis

Generate a script that fuzzy search the target history for fish.

To load the fuzzy search the target history script in your current shell session:
$ eval (gardenctl history-env fish)


```
gardenctl history-env fish [flags]
```

### Options

```
-h, --help help for fish
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl history-env](gardenctl_history-env.md) - Generate a script Fuzzy search the target history

45 changes: 45 additions & 0 deletions docs/help/gardenctl_history-env_powershell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## gardenctl history-env powershell

Generate a script that fuzzy search the target history for powershell

### Synopsis

Generate a script that fuzzy search the target history for powershell.

To load the fuzzy search the target history script in your current shell session:
PS /> & gardenctl history-env powershell | Invoke-Expression


```
gardenctl history-env powershell [flags]
```

### Options

```
-h, --help help for powershell
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl history-env](gardenctl_history-env.md) - Generate a script Fuzzy search the target history

45 changes: 45 additions & 0 deletions docs/help/gardenctl_history-env_zsh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## gardenctl history-env zsh

Generate a script that fuzzy search the target history for zsh

### Synopsis

Generate a script that fuzzy search the target history for zsh.

To load the fuzzy search the target history script in your current shell session:
$ eval "$(gardenctl history-env zsh)"


```
gardenctl history-env zsh [flags]
```

### Options

```
-h, --help help for zsh
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl history-env](gardenctl_history-env.md) - Generate a script Fuzzy search the target history

1 change: 1 addition & 0 deletions docs/help/gardenctl_target.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ gardenctl target value/that/matches/pattern --control-plane
* [gardenctl](gardenctl.md) - Gardenctl is a utility to interact with Gardener installations
* [gardenctl target control-plane](gardenctl_target_control-plane.md) - Target the control plane of the shoot
* [gardenctl target garden](gardenctl_target_garden.md) - Target a garden
* [gardenctl target history](gardenctl_target_history.md) - Print the target history
* [gardenctl target project](gardenctl_target_project.md) - Target a project
* [gardenctl target seed](gardenctl_target_seed.md) - Target a seed
* [gardenctl target shoot](gardenctl_target_shoot.md) - Target a shoot
Expand Down
46 changes: 46 additions & 0 deletions docs/help/gardenctl_target_history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## gardenctl target history

Print the target history

### Synopsis

Print the target history

```
gardenctl target history [flags]
```

### Options

```
-h, --help help for history
```

### Options inherited from parent commands

```
--add-dir-header If true, adds the file directory to the header of the log messages
--alsologtostderr log to standard error as well as files (no effect when -logtostderr=true)
--config string config file (default is ~/.garden/gardenctl-v2.yaml)
--control-plane target control plane of shoot, use together with shoot argument
--garden string target the given garden cluster
--log-backtrace-at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log-dir string If non-empty, write log files in this directory (no effect when -logtostderr=true)
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--logtostderr log to standard error instead of files (default true)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--project string target the given project
--seed string target the given seed cluster
--shoot string target the given shoot cluster
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
--stderrthreshold severity logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=false) (default 2)
-v, --v Level number for the log level verbosity
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO

* [gardenctl target](gardenctl_target.md) - Set scope for next operations, using subcommands or pattern

1 change: 1 addition & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Find more information at: https://github.com/gardener/gardenctl-v2/blob/master/R
cmd.AddCommand(cmdconfig.NewCmdConfig(f, ioStreams))
cmd.AddCommand(cmdenv.NewCmdProviderEnv(f, ioStreams))
cmd.AddCommand(cmdenv.NewCmdKubectlEnv(f, ioStreams))
cmd.AddCommand(cmdenv.NewCmdHistoryEnv(f, ioStreams))
cmd.AddCommand(cmdenv.NewCmdRC(f, ioStreams))
cmd.AddCommand(kubeconfig.NewCmdKubeconfig(f, ioStreams))

Expand Down
40 changes: 40 additions & 0 deletions pkg/cmd/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,43 @@ The generated script points the KUBECONFIG environment variable to the currently

return cmd
}

// NewCmdHistoryEnv returns a new history-env command.
func NewCmdHistoryEnv(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &options{
Options: base.Options{
IOStreams: ioStreams,
},
ProviderType: "history",
}
runE := base.WrapRunE(o, f)
cmd := &cobra.Command{
Use: "history-env",
Short: "Generate a script Fuzzy search the target history",
Long: `Generate a script Fuzzy search the target history

The fuzzy finder must be installed.
Please refer to the installation instructions of the 3rd party tools:
* fuzzy finder - https://github.com/junegunn/fzf,

Generate a script that fuzzy search the target history for the specified shell.
See each sub-command's help for details on how to use the generated script.

`,
DisableFlagParsing: true,
}

for _, s := range validShells {
cmd.AddCommand(&cobra.Command{
Use: string(s),
Short: fmt.Sprintf("Generate a script that fuzzy search the target history for %s", s),
Long: fmt.Sprintf("Generate a script that fuzzy search the target history for %s.\n\n"+
"To load the fuzzy search the target history script in your current shell session:\n%s\n",
s, s.Prompt(runtime.GOOS)+s.EvalCommand(fmt.Sprintf("%s %s %s", "gardenctl", cmd.Use, s)),
),
RunE: runE,
})
}

return cmd
}
17 changes: 17 additions & 0 deletions pkg/cmd/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@ var _ = Describe("Env Commands", func() {
}
})
})

Describe("given a HistoryEnv instance", func() {
BeforeEach(func() {
cmd = env.NewCmdHistoryEnv(factory, streams)
})

It("should have Use, Flags and SubCommands", func() {
Expect(cmd.Use).To(Equal("history-env"))
Expect(cmd.Flag("output")).To(BeNil())
subCmds := cmd.Commands()
Expect(len(subCmds)).To(Equal(4))
for _, c := range subCmds {
s := env.Shell(c.Name())
Expect(s).To(BeElementOf(env.ValidShells))
}
})
})
})
Loading