code shuffle; quiet flag

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2016-03-12 20:45:19 +03:00
parent 59fb4b81eb
commit b5331d8c93

58
ufw
View File

@ -15,8 +15,13 @@ is_url() {
[[ "$1" =~ $cfg_url_regex ]]
}
msg() { printf '%s\n' "[ufw] $1"; }
err() { msg "(error) $1" >&2; }
msg() {
if ! (( flag_quiet )); then
printf '%s\n' "$1"
fi
}
err() { printf '(error) %s\n' "$*" >&2; }
usage() {
_cat <<- EOF
@ -47,12 +52,6 @@ usage() {
EOF
}
ensure_env() {
for i in "$cfg_tmp_dir"; do
[[ -d "$i" ]] || { mkdir -p "$i"; }
done
}
get_file_hash() {
read file_hash _ < <( sha1sum "$1" )
}
@ -341,53 +340,52 @@ main() {
while [[ "$1" ]]; do
case "$1" in
-h|--help|--usage) usage; return;;
-D|--screenshot-delay) cfg_scrot_delay="$2"; shift;;
-m|--max-filesize) cfg_max_filesize=$2; shift;;
-A|--album-name) album_name=$2; shift;;
-i|--my-ip) action='getmyip';;
-u|--shorten) action='url';;
-p|--public) flag_private='false';;
-R|--remove-file) flag_rm='1';;
-s|--screenshot) flag_scrot='1';;
-D|--screenshot-delay) cfg_scrot_delay="$2"; shift;;
-S|--short-url) flag_shortlink=1;;
-P|--page-url) flag_directlink=0;;
-q|--quiet) flag_quiet=1;;
-F|--fullscreen)
flag_scrot='1'
flag_scrot_fullscreen='1'
;;
-m|--max-filesize) cfg_max_filesize=$2; shift;;
-i|--my-ip) action='getmyip';;
-u|--shorten) action='url';;
-S|--short-url) flag_shortlink=1;;
-P|--page-url) flag_directlink=0;;
-a|--album-id)
misc_curl_args+=( -F "album_id=$2" )
shift
;;
-A|--album-name) album_name=$2; shift;;
-d|--description)
misc_curl_args+=( -F "description=$2" )
shift
;;
-l|--login)
action='login'
login=$2
shift
;;
-h|--help|--usage) usage; return;;
--) shift; break;;
-*)
err "Unknown flag: $1"
usage
return 1
;;
*) break;;
esac
shift
done
ensure_env
for i in "$cfg_tmp_dir"; do
[[ -d "$i" ]] || { mkdir -p "$i"; }
done
case "${action:-upload}" in
upload) upload "$1";;