diff --git a/angel b/angel new file mode 100755 index 0000000..0912c09 Binary files /dev/null and b/angel differ diff --git a/cmd/angel/main.go b/cmd/angel/main.go index e50c0a0..dee502d 100644 --- a/cmd/angel/main.go +++ b/cmd/angel/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "log" "os" "github.com/daite/angel/common" @@ -14,11 +13,6 @@ import ( var version = "0.7.0" func main() { - cli.VersionFlag = &cli.BoolFlag{ - Name: "print-version", - Aliases: []string{"V"}, - Usage: "print only the version", - } app := &cli.App{ Name: "angel", Usage: "search torrent magnet!", @@ -29,13 +23,29 @@ func main() { Aliases: []string{"l"}, Usage: "choose torrent sites (kr or jp)", }, + // Removed the `version` flag from here }, Action: func(c *cli.Context) error { - keyword := "동상이몽2" - if c.NArg() > 0 { - keyword = c.Args().Get(0) + // Handle the -v flag to print the version + if c.Bool("version") { + fmt.Printf("%s version %s\n", c.App.Name, c.App.Version) + return nil + } + + // Print usage information if no arguments are provided + if c.Args().Len() == 0 && !c.IsSet("lang") { + cli.ShowAppHelp(c) + return nil } - if c.String("lang") == "kr" { + + // Print usage information if the -l flag is provided + if c.IsSet("lang") { + cli.ShowAppHelp(c) + return nil + } + + // Proceed with regular processing if a language is specified + if lang := c.String("lang"); lang == "kr" { s := []common.Scraping{ &ktorrent.TorrentMobile{}, &ktorrent.TorrentView{}, @@ -49,7 +59,7 @@ func main() { } s = common.GetAvailableSites(s) fmt.Printf("[*] Angel found %d available site(s) ...\n", len(s)) - data := common.CollectData(s, keyword) + data := common.CollectData(s, "") common.PrintData(data) } else { s := []common.ScrapingEx{ @@ -58,14 +68,19 @@ func main() { } s = common.GetAvailableSitesEx(s) fmt.Printf("[*] Angel found %d available site(s) ...\n", len(s)) - data := common.CollectDataEx(s, keyword) + data := common.CollectDataEx(s, "") common.PrintDataEx(data) } return nil }, + // Use the default error handling for CLI, which avoids the redefined error } + + // Run the app err := app.Run(os.Args) if err != nil { - log.Fatal(err) + // Log errors + fmt.Fprintln(os.Stderr, err) + os.Exit(1) } } diff --git a/common/common.go b/common/common.go index 51a41b3..6cb735b 100644 --- a/common/common.go +++ b/common/common.go @@ -197,6 +197,7 @@ func CheckNetWorkFromURL(url string) bool { // GetAvailableSites function gets available torrent sites func GetAvailableSites(oldItems []Scraping) []Scraping { + UpdateTorrentURL() fmt.Println("[*] Angel is checking available torrent sites ...") newItems := make([]Scraping, 0) items := []string{ @@ -226,6 +227,7 @@ func GetAvailableSites(oldItems []Scraping) []Scraping { // GetAvailableSitesEx function gets available torrent sites func GetAvailableSitesEx(oldItems []ScrapingEx) []ScrapingEx { + UpdateTorrentURL() fmt.Println("[*] Angel is checking available torrent sites ...") newItems := make([]ScrapingEx, 0) items := []string{"nyaa", "sukebe"} @@ -339,7 +341,7 @@ func generateBar(percentage int) string { return bar } -func init() { +func UpdateTorrentURL() { total := len(TorrentURL) successes := 0 failures := 0