Skip to content

Commit

Permalink
enh: target cmd - only register target flags with higher specificty
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-petersen committed Jan 17, 2023
1 parent 740e73e commit 0276ae2
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 47 deletions.
12 changes: 5 additions & 7 deletions docs/help/gardenctl_target_control-plane.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ gardenctl target control-plane --garden my-garden --project my-project --shoot m
### Options

```
-h, --help help for control-plane
-o, --output string One of 'yaml' or 'json'.
--garden string target the given garden cluster
-h, --help help for control-plane
-o, --output string One of 'yaml' or 'json'.
--project string target the given project
--shoot string target the given shoot cluster
```

### Options inherited from parent commands
Expand All @@ -33,17 +36,12 @@ gardenctl target control-plane --garden my-garden --project my-project --shoot m
--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)
Expand Down
5 changes: 0 additions & 5 deletions docs/help/gardenctl_target_garden.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ gardenctl target garden my-garden
--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)
Expand Down
6 changes: 1 addition & 5 deletions docs/help/gardenctl_target_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gardenctl target project my-project --garden my-garden
### Options

```
--garden string target the given garden cluster
-h, --help help for project
-o, --output string One of 'yaml' or 'json'.
```
Expand All @@ -33,17 +34,12 @@ gardenctl target project my-project --garden my-garden
--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)
Expand Down
6 changes: 1 addition & 5 deletions docs/help/gardenctl_target_seed.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gardenctl target seed my-seed --garden my-garden
### Options

```
--garden string target the given garden cluster
-h, --help help for seed
-o, --output string One of 'yaml' or 'json'.
```
Expand All @@ -33,17 +34,12 @@ gardenctl target seed my-seed --garden my-garden
--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)
Expand Down
12 changes: 5 additions & 7 deletions docs/help/gardenctl_target_shoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ gardenctl target shoot my-shoot --garden my-garden --project my-project
### Options

```
-h, --help help for shoot
-o, --output string One of 'yaml' or 'json'.
--garden string target the given garden cluster
-h, --help help for shoot
-o, --output string One of 'yaml' or 'json'.
--project string target the given project
--seed string target the given seed cluster
```

### Options inherited from parent commands
Expand All @@ -33,17 +36,12 @@ gardenctl target shoot my-shoot --garden my-garden --project my-project
--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)
Expand Down
5 changes: 0 additions & 5 deletions docs/help/gardenctl_target_unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ gardenctl target unset garden
--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)
Expand Down
5 changes: 0 additions & 5 deletions docs/help/gardenctl_target_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ gardenctl target view [flags]
--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)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/target/control-plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package target

import (
"github.com/spf13/cobra"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/gardener/gardenctl-v2/internal/util"
"github.com/gardener/gardenctl-v2/pkg/cmd/base"
"github.com/gardener/gardenctl-v2/pkg/flags"
)

// NewCmdTargetControlPlane returns a new target control plane command.
Expand All @@ -36,5 +38,13 @@ gardenctl target control-plane --garden my-garden --project my-project --shoot m

o.AddFlags(cmd.Flags())

manager, err := f.Manager()
utilruntime.Must(err)
manager.TargetFlags().AddGardenFlag(cmd.Flags())
manager.TargetFlags().AddProjectFlag(cmd.Flags())
manager.TargetFlags().AddShootFlag(cmd.Flags())
manager.TargetFlags().AddSeedFlag(cmd.Flags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.Flags())

return cmd
}
7 changes: 7 additions & 0 deletions pkg/cmd/target/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package target

import (
"github.com/spf13/cobra"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/gardener/gardenctl-v2/internal/util"
"github.com/gardener/gardenctl-v2/pkg/cmd/base"
"github.com/gardener/gardenctl-v2/pkg/flags"
)

// NewCmdTargetProject returns a new target project command.
Expand All @@ -36,5 +38,10 @@ gardenctl target project my-project --garden my-garden`,

o.AddFlags(cmd.Flags())

manager, err := f.Manager()
utilruntime.Must(err)
manager.TargetFlags().AddGardenFlag(cmd.Flags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.Flags())

return cmd
}
7 changes: 7 additions & 0 deletions pkg/cmd/target/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package target

import (
"github.com/spf13/cobra"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/gardener/gardenctl-v2/internal/util"
"github.com/gardener/gardenctl-v2/pkg/cmd/base"
"github.com/gardener/gardenctl-v2/pkg/flags"
)

// NewCmdTargetSeed returns a new target seed command.
Expand All @@ -36,5 +38,10 @@ gardenctl target seed my-seed --garden my-garden`,

o.AddFlags(cmd.Flags())

manager, err := f.Manager()
utilruntime.Must(err)
manager.TargetFlags().AddGardenFlag(cmd.Flags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.Flags())

return cmd
}
9 changes: 9 additions & 0 deletions pkg/cmd/target/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package target

import (
"github.com/spf13/cobra"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/gardener/gardenctl-v2/internal/util"
"github.com/gardener/gardenctl-v2/pkg/cmd/base"
"github.com/gardener/gardenctl-v2/pkg/flags"
)

// NewCmdTargetShoot returns a new target shoot command.
Expand All @@ -36,5 +38,12 @@ gardenctl target shoot my-shoot --garden my-garden --project my-project`,

o.AddFlags(cmd.Flags())

manager, err := f.Manager()
utilruntime.Must(err)
manager.TargetFlags().AddGardenFlag(cmd.Flags())
manager.TargetFlags().AddProjectFlag(cmd.Flags())
manager.TargetFlags().AddSeedFlag(cmd.Flags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.Flags())

return cmd
}
4 changes: 2 additions & 2 deletions pkg/cmd/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ gardenctl target value/that/matches/pattern --control-plane`,

manager, err := f.Manager()
utilruntime.Must(err)
manager.TargetFlags().AddFlags(cmd.PersistentFlags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.PersistentFlags())
manager.TargetFlags().AddFlags(cmd.Flags())
flags.RegisterCompletionFuncsForTargetFlags(cmd, f, ioStreams, cmd.Flags())

return cmd
}
Expand Down
Loading

0 comments on commit 0276ae2

Please sign in to comment.