diff --git a/README.org b/README.org index b315c8c..fcd561d 100644 --- a/README.org +++ b/README.org @@ -5,11 +5,12 @@ Get an access to the [[https://www.digital.sncf.com/startup/api][SNCF API]]. By creating an account, you should receive an email with your authentication key. -You can now call the program with the authentication key as the first -argument. +The program reads the authentication key from the =SNCF_AUTH_KEY= +environment variable. #+begin_src sh -$ sncf +$ export SNCF_AUTH_KEY= +$ sncf ┌────────────┬────────────────────────────────┬───────────────┐ │ Réseau │ Direction │ Heure │ ├────────────┼────────────────────────────────┼───────────────┤ diff --git a/sncf.ss b/sncf.ss index 226217d..846e6dc 100755 --- a/sncf.ss +++ b/sncf.ss @@ -15,14 +15,22 @@ (def +sncf-url+ "https://api.sncf.com/v1/coverage/sncf/stop_areas/stop_area:SNCF:87415604/departures") (def (main . args) - (def gopt (getopt (argument 'sncf-key help: "SNCF API authentication key.") + (def gopt (getopt (flag 'help "-h" "--help" help: "Display this help.") (option 'mattermost-url "--mattermost-url" help: "Mattermost incoming webhook URL.") (option 'mattermost-channel "--channel" help: "Mattermost channel."))) (try (let* ((options (getopt-parse gopt args)) - (sncf-key (hash-ref options 'sncf-key)) + (help (hash-ref options 'help #f)) (mattermost-url (hash-ref options 'mattermost-url)) (mattermost-channel (hash-ref options 'mattermost-channel))) + (when help + (getopt-display-help gopt "sncf") + (exit 0)) + (def sncf-key (getenv "SNCF_AUTH_KEY" #f)) + (unless sncf-key + (display "No SNCF API authentication key found. Set the SNCF_AUTH_KEY environment variable.\n" + (current-error-port)) + (exit 1)) (let-values (((departures disruptions) (get-departures sncf-key))) (display-departures-table departures) (display-disruptions disruptions)