Commit 45e2f78b6d
Unsigned
Layout: unified · split
cmd/curd/main.go +7 −1
| @@ -51,7 +51,8 @@ func main() { | |||
| 51 | flag.BoolVar(&userCurdConfig.SaveMpvSpeed, "save-mpv-speed", userCurdConfig.SaveMpvSpeed, "Save MPV speed setting (true/false)") | 51 | flag.BoolVar(&userCurdConfig.SaveMpvSpeed, "save-mpv-speed", userCurdConfig.SaveMpvSpeed, "Save MPV speed setting (true/false)") |
| 52 | flag.BoolVar(&userCurdConfig.DiscordPresence, "discord-presence", userCurdConfig.DiscordPresence, "Enable Discord presence (true/false)") | 52 | flag.BoolVar(&userCurdConfig.DiscordPresence, "discord-presence", userCurdConfig.DiscordPresence, "Enable Discord presence (true/false)") |
| 53 | continueLast := flag.Bool("c", false, "Continue last episode") | 53 | continueLast := flag.Bool("c", false, "Continue last episode") |
| 54 | 54 | editConfig := flag.Bool("e", false, "Edit config") | |
| 55 | |||
| 55 | subFlag := flag.Bool("sub", false, "Watch sub version") | 56 | subFlag := flag.Bool("sub", false, "Watch sub version") |
| 56 | dubFlag := flag.Bool("dub", false, "Watch dub version") | 57 | dubFlag := flag.Bool("dub", false, "Watch dub version") |
| 57 | 58 | ||
| @@ -66,6 +67,11 @@ func main() { | |||
| 66 | 67 | ||
| 67 | anime.Ep.ContinueLast = *continueLast | 68 | anime.Ep.ContinueLast = *continueLast |
| 68 | 69 | ||
| 70 | if *editConfig { | ||
| 71 | internal.EditConfig(configFilePath) | ||
| 72 | return | ||
| 73 | } | ||
| 74 | |||
| 69 | // Set SubOrDub based on the flags | 75 | // Set SubOrDub based on the flags |
| 70 | if *subFlag { | 76 | if *subFlag { |
| 71 | userCurdConfig.SubOrDub = "sub" | 77 | userCurdConfig.SubOrDub = "sub" |
internal/curd.go +27
| @@ -4,6 +4,7 @@ import ( | |||
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | "os" | 6 | "os" |
| 7 | "os/exec" | ||
| 7 | "path/filepath" | 8 | "path/filepath" |
| 8 | "runtime" | 9 | "runtime" |
| 9 | "strconv" | 10 | "strconv" |
| @@ -24,6 +25,32 @@ func GetTokenFromFile(filePath string) (string, error) { | |||
| 24 | return token, nil | 25 | return token, nil |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 28 | func EditConfig(configFilePath string) { | ||
| 29 | // Get the user's preferred editor from the EDITOR environment variable | ||
| 30 | editor := os.Getenv("EDITOR") | ||
| 31 | if editor == "" { | ||
| 32 | // If EDITOR is not set, default to "vim" | ||
| 33 | editor = "vim" | ||
| 34 | } | ||
| 35 | |||
| 36 | // Construct the command to open the config file | ||
| 37 | cmd := exec.Command(editor, configFilePath) | ||
| 38 | |||
| 39 | // Set the command to run in the current terminal | ||
| 40 | cmd.Stdin = os.Stdin | ||
| 41 | cmd.Stdout = os.Stdout | ||
| 42 | cmd.Stderr = os.Stderr | ||
| 43 | |||
| 44 | // Run the editor command | ||
| 45 | err := cmd.Run() | ||
| 46 | if err != nil { | ||
| 47 | fmt.Printf("Error opening config file: %v\n", err) | ||
| 48 | return | ||
| 49 | } | ||
| 50 | |||
| 51 | fmt.Println("Config file edited successfully.") | ||
| 52 | } | ||
| 53 | |||
| 27 | // ClearLogFile removes all contents from the specified log file | 54 | // ClearLogFile removes all contents from the specified log file |
| 28 | func ClearLogFile(logFile string) error { | 55 | func ClearLogFile(logFile string) error { |
| 29 | // Open the file with truncate flag to clear its contents | 56 | // Open the file with truncate flag to clear its contents |