allow specifying file output name

This commit is contained in:
lee2sman 2022-01-01 21:47:58 -05:00
parent 19d0fe69ed
commit d05677ca65
1 changed files with 15 additions and 4 deletions

View File

@ -16,9 +16,9 @@ end
function usage
echo "Bookmobile: Simple command line script to download articles for offline reading as html, epub or markdown. Saves a simplified html document to current directory as default."
echo ""
echo "Optionally, you can specify a theme, format and output directory"
echo "Optionally, you can specify a theme, format, filename and output directory"
echo ""
echo "Usage: ./bookmobile url [ --theme THEME ] [ --format FORMAT ] [ --output OUTPUT ]"
echo "Usage: ./bookmobile url [ --theme THEME ] [ --format FORMAT ] [ --name FILENAME ] [ --output OUTPUT ]"
echo " [-h | --help ]"
echo ""
echo "Options:"
@ -37,6 +37,9 @@ function usage
echo " -f FORMAT Set file format (html, reader, markdown, epub)"
echo " default: html"
echo ""
echo " --name NAME"
echo " -n NAME Set specified file name instead of defaulting to article title"
echo ""
echo " --output OUTPUT"
echo " -o OUTPUT Set output location"
echo " default: current directory"
@ -44,7 +47,7 @@ function usage
end
function check_args
argparse h/help t/theme= f/format= o/output= -- $argv
argparse h/help t/theme= f/format= n/name= o/output= -- $argv
or exit 1
if set -q _flag_help
@ -60,6 +63,10 @@ function check_args
set format $_flag_format
end
if set -q _flag_n
set -g name $_flag_name
end
if set -q _flag_o
set output $_flag_output
end
@ -71,7 +78,11 @@ function set_metadata
set -g title (readable $url --properties "title")
if test -z "$title" #if title was empty, set title to date time
if test -n "$name" #check if title specified by user
set -g title $name
else if test -z "$title" #if title was empty, set title to date time
set -g title (date "+%Y-%m-%d_%H:%M:%S")