mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
cmd/ctrld: separate iface variable for start/stop aliases
While at it, also fix a bug in getDNSByResolvectl, which won't return correct DNS values if there's no "%" symbol in output.
This commit is contained in:
committed by
Cuong Manh Le
parent
47c280cf1d
commit
a9fabd1b79
@@ -388,20 +388,22 @@ func initCLI() {
|
||||
Use: "start",
|
||||
Short: "Quick start service and configure DNS on interface",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
os.Args = append(os.Args, "--iface="+ifaceStartStop)
|
||||
startCmd.Run(cmd, args)
|
||||
},
|
||||
}
|
||||
startCmdAlias.Flags().StringVarP(&iface, "iface", "", "auto", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
||||
startCmdAlias.Flags().StringVarP(&ifaceStartStop, "iface", "", "auto", `Update DNS setting for iface, "auto" means the default interface gateway`)
|
||||
startCmdAlias.Flags().AddFlagSet(startCmd.Flags())
|
||||
rootCmd.AddCommand(startCmdAlias)
|
||||
stopCmdAlias := &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "Quick stop service and remove DNS from interface",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
os.Args = append(os.Args, "--iface="+ifaceStartStop)
|
||||
stopCmd.Run(cmd, args)
|
||||
},
|
||||
}
|
||||
stopCmdAlias.Flags().StringVarP(&iface, "iface", "", "auto", `Reset DNS setting for iface, "auto" means the default interface gateway`)
|
||||
stopCmdAlias.Flags().StringVarP(&ifaceStartStop, "iface", "", "auto", `Reset DNS setting for iface, "auto" means the default interface gateway`)
|
||||
stopCmdAlias.Flags().AddFlagSet(stopCmd.Flags())
|
||||
rootCmd.AddCommand(stopCmdAlias)
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ var (
|
||||
mainLog = rootLogger
|
||||
proxyLog = rootLogger
|
||||
|
||||
cdUID string
|
||||
iface string
|
||||
cdUID string
|
||||
iface string
|
||||
ifaceStartStop string
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -78,11 +78,8 @@ func getDNSByResolvectl(iface string) []string {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
parts := strings.SplitN(string(b), "%", 2)
|
||||
if len(parts) != 2 {
|
||||
return nil
|
||||
}
|
||||
parts = strings.Fields(parts[0])
|
||||
|
||||
parts := strings.Fields(strings.SplitN(string(b), "%", 2)[0])
|
||||
if len(parts) > 2 {
|
||||
return parts[3:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user