bnjmnt4n / canvas-downloader

Downloader for Canvas written in Rust
35 stars 11 forks source link

Upgrade clap and change CLI arguments #26

Closed k-walter closed 1 year ago

k-walter commented 1 year ago
          Note that this is for `clap` v3.0. For `clap` v4.0, we should use `num_args(1..)`. I can upgrade clap in a separate PR as well

_Originally posted by @parth-io in https://github.com/k-walter/canvas-downloader/pull/22#discussion_r1091018983_

k-walter commented 1 year ago

Thinking of only allowing cred file and rearranging the flags in a major release.

k-walter commented 1 year ago

The current arguments are

USAGE:
    canvas-downloader [OPTIONS]

OPTIONS:
    -c, --canvas-credential-path <CANVAS_CREDENTIAL_PATH>    
    -d, --destination-folder <DESTINATION_FOLDER>            [default: .]
    -h, --help                                               Print help information
    -i, --enrollment-term-ids <ENROLLMENT_TERM_IDS>...       
    -n, --download-newer                                     
    -s, --save-credentials                                   
    -t, --canvas-token <CANVAS_TOKEN>                        
    -u, --canvas-url <CANVAS_URL> 

I would prefer the arguments to be

USAGE:
    canvas-downloader --credential-file <FILE> --term-ids <IDs>...  [OPTIONS]

OPTIONS:
    -c, --credential-file <FILE>    
    -d, --destination-folder <FOLDER>            [default: .]
    -h, --help                                   Print help information
    -t, --term-ids <IDs>...       
    -n, --download-newer

Then, the steps to get started are

  1. Write a credential file (e.g. cred.json) such as the following
    {
    "canvas_url": "canvas.nus.edu.sg",
    "canvas_token": 12345,
    }
  2. Get the terms by running the program with the credential file
    $ canvas-downloader --credential-file cred.json
    Please provide the Term ID(s) to download via -t
    Term IDs  | Courses
    115       | ["CS1101S", "CS1231S"]
    120       | ["CS2040S", "CS2030"]
  3. Rerun the program with the terms you are interested in downloading, eg
    $ canvas-downloader --credential-file cred.json -t 115 120
    Courses found:
    * CS1101S
    * CS1231S
    ...
JingYenLoh commented 1 year ago

This simplifies the tool a fair bit but can we still have the option to pass the token via the command line? I like to run the tool this way:

canvas-downloader ... --token $(fetch my token from password manager)

Don't have a very strong opinion on this though, if the feature is removed I will just find some workaround