[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: wget2 | Similarity of --output-file/-o and --output-document/-O (#67
From: |
Mark Collins (@Marcool04) |
Subject: |
Re: wget2 | Similarity of --output-file/-o and --output-document/-O (#675) |
Date: |
Mon, 29 Jul 2024 06:05:42 +0000 |
Mark Collins commented:
https://gitlab.com/gnuwget/wget2/-/issues/675#note_2019790455
Just for illustration, here is the safety-net I've woven for myself:
```bash
#!/usr/bin/env bash
if ! TEMP=$(getopt -o 'o:' --long 'output-file:' -n 'wget2' -- "$@"); then
echo 'Terminating...' >&2
exit 1
fi
eval set -- "$TEMP"
unset TEMP
output_file="__UNSET"
while true; do
case "$1" in
'-o'|'--output-file')
if [[ -n "$2" ]]; then
output_file="$2"
fi
shift 2
continue
;;
'--')
shift
break
;;
*)
echo 'getopt internal error!' >&2
exit 1
;;
esac
done
if [[ "$output_file" != "__UNSET" ]]; then
if [[ -e "$output_file" ]]; then
>&2 echo "WARNING: output-file specified and $output_file exists"
i=1
while [[ -e "${output_file}.$i" ]]; do
>&2 echo "WARNING: File ${output_file}.$i also exists"
((i=i+1))
continue
done
>&2 echo "WARNING: Saving wget2 log output to ${output_file}.$i"
wget2 --output-file "${output_file}.$i" "$@"
else
wget2 --output-file "${output_file}" "$@"
fi
else
wget2 "$@"
fi
```
It doesn't handle `--clobber` or anything fancy like that (because there's too
much sophistication in wget2 as far as --no-clobber etc. goes) but it should
give an idea of what I mean.
--
Reply to this email directly or view it on GitLab:
https://gitlab.com/gnuwget/wget2/-/issues/675#note_2019790455
You're receiving this email because of your account on gitlab.com.