From a5bc5db713082001874738a47d4def65010b8e31 Mon Sep 17 00:00:00 2001 From: rusk Date: Sun, 3 Jan 2021 23:20:19 -0800 Subject: [PATCH] flags instead of getopt, push go.sum --- go.mod | 5 +---- go.sum | 2 ++ main.go | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index 854d1d1..f1ed24a 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module github.com/lordrusk/goscrape go 1.15 -require ( - github.com/mtarnawa/godesu v1.0.0 - github.com/pborman/getopt v1.1.0 -) +require github.com/mtarnawa/godesu v1.0.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..52910e8 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/mtarnawa/godesu v1.0.0 h1:i3W32K/ghhf9qaA7gRjS2dgDGXkByvonzgTHfO2AVRE= +github.com/mtarnawa/godesu v1.0.0/go.mod h1:GCnGaXjQp0BH6BQpvZvZfRwKLCeY4tzSFi2WMAGNcjA= diff --git a/main.go b/main.go index 9227cee..e23fd08 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io" "net/http" @@ -9,7 +10,6 @@ import ( "strings" "github.com/mtarnawa/godesu" - "github.com/pborman/getopt" ) type finishState struct { @@ -18,26 +18,30 @@ type finishState struct { } var ( // opts - help = getopt.BoolLong("help", 'h', "Help") - useOrigFilename = getopt.BoolLong("useOrigFilename", 'o', "Download with the original filename") - customDownloadDir = getopt.StringLong("customDownloadDir", 'c', "", "Set a custom directory for the images to download to") + help = flag.Bool("h", false, "Show help menu") + useOrigFilename = flag.Bool("o", false, "Download with the original filename") + customDownloadDir = flag.String("c", "", "Set a custom directory for the images to download to") ) func main() { - getopt.Parse() + flag.Parse() if *help { - getopt.Usage() + flag.Usage() return } - args := getopt.Args() + args := flag.Args() if len(args) < 1 { - getopt.Usage() + flag.Usage() return } urls := strings.Split(args[0], " ") - origDir, _ := os.Getwd() + origDir, err := os.Getwd() + if err != nil { + fmt.Printf("Could not grab working directory! | %v\n", err) + return + } Gochan := godesu.New() for urlNum, url := range urls { // loop through all urls @@ -71,7 +75,7 @@ func main() { fmt.Printf("Cannot create directory! %v\n", err) return } - + os.Chdir(purl[3] + "/" + purl[5]) }