refactor
This commit is contained in:
parent
aedc4a4518
commit
9b0e2ed6dc
15 changed files with 693 additions and 540 deletions
80
cmd/root.go
Normal file
80
cmd/root.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue