-
Notifications
You must be signed in to change notification settings - Fork 85
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
Minor improvements in CLI #25
Conversation
html_links_<TIMESTAMP>.txt)
Thanks for taking the time to submit a PR @cknabs! Please give me a few days to take a look. |
help="R|Save the html links to a file.\n" | ||
"no -f = Do not save links\n" | ||
"-f = Save links to html_links_<TIMESTAMP>.txt\n" | ||
"-f SAVE_FILE = Save links to SAVE_FILE", |
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.
Nice upgrade to the -f switch. I like it!
metagoofil.py
Outdated
@@ -238,6 +236,16 @@ def _split_lines(self, text, width): | |||
return argparse.HelpFormatter._split_lines(self, text, width) | |||
|
|||
|
|||
def pos(type): | |||
def check(value): |
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've never seen this function convention before. It was hard to google for as well...is this called something specifically?
How is the actual value
from argparse being passed? Are you overriding a .check()
function within argparse or something?
I definitely like the spirit of this and want to keep it, but anyway it could be simplified? Or do you have some documentation recommending this for Python argparse type checking?
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.
The type
argument of argparse's add_argument()
is a callable that takes a string, converts it to the desired type, and can do some basic type-checking (see https://docs.python.org/3/library/argparse.html#type).
Here pos(T)
returns such a callable (called check()
, but the name has no special meaning) that maps a string to a result of type T
. It might be simpler to define separate pos_float()
and pos_int()
, and then use type=pos_int
instead of type=int
:
def pos_int(value):
try:
value_int = int(value)
assert value_int >= 0
return value_int
except (AssertionError, ValueError):
raise argparse.ArgumentTypeError(f"invalid value '{value}', must be an int >= 0")
In this particular case, I think checking that these 3 args are positive after parsing is fine, a callable returning a callable / using custom "types" is a bit overkill for such a simple interface.
The improvement provided here is minimal, this kind of custom type is more useful and relevant for a larger number of arguments with similar constraints, which isn't really the case here.
Let me know what you'd prefer, and I can amend the PR :)
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.
Learn something new every day! If you could make it two separate functions:
positive_int()
positive_float()
and keep the simple function check you have above instead of a callable returning a callable...that'd be perfect.
(`delay`, `url_timeout`, `number_of_threads`)
Done, feel free to squash everything into one commit if you think that helps. |
Thanks for your contributions @cknabs! |
This PR adds the following (minor) improvements to the CLI:
domain
andfile_types
, since this is already done by argparsesave_directory
ifdownload_files
is False-f
with an argument. If only-f
is specified, the links are saved tohtml_links_<TIMESTAMP>.txt
, as before.Thanks for the good work, really appreciate it!