-
Notifications
You must be signed in to change notification settings - Fork 23
Add --output/-o flag #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,28 +48,34 @@ usage() | |
| cat << _EOF_ | ||
| ${PROGRAM_NAME} -- a simple wrapper around curl to easily download files. | ||
|
|
||
| Usage: ${PROGRAM_NAME} [--curl-options <CURL_OPTIONS>] [--dry-run] [--no-decode-filename] [--] <URL>... | ||
| ${PROGRAM_NAME} [--curl-options=<CURL_OPTIONS>] [--dry-run] [--no-decode-filename] [--] <URL>... | ||
| Usage: ${PROGRAM_NAME} <URL>... | ||
| ${PROGRAM_NAME} [--curl-options <CURL_OPTIONS>]... [--no-decode-filename] [-o|-O|--output <PATH>] [--dry-run] [--] <URL>... | ||
| ${PROGRAM_NAME} [--curl-options=<CURL_OPTIONS>]... [--no-decode-filename] [--output=<PATH>] [--dry-run] [--] <URL>... | ||
| ${PROGRAM_NAME} -h|--help | ||
| ${PROGRAM_NAME} -V|--version | ||
|
|
||
| Options: | ||
|
|
||
| --curl-options <CURL_OPTIONS>: Specify extra options to be | ||
| passed when invoking curl. May be | ||
| --curl-options <CURL_OPTIONS>: Specify extra options to be passed when invoking curl. May be | ||
| specified more than once. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise: these are formatting changed that should go into their own PR IMHO. |
||
|
|
||
| --no-decode-filename: Don't percent-decode the output filename, | ||
| even if the percent-encoding in the URL was | ||
| done by wcurl, e.g.: The URL contained | ||
| whitespaces. | ||
| -o, -O, --output <PATH>: Use the provided output path instead of getting it from the URL. If | ||
| multiple URLs are provided, all files will have the same name with a | ||
| number appended to the end (curl >= 7.83.0). | ||
|
|
||
| --dry-run: Don't actually execute curl, just print what would be | ||
| invoked. | ||
| --no-decode-filename: Don't percent-decode the output filename, even if the percent-encoding in | ||
| the URL was done by wcurl, e.g.: The URL contained whitespaces. | ||
|
|
||
| -V,--version: Print version information. | ||
| --dry-run: Don't actually execute curl, just print what would be invoked. | ||
|
|
||
| -h,--help: Print this usage message. | ||
| -V, --version: Print version information. | ||
|
|
||
| -h, --help: Print this usage message. | ||
|
|
||
| <URL>: The URL to be downloaded. May be specified more than once. | ||
|
|
||
| <CURL_OPTIONS>: Any option supported by curl can be set here. This is not used by wcurl; it's | ||
| instead forwarded to the curl invocation. | ||
|
|
||
| <URL>: The URL to be downloaded. May be specified more than once. | ||
| _EOF_ | ||
|
|
@@ -92,6 +98,11 @@ CURL_OPTIONS="" | |
| # The URLs to be downloaded. | ||
| URLS="" | ||
|
|
||
| # Will be set to the percent-decoded filename parsed from the URL, unless | ||
| # --output or --no-decode-filename are used. | ||
| OUTPUT_PATH="" | ||
| HAS_USER_SET_OUTPUT="false" | ||
|
|
||
| # The parameters that will be passed per-URL to curl. | ||
| readonly PER_URL_PARAMETERS="\ | ||
| --fail \ | ||
|
|
@@ -112,7 +123,7 @@ sanitize() | |
| error "You must provide at least one URL to download." | ||
| fi | ||
|
|
||
| readonly CURL_OPTIONS URLS DRY_RUN | ||
| readonly CURL_OPTIONS URLS DRY_RUN HAS_USER_SET_OUTPUT | ||
| } | ||
|
|
||
| # Indicate via exit code whether the string given in the first parameter | ||
|
|
@@ -213,10 +224,14 @@ exec_curl() | |
|
|
||
| NEXT_PARAMETER="" | ||
| for url in ${URLS}; do | ||
| filename="$(get_url_filename "${url}")" | ||
| [ -z "${filename}" ] && filename=index.html | ||
| # If the user did not provide an output path, define one. | ||
| if [ "${HAS_USER_SET_OUTPUT}" = "false" ]; then | ||
sergiodj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| OUTPUT_PATH="$(get_url_filename "${url}")" | ||
| # If we could not get a path from the URL, use the default: index.html. | ||
| [ -z "${OUTPUT_PATH}" ] && OUTPUT_PATH=index.html | ||
| fi | ||
| # shellcheck disable=SC2086 | ||
| set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${CURL_HAS_NO_CLOBBER} ${CURL_OPTIONS} --output "${filename}" "${url}" | ||
| set -- "$@" ${NEXT_PARAMETER} ${PER_URL_PARAMETERS} ${CURL_HAS_NO_CLOBBER} ${CURL_OPTIONS} --output "${OUTPUT_PATH}" "${url}" | ||
| NEXT_PARAMETER="--next" | ||
| done | ||
|
|
||
|
|
@@ -247,6 +262,18 @@ while [ -n "${1-}" ]; do | |
| DRY_RUN="true" | ||
| ;; | ||
|
|
||
| --output=*) | ||
| opt=$(printf "%s\n" "${1}" | sed 's/^--output=//') | ||
| HAS_USER_SET_OUTPUT="true" | ||
| OUTPUT_PATH="${opt}" | ||
| ;; | ||
|
|
||
| -o|-O|--output) | ||
| shift | ||
| HAS_USER_SET_OUTPUT="true" | ||
| OUTPUT_PATH="${1}" | ||
| ;; | ||
|
|
||
| --no-decode-filename) | ||
| DECODE_FILENAME="false" | ||
| ;; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this change, but it doesn't belong in this PR :-).