Skip to content

Commit

Permalink
🐛 Can specify path with -o now - fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
makew0rld committed Jun 28, 2020
1 parent e687c35 commit f0c6d71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

# Binaries
build
gemget
gemget-*

# Created by https://www.gitignore.io/api/go,linux,code
# Edit at https://www.gitignore.io/?templates=go,linux,code
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Usage of gemget:
-e, --add-extension Add .gmi extensions to gemini files that don't have it, like directories.
-d, --directory string The directory where downloads go (default ".")
-i, --insecure Skip checking the cert
-o, --output string Output file, for when there is only one URL.
-o, --output string Output path, for when there is only one URL.
'-' means stdout and implies --quiet.
It overrides --directory.
-q, --quiet No output except for errors.
-r, --redirects uint How many redirects to follow before erroring out. (default 5)
-s, --skip Move to the next URL when one fails.
Expand Down
16 changes: 10 additions & 6 deletions gemget.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var insecure = flag.BoolP("insecure", "i", false, "Skip checking the cert")
var dir = flag.StringP("directory", "d", ".", "The directory where downloads go")
var output = flag.StringP("output", "o", "", "Output file, for when there is only one URL.\n'-' means stdout and implies --quiet.")
var output = flag.StringP("output", "o", "", "Output path, for when there is only one URL.\n'-' means stdout and implies --quiet.\nIt overrides --directory.")
var errorSkip = flag.BoolP("skip", "s", false, "Move to the next URL when one fails.")
var exts = flag.BoolP("add-extension", "e", false, "Add .gmi extensions to gemini files that don't have it, like directories.")
var quiet bool // Set in main, so that it can be changed later if needed
Expand All @@ -45,10 +45,10 @@ func urlError(format string, a ...interface{}) {

func saveFile(resp *gemini.Response, u *url.URL) {
var name string
if *output != "" {
name = *output
} else {
name = path.Base(u.Path) // Filename from URL
var savePath string

if *output == "" {
name := path.Base(u.Path) // Filename from URL
if name == "/" || name == "." {
// Domain is being downloaded, so there's no path/file
name = u.Hostname()
Expand All @@ -57,9 +57,13 @@ func saveFile(resp *gemini.Response, u *url.URL) {
// It's a gemini file, but it doesn't have that extension - and the user wants them added
name += ".gmi"
}
savePath = filepath.Join(*dir, name)
} else {
// There is an output path
savePath = *output
}

f, err := os.OpenFile(filepath.Join(*dir, name), os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(savePath, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fatal("Error saving file %s", name)
}
Expand Down

0 comments on commit f0c6d71

Please sign in to comment.