some finishing touches

This commit is contained in:
blank X 2021-11-18 17:57:22 +07:00
parent 0849c99d3c
commit f796ecb584
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 27 additions and 24 deletions

51
main.go
View File

@ -64,27 +64,6 @@ func main() {
if filename[0] == '.' { if filename[0] == '.' {
filename = "_" + filename[1:] filename = "_" + filename[1:]
} }
files, err := os.ReadDir(".")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list files: %s\n", err)
os.Exit(1)
}
stdin := bufio.NewReader(os.Stdin)
for _, i := range files {
if strings.HasPrefix(i.Name(), filename) {
fmt.Printf("A file that starts with %s exists (%s), potentially overwrite (y/N)? ", filename, i.Name())
b, err := stdin.ReadByte()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when reading stdin: %s\n", err)
os.Exit(1)
}
if b != 'y' && b != 'Y' {
fmt.Println("Not overwriting")
os.Exit(1)
}
break
}
}
if submission.CrosspostParent != "" && len(submission.CrosspostParentList) > 0 { if submission.CrosspostParent != "" && len(submission.CrosspostParentList) > 0 {
submission, err = GetSubmission(client, token, submission.CrosspostParent[3:]) submission, err = GetSubmission(client, token, submission.CrosspostParent[3:])
if err != nil { if err != nil {
@ -145,14 +124,16 @@ func main() {
} }
} }
} }
fmt.Println(urls) stdin := bufio.NewReader(os.Stdin)
i, err := InteractivelyAskIndex(stdin, urls) i, err := InteractivelyAskIndex(stdin, urls)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get index: %s\n", err) fmt.Fprintf(os.Stderr, "Failed to get index: %s\n", err)
os.Exit(1) os.Exit(1)
} }
if len(urls) > 1 {
filename = fmt.Sprintf("%s_%03d", filename, i)
}
unparsedUrl := urls[i] unparsedUrl := urls[i]
fmt.Println(unparsedUrl)
parsedUrl, err := url.Parse(unparsedUrl) parsedUrl, err := url.Parse(unparsedUrl)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse url: %s\n", err) fmt.Fprintf(os.Stderr, "Failed to parse url: %s\n", err)
@ -211,8 +192,30 @@ func main() {
fmt.Fprintf(os.Stderr, "Failed to get index: %s\n", err) fmt.Fprintf(os.Stderr, "Failed to get index: %s\n", err)
os.Exit(1) os.Exit(1)
} }
if len(urls) > 1 {
filename = fmt.Sprintf("%s_%03d", filename, i)
}
files, err := os.ReadDir(".")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list files: %s\n", err)
os.Exit(1)
}
for _, i := range files {
if strings.HasPrefix(i.Name(), filename) {
fmt.Printf("A file that starts with %s exists (%s), potentially overwrite (y/N)? ", filename, i.Name())
b, err := stdin.ReadByte()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when reading stdin: %s\n", err)
os.Exit(1)
}
if b != 'y' && b != 'Y' {
fmt.Println("Not overwriting")
os.Exit(1)
}
break
}
}
unparsedUrl = urls[i] unparsedUrl = urls[i]
fmt.Println(unparsedUrl)
response, err := client.Get(unparsedUrl) response, err := client.Get(unparsedUrl)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get response: %s\n", err) fmt.Fprintf(os.Stderr, "Failed to get response: %s\n", err)