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 4, 2023
1 parent 740e73e commit 6876523
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 129 deletions.
13 changes: 6 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,12 @@ 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
--seed string target the given seed cluster
--shoot string target the given shoot cluster
```

### Options inherited from parent commands
Expand All @@ -33,17 +37,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
11 changes: 4 additions & 7 deletions docs/help/gardenctl_target_seed.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ gardenctl target seed my-seed --garden my-garden
### Options

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

### Options inherited from parent commands
Expand All @@ -33,17 +35,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
11 changes: 4 additions & 7 deletions docs/help/gardenctl_target_shoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ 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
```

### Options inherited from parent commands
Expand All @@ -33,17 +35,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
14 changes: 7 additions & 7 deletions docs/help/gardenctl_target_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ gardenctl target view [flags]
### Options

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

### Options inherited from parent commands
Expand All @@ -19,17 +24,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
12 changes: 10 additions & 2 deletions pkg/cmd/target/control-plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ 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"
"github.com/gardener/gardenctl-v2/pkg/target"
)

// NewCmdTargetControlPlane returns a new target control plane command.
func NewCmdTargetControlPlane(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &TargetOptions{
Kind: TargetKindControlPlane,
Kind: target.TargetKindControlPlane,
Options: base.Options{
IOStreams: ioStreams,
},
Expand All @@ -30,11 +33,16 @@ gardenctl target control-plane
# target control-plane of shoot my-shoot
gardenctl target control-plane --garden my-garden --project my-project --shoot my-shoot`,
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, TargetKindControlPlane),
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, target.TargetKindControlPlane),
RunE: base.WrapRunE(o, f),
}

o.AddFlags(cmd.Flags())

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

return cmd
}
12 changes: 10 additions & 2 deletions pkg/cmd/target/garden.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ 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"
"github.com/gardener/gardenctl-v2/pkg/target"
)

// NewCmdTargetGarden returns a new target garden command.
func NewCmdTargetGarden(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &TargetOptions{
Kind: TargetKindGarden,
Kind: target.TargetKindGarden,
Options: base.Options{
IOStreams: ioStreams,
},
Expand All @@ -27,11 +30,16 @@ func NewCmdTargetGarden(f util.Factory, ioStreams util.IOStreams) *cobra.Command
Long: "Target a garden to set the scope for the next operations",
Example: `# target garden with name my-garden
gardenctl target garden my-garden`,
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, TargetKindGarden),
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, target.TargetKindGarden),
RunE: base.WrapRunE(o, f),
}

o.AddFlags(cmd.Flags())

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

return cmd
}
12 changes: 10 additions & 2 deletions pkg/cmd/target/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ 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"
"github.com/gardener/gardenctl-v2/pkg/target"
)

// NewCmdTargetProject returns a new target project command.
func NewCmdTargetProject(f util.Factory, ioStreams util.IOStreams) *cobra.Command {
o := &TargetOptions{
Kind: TargetKindProject,
Kind: target.TargetKindProject,
Options: base.Options{
IOStreams: ioStreams,
},
Expand All @@ -30,11 +33,16 @@ gardenctl target project my-project
# target project with name my-project of garden my-garden
gardenctl target project my-project --garden my-garden`,
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, TargetKindProject),
ValidArgsFunction: validTargetFunctionWrapper(f, ioStreams, target.TargetKindProject),
RunE: base.WrapRunE(o, f),
}

o.AddFlags(cmd.Flags())

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

return cmd
}
Loading

0 comments on commit 6876523

Please sign in to comment.