omareldeeb / tum-moodle-downloader

A python-built web crawler to automate file downloads off of https://www.moodle.tum.de/
29 stars 10 forks source link

fix argparse bug #14

Closed noahpy closed 12 months ago

noahpy commented 1 year ago

When running python3 src/main.py without any additional arguments, the program fails without printing an usage message after entering the credentials (see below).

Output on the console:

$ python3 src/main.py
Enter password for [user]:
Starting Moodle session...
Traceback (most recent call last):
  File "/home/noah/.programs/tum-moodle-downloader-fork/src/main.py", line 76, in <module>
    args.func(args)
    ^^^^^^^^^
AttributeError: 'Namespace' object has no attribute 'func'

This is a known bug from argparse version 3.3.0 and above and can be fixed as seen here. With this fix the program simply terminates by displaying an usage message.

Output on the console after fix:

$ python3 src/main.py
Enter password for [user]:
Starting Moodle session
usage: main.py [-h] {list,download} ...

positional arguments:
  {list,download}
    list           List available resources of the specified "course" or, if no
                   course is specified, list available courses
    download       Download resources which match a "file_pattern" from a "course"
                   into a "destination" path. If parameters are omitted they are
                   retrieved from "src/course_config.json"

options:
  -h, --help       show this help message and exit
omareldeeb commented 12 months ago

Hi Noah, thanks for the pull request. I've cherry-picked your commit into the current master, as it had diverged a bit too much to merge.