ProxySwitcher/cmd/set.go

44 lines
1.1 KiB
Go
Raw Normal View History

2024-08-29 21:08:02 +00:00
package cmd
import (
2024-08-30 16:08:24 +00:00
"encoding/json"
2024-08-29 21:08:02 +00:00
"fmt"
"os"
"os/signal"
"syscall"
2024-08-30 16:08:24 +00:00
"github.com/Baipyrus/ProxySwitcher/util"
2024-08-29 21:08:02 +00:00
"github.com/spf13/cobra"
)
// setCmd represents the set command
var setCmd = &cobra.Command{
Use: "set",
Short: "Enable the current internet proxy settings",
Run: func(cmd *cobra.Command, args []string) {
2024-08-30 16:08:24 +00:00
config, _ := util.ReadConfigs()
data, _ := json.Marshal(config)
fmt.Printf("%s\n\n", string(data))
2024-08-29 21:08:02 +00:00
// Block process until interrupted
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
fmt.Println("Blocking, press ctrl+c to continue...")
<-done
},
}
func init() {
rootCmd.AddCommand(setCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// setCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// setCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}