@@ -86,7 +86,7 @@ var rootCmd = &cobra.Command{
8686 return nil
8787 }
8888
89- port := getPort ( )
89+ port := viper . GetInt ( "port" )
9090
9191 // Use Viper to get source/target URIs (supports CLI flags and env vars)
9292 sourceURI := viper .GetString ("source" )
@@ -147,9 +147,7 @@ var statusCmd = &cobra.Command{
147147 Use : "status" ,
148148 Short : "Get the status of the replication process" ,
149149 RunE : func (cmd * cobra.Command , _ []string ) error {
150- port := getPort ()
151-
152- return NewClient (port ).Status (cmd .Context ())
150+ return NewClient (viper .GetInt ("port" )).Status (cmd .Context ())
153151 },
154152}
155153
@@ -158,8 +156,6 @@ var startCmd = &cobra.Command{
158156 Use : "start" ,
159157 Short : "Start Cluster Replication" ,
160158 RunE : func (cmd * cobra.Command , _ []string ) error {
161- port := getPort ()
162-
163159 pauseOnInitialSync , _ := cmd .Flags ().GetBool ("pause-on-initial-sync" )
164160 includeNamespaces , _ := cmd .Flags ().GetStringSlice ("include-namespaces" )
165161 excludeNamespaces , _ := cmd .Flags ().GetStringSlice ("exclude-namespaces" )
@@ -170,7 +166,7 @@ var startCmd = &cobra.Command{
170166 ExcludeNamespaces : excludeNamespaces ,
171167 }
172168
173- return NewClient (port ).Start (cmd .Context (), startOptions )
169+ return NewClient (viper . GetInt ( " port" ) ).Start (cmd .Context (), startOptions )
174170 },
175171}
176172
@@ -179,15 +175,13 @@ var finalizeCmd = &cobra.Command{
179175 Use : "finalize" ,
180176 Short : "Finalize Cluster Replication" ,
181177 RunE : func (cmd * cobra.Command , _ []string ) error {
182- port := getPort ()
183-
184178 ignoreHistoryLost , _ := cmd .Flags ().GetBool ("ignore-history-lost" )
185179
186180 finalizeOptions := finalizeRequest {
187181 IgnoreHistoryLost : ignoreHistoryLost ,
188182 }
189183
190- return NewClient (port ).Finalize (cmd .Context (), finalizeOptions )
184+ return NewClient (viper . GetInt ( " port" ) ).Finalize (cmd .Context (), finalizeOptions )
191185 },
192186}
193187
@@ -196,9 +190,7 @@ var pauseCmd = &cobra.Command{
196190 Use : "pause" ,
197191 Short : "Pause Cluster Replication" ,
198192 RunE : func (cmd * cobra.Command , _ []string ) error {
199- port := getPort ()
200-
201- return NewClient (port ).Pause (cmd .Context ())
193+ return NewClient (viper .GetInt ("port" )).Pause (cmd .Context ())
202194 },
203195}
204196
@@ -207,15 +199,13 @@ var resumeCmd = &cobra.Command{
207199 Use : "resume" ,
208200 Short : "Resume Cluster Replication" ,
209201 RunE : func (cmd * cobra.Command , _ []string ) error {
210- port := getPort ()
211-
212202 fromFailure , _ := cmd .Flags ().GetBool ("from-failure" )
213203
214204 resumeOptions := resumeRequest {
215205 FromFailure : fromFailure ,
216206 }
217207
218- return NewClient (port ).Resume (cmd .Context (), resumeOptions )
208+ return NewClient (viper . GetInt ( " port" ) ).Resume (cmd .Context (), resumeOptions )
219209 },
220210}
221211
@@ -312,12 +302,6 @@ var resetHeartbeatCmd = &cobra.Command{
312302 },
313303}
314304
315- // getPort returns the port number from Viper configuration.
316- // Viper handles precedence: CLI flag > env var (PCSM_PORT) > default.
317- func getPort () int {
318- return viper .GetInt ("port" )
319- }
320-
321305func main () {
322306 rootCmd .PersistentFlags ().String ("log-level" , "info" , "Log level" )
323307 rootCmd .PersistentFlags ().Bool ("log-json" , false , "Output log in JSON format" )
0 commit comments