some finishing touches

master
blank X 1 year ago
parent 0849c99d3c
commit f796ecb584
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
  1. 51
      main.go

@ -64,27 +64,6 @@ func main() {
if filename[0] == '.' {
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 {
submission, err = GetSubmission(client, token, submission.CrosspostParent[3:])
if err != nil {
@ -145,14 +124,16 @@ func main() {
}
}
}
fmt.Println(urls)
stdin := bufio.NewReader(os.Stdin)
i, err := InteractivelyAskIndex(stdin, urls)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get index: %s\n", err)
os.Exit(1)
}
if len(urls) > 1 {
filename = fmt.Sprintf("%s_%03d", filename, i)
}
unparsedUrl := urls[i]
fmt.Println(unparsedUrl)
parsedUrl, err := url.Parse(unparsedUrl)
if err != nil {
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)
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]
fmt.Println(unparsedUrl)
response, err := client.Get(unparsedUrl)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get response: %s\n", err)