Skip to content

Commit e164d09

Browse files
committed
refactor: hydrate, initialize, and version commands with flag handling
1 parent 2d93d2b commit e164d09

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

cmd/nomos/flags/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package flags contains flags used by several CLI commands.
16+
// the local flags will be found in the command folder in the flags.go file.
1517
package flags
1618

1719
import (
File renamed without changes.
File renamed without changes.

cmd/nomos/version/cmd.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package version
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
"kpt.dev/configsync/cmd/nomos/flags"
20+
)
21+
22+
func init() {
23+
// Initialize flags for the bugreport command
24+
// This separation keeps flag definitions isolated from command execution logic
25+
flags.AddClientTimeout(Cmd)
26+
}
27+
28+
// Cmd is the Cobra object representing the nomos version command.
29+
var Cmd = &cobra.Command{
30+
Use: "version",
31+
Short: "Prints the version of ACM for each cluster as well this CLI",
32+
Long: `Prints the version of Configuration Management installed on each cluster and the version
33+
of the "nomos" client binary for debugging purposes.`,
34+
Example: ` nomos version`,
35+
RunE: func(cmd *cobra.Command, _ []string) error {
36+
// Don't show usage on error, as argument validation passed.
37+
cmd.SilenceUsage = true
38+
39+
// Create execution parameters from parsed flags
40+
params := ExecParams{
41+
Contexts: flags.Contexts,
42+
ClientTimeout: flags.ClientTimeout,
43+
}
44+
45+
// Execute the version command logic
46+
return ExecuteVersion(cmd.Context(), params)
47+
},
48+
}

cmd/nomos/version/version.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"strings"
2424
"sync"
2525

26-
"github.com/spf13/cobra"
2726
v1 "k8s.io/api/apps/v1"
2827
corev1 "k8s.io/api/core/v1"
2928
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -40,12 +39,6 @@ import (
4039
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
4140
)
4241

43-
func init() {
44-
// Initialize flags for the bugreport command
45-
// This separation keeps flag definitions isolated from command execution logic
46-
flags.AddClientTimeout(Cmd)
47-
}
48-
4942
// GetVersionReadCloser returns a ReadCloser with the output produced by running the "nomos version" command as a string
5043
func GetVersionReadCloser(ctx context.Context) (io.ReadCloser, error) {
5144
r, w, _ := os.Pipe()
@@ -68,28 +61,6 @@ var clientVersion = func() string {
6861
return version.VERSION
6962
}
7063

71-
// Cmd is the Cobra object representing the nomos version command.
72-
var Cmd = &cobra.Command{
73-
Use: "version",
74-
Short: "Prints the version of ACM for each cluster as well this CLI",
75-
Long: `Prints the version of Configuration Management installed on each cluster and the version
76-
of the "nomos" client binary for debugging purposes.`,
77-
Example: ` nomos version`,
78-
RunE: func(cmd *cobra.Command, _ []string) error {
79-
// Don't show usage on error, as argument validation passed.
80-
cmd.SilenceUsage = true
81-
82-
// Create execution parameters from parsed flags
83-
params := ExecParams{
84-
Contexts: flags.Contexts,
85-
ClientTimeout: flags.ClientTimeout,
86-
}
87-
88-
// Execute the version command logic
89-
return ExecuteVersion(cmd.Context(), params)
90-
},
91-
}
92-
9364
// allKubectlConfigs gets all kubectl configs, with error handling
9465
// This function is maintained for backward compatibility with existing code
9566
func allKubectlConfigs() (map[string]*rest.Config, error) {

0 commit comments

Comments
 (0)