Skip to content

Commit 295cb11

Browse files
authored
Add version subcommand (#31)
* Remove version flag The flag has never worked. In addition, it's intended to use a dedicated subcommand rather than a global flag. * Add version subcommand * Make wording for command help more consistent
1 parent c35f788 commit 295cb11

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

cmd/gardener-landscape-kit/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99

1010
"github.com/spf13/cobra"
1111
"k8s.io/cli-runtime/pkg/genericiooptions"
12-
"k8s.io/component-base/version/verflag"
1312

1413
"github.com/gardener/gardener-landscape-kit/pkg/cmd"
1514
"github.com/gardener/gardener-landscape-kit/pkg/cmd/generate"
1615
"github.com/gardener/gardener-landscape-kit/pkg/cmd/resolveocm"
16+
"github.com/gardener/gardener-landscape-kit/pkg/cmd/version"
1717
)
1818

1919
// Name is a const for the name of this component.
@@ -47,13 +47,13 @@ func NewCommand() *cobra.Command {
4747
for _, subcommand := range []*cobra.Command{
4848
generate.NewCommand(opts),
4949
resolveocm.NewCommand(opts),
50+
version.NewCommand(opts),
5051
} {
5152
cmd.AddCommand(subcommand)
5253
}
5354

5455
flags := cmd.PersistentFlags()
5556
opts.AddFlags(flags)
56-
verflag.AddFlags(flags)
5757

5858
return cmd
5959
}

pkg/cmd/generate/base/base.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ func NewCommand(globalOpts *cmd.Options) *cobra.Command {
2222

2323
cmd := &cobra.Command{
2424
Use: "base (-c CONFIG_FILE) TARGET_DIR",
25-
Short: "base generates or updates the base directory",
26-
Long: "Generates or updates base specific directories.",
25+
Short: "Generate or update the base directory",
2726
Example: "gardener-landscape-kit generate base -c ./example/20-componentconfig-glk.yaml ./base",
2827
Args: cobra.ExactArgs(1),
2928
RunE: func(cmd *cobra.Command, args []string) error {

pkg/cmd/generate/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func NewCommand(globalOpts *cmd.Options) *cobra.Command {
1717
cmd := &cobra.Command{
1818
Use: "generate",
19-
Short: "Generates or updates the landscape directories",
19+
Short: "Generate or update the landscape directories",
2020
}
2121

2222
for _, subcommand := range []*cobra.Command{

pkg/cmd/generate/landscape/landscape.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ func NewCommand(globalOpts *cmd.Options) *cobra.Command {
2424

2525
cmd := &cobra.Command{
2626
Use: "landscape (-c CONFIG_FILE) TARGET_DIR",
27-
Short: "landscape generates or updates the landscape directory",
28-
Long: "Generates or updates landscape specific directories.",
27+
Short: "Generate or update landscape specific directories",
2928
Example: "gardener-landscape-kit generate landscape -c ./example/20-componentconfig-glk.yaml ./",
3029
Args: cobra.ExactArgs(1),
3130
RunE: func(cmd *cobra.Command, args []string) error {

pkg/cmd/resolveocm/resolve_ocm_components.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func NewCommand(globalOpts *cmd.Options) *cobra.Command {
1919

2020
cmd := &cobra.Command{
2121
Use: "resolve-ocm-components",
22-
Short: "Collects all OCM components and their versions and generates component list and image vector files.",
23-
Long: "Collects all OCM components by walking all dependencies of the root component descriptor. " +
24-
"It outputs the component list and generates the imagevector overwrites for each component.",
22+
Short: "Collect all OCM components and their versions and generate component list and image vector files",
23+
Long: "Collect all OCM components by walking all dependencies of the root component descriptor. " +
24+
"Produce the component list and generate the image vector overwrites for each component.",
2525

2626
Example: `# Resolve all components starting at the root component. Writes component list, imagevector overwrite files for each component, and dumps all component descriptors.
2727

pkg/cmd/version/version.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package version
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/spf13/cobra"
11+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
12+
"k8s.io/component-base/version"
13+
14+
"github.com/gardener/gardener-landscape-kit/pkg/cmd"
15+
)
16+
17+
// NewCommand creates a new cobra.Command.
18+
func NewCommand(opts *cmd.Options) *cobra.Command {
19+
cmd := &cobra.Command{
20+
Use: "version",
21+
Short: "Print the program version information",
22+
Long: "Print the program version information",
23+
24+
Run: func(_ *cobra.Command, _ []string) {
25+
_, err := fmt.Fprintf(opts.Out, "gardener-landscape-kit Version: %s\n", version.Get())
26+
utilruntime.Must(err)
27+
},
28+
}
29+
30+
return cmd
31+
}

0 commit comments

Comments
 (0)