mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
- Update all Init*Cmd function signatures to accept rootCmd parameter: * InitServiceCmd(rootCmd *cobra.Command) * InitClientsCmd(rootCmd *cobra.Command) * InitLogCmd(rootCmd *cobra.Command) * InitUpgradeCmd(rootCmd *cobra.Command) * InitRunCmd(rootCmd *cobra.Command) * InitInterfacesCmd(rootCmd *cobra.Command) - Update function calls in cli.go to pass rootCmd parameter - Update InitInterfacesCmd call in commands_service.go Benefits: - Eliminates global state dependency on rootCmd variable - Makes dependencies explicit in function signatures - Improves testability by allowing different root commands - Better encapsulation and modularity
59 lines
2.4 KiB
Go
59 lines
2.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
// RunCommand handles run-related operations
|
|
type RunCommand struct {
|
|
// Add any dependencies here if needed in the future
|
|
}
|
|
|
|
// NewRunCommand creates a new run command handler
|
|
func NewRunCommand() *RunCommand {
|
|
return &RunCommand{}
|
|
}
|
|
|
|
// Run implements the logic for the run command
|
|
func (rc *RunCommand) Run(cmd *cobra.Command, args []string) {
|
|
RunCobraCommand(cmd)
|
|
}
|
|
|
|
// InitRunCmd creates the run command with proper logic
|
|
func InitRunCmd(rootCmd *cobra.Command) *cobra.Command {
|
|
rc := NewRunCommand()
|
|
|
|
runCmd := &cobra.Command{
|
|
Use: "run",
|
|
Short: "Run the DNS proxy server",
|
|
Args: cobra.NoArgs,
|
|
Run: rc.Run,
|
|
}
|
|
runCmd.Flags().BoolVarP(&daemon, "daemon", "d", false, "Run as daemon")
|
|
runCmd.Flags().StringVarP(&configPath, "config", "c", "", "Path to config file")
|
|
runCmd.Flags().StringVarP(&configBase64, "base64_config", "", "", "Base64 encoded config")
|
|
runCmd.Flags().StringVarP(&listenAddress, "listen", "", "", "Listener address and port, in format: address:port")
|
|
runCmd.Flags().StringVarP(&primaryUpstream, "primary_upstream", "", "", "Primary upstream endpoint")
|
|
runCmd.Flags().StringVarP(&secondaryUpstream, "secondary_upstream", "", "", "Secondary upstream endpoint")
|
|
runCmd.Flags().StringSliceVarP(&domains, "domains", "", nil, "List of domain to apply in a split DNS policy")
|
|
runCmd.Flags().StringVarP(&logPath, "log", "", "", "Path to log file")
|
|
runCmd.Flags().IntVarP(&cacheSize, "cache_size", "", 0, "Enable cache with size items")
|
|
runCmd.Flags().StringVarP(&cdUID, cdUidFlagName, "", "", "Control D resolver uid")
|
|
runCmd.Flags().StringVarP(&cdOrg, cdOrgFlagName, "", "", "Control D provision token")
|
|
runCmd.Flags().StringVarP(&customHostname, customHostnameFlagName, "", "", "Custom hostname passed to ControlD API")
|
|
runCmd.Flags().BoolVarP(&cdDev, "dev", "", false, "Use Control D dev resolver/domain")
|
|
_ = runCmd.Flags().MarkHidden("dev")
|
|
runCmd.Flags().StringVarP(&homedir, "homedir", "", "", "")
|
|
_ = runCmd.Flags().MarkHidden("homedir")
|
|
runCmd.Flags().StringVarP(&iface, "iface", "", "", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
|
_ = runCmd.Flags().MarkHidden("iface")
|
|
runCmd.Flags().StringVarP(&cdUpstreamProto, "proto", "", ctrld.ResolverTypeDOH, `Control D upstream type, either "doh" or "doh3"`)
|
|
|
|
runCmd.FParseErrWhitelist = cobra.FParseErrWhitelist{UnknownFlags: true}
|
|
rootCmd.AddCommand(runCmd)
|
|
|
|
return runCmd
|
|
}
|