80 lines
1.4 KiB
Go
80 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"sub-cli/internal/config"
|
|
"sub-cli/internal/converter"
|
|
"sub-cli/internal/formatter"
|
|
"sub-cli/internal/sync"
|
|
)
|
|
|
|
// Execute runs the main CLI application
|
|
func Execute() {
|
|
// parse args
|
|
if len(os.Args) < 2 {
|
|
fmt.Println(config.Usage)
|
|
return
|
|
}
|
|
|
|
switch os.Args[1] {
|
|
case "sync":
|
|
handleSync(os.Args[2:])
|
|
case "convert":
|
|
handleConvert(os.Args[2:])
|
|
case "fmt":
|
|
handleFormat(os.Args[2:])
|
|
case "version":
|
|
fmt.Printf("sub-cli version %s\n", config.Version)
|
|
case "help":
|
|
fmt.Println(config.Usage)
|
|
default:
|
|
fmt.Println("Unknown command")
|
|
fmt.Println(config.Usage)
|
|
}
|
|
}
|
|
|
|
// handleSync handles the sync command
|
|
func handleSync(args []string) {
|
|
if len(args) < 2 {
|
|
fmt.Println(config.SyncUsage)
|
|
return
|
|
}
|
|
|
|
sourceFile := args[0]
|
|
targetFile := args[1]
|
|
|
|
if err := sync.SyncLyrics(sourceFile, targetFile); err != nil {
|
|
fmt.Printf("Error: %v\n", err)
|
|
}
|
|
}
|
|
|
|
// handleConvert handles the convert command
|
|
func handleConvert(args []string) {
|
|
if len(args) < 2 {
|
|
fmt.Println(config.ConvertUsage)
|
|
return
|
|
}
|
|
|
|
sourceFile := args[0]
|
|
targetFile := args[1]
|
|
|
|
if err := converter.Convert(sourceFile, targetFile); err != nil {
|
|
fmt.Printf("Error: %v\n", err)
|
|
}
|
|
}
|
|
|
|
// handleFormat handles the fmt command
|
|
func handleFormat(args []string) {
|
|
if len(args) < 1 {
|
|
fmt.Println("Usage: sub-cli fmt <file>")
|
|
return
|
|
}
|
|
|
|
filePath := args[0]
|
|
|
|
if err := formatter.Format(filePath); err != nil {
|
|
fmt.Printf("Error: %v\n", err)
|
|
}
|
|
}
|