Commit c231390

Karn Wong <karn@karnwong.me>
2024-07-30 06:06:58
chore: refactor init function
1 parent 7e9f758
cmd/get/get.go
@@ -14,8 +14,3 @@ var Cmd = &cobra.Command{
 		fmt.Println("Please specify subcommand")
 	},
 }
-
-func init() {
-	Cmd.AddCommand(getIPCmd)
-	Cmd.AddCommand(getSystemInfoCmd)
-}
cmd/get/get_ip.go
@@ -70,3 +70,7 @@ var getIPCmd = &cobra.Command{
 		}
 	},
 }
+
+func init() {
+	Cmd.AddCommand(getIPCmd)
+}
cmd/get/get_system_info.go
@@ -132,3 +132,7 @@ var getSystemInfoCmd = &cobra.Command{
 		fmt.Println(systemInfoStr)
 	},
 }
+
+func init() {
+	Cmd.AddCommand(getSystemInfoCmd)
+}
cmd/root.go
@@ -30,8 +30,4 @@ func init() {
 	rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
 	rootCmd.AddCommand(get.Cmd)
 	rootCmd.AddCommand(generate.Cmd)
-	rootCmd.AddCommand(SpeedTestCmd)
-	rootCmd.AddCommand(ShouldIDeployTodayCmd)
-	rootCmd.AddCommand(TimerCmd)
-	rootCmd.AddCommand(StopwatchCmd)
 }
cmd/shouldideploytoday.go
@@ -48,3 +48,7 @@ var ShouldIDeployTodayCmd = &cobra.Command{
 		}
 	},
 }
+
+func init() {
+	rootCmd.AddCommand(ShouldIDeployTodayCmd)
+}
cmd/speedtest.go
@@ -46,3 +46,7 @@ var SpeedTestCmd = &cobra.Command{
 		}
 	},
 }
+
+func init() {
+	rootCmd.AddCommand(SpeedTestCmd)
+}
cmd/stopwatch.go
@@ -109,3 +109,7 @@ var StopwatchCmd = &cobra.Command{
 		}
 	},
 }
+
+func init() {
+	rootCmd.AddCommand(StopwatchCmd)
+}
cmd/timer.go
@@ -140,3 +140,7 @@ var TimerCmd = &cobra.Command{
 		}
 	},
 }
+
+func init() {
+	rootCmd.AddCommand(TimerCmd)
+}