2024-08-30 14:15:40 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-08-31 19:13:16 +00:00
|
|
|
"encoding/json"
|
2024-08-30 14:15:40 +00:00
|
|
|
"fmt"
|
2024-08-31 19:13:16 +00:00
|
|
|
"strings"
|
2024-08-30 14:15:40 +00:00
|
|
|
|
2024-08-31 19:13:16 +00:00
|
|
|
"github.com/Baipyrus/ProxySwitcher/util"
|
2024-08-30 14:15:40 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// saveCmd represents the save command
|
|
|
|
var saveCmd = &cobra.Command{
|
|
|
|
Use: "save",
|
2024-08-30 14:30:56 +00:00
|
|
|
Short: "Save a new internet proxy config",
|
2024-08-30 14:15:40 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2024-08-31 19:10:34 +00:00
|
|
|
var name string
|
|
|
|
fmt.Print("Name: ")
|
|
|
|
fmt.Scanln(&name)
|
2024-08-30 14:15:40 +00:00
|
|
|
|
2024-08-31 19:10:34 +00:00
|
|
|
var command string
|
|
|
|
fmt.Print("Command? ")
|
|
|
|
fmt.Scanln(&command)
|
2024-08-31 19:13:16 +00:00
|
|
|
|
2024-08-31 19:13:46 +00:00
|
|
|
fmt.Println("\nPrompting 'set' variants:")
|
|
|
|
set := util.PromptVariants()
|
|
|
|
|
|
|
|
fmt.Println("\nPrompting 'unset' variants:")
|
|
|
|
unset := util.PromptVariants()
|
|
|
|
|
2024-08-31 19:13:16 +00:00
|
|
|
config := util.Config{Name: name, Cmd: command, Set: set, Unset: unset}
|
|
|
|
|
|
|
|
fmt.Println("\n\nPlease confirm the following data:")
|
|
|
|
|
|
|
|
data, _ := json.Marshal(config)
|
|
|
|
fmt.Printf("%s\n", string(data))
|
|
|
|
|
|
|
|
var input string
|
|
|
|
fmt.Print("Save this data? (Y/n) ")
|
|
|
|
if input == "" || strings.ToLower(input) == "y" {
|
|
|
|
util.SaveConfig(config)
|
|
|
|
}
|
2024-08-30 14:15:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(saveCmd)
|
|
|
|
|
|
|
|
// Here you will define your flags and configuration settings.
|
|
|
|
|
|
|
|
// Cobra supports Persistent Flags which will work for this command
|
|
|
|
// and all subcommands, e.g.:
|
|
|
|
// saveCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
|
|
|
|
|
|
// Cobra supports local flags which will only run when this command
|
|
|
|
// is called directly, e.g.:
|
|
|
|
// saveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
|
|
}
|