From 24f1f64b760d267eb493e81d9b08475baaa7ebbb Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Sat, 20 Mar 2021 16:09:05 -0400 Subject: [PATCH] Restructure to handle subcommands --- README.md | 7 ++++- TODO | 20 ++++++------- info.rkt | 2 +- tt.rkt | 87 +++++++++++++++++++++++++++++++------------------------ 4 files changed, 66 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index c8a62af..0ce900c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,12 @@ instructions (replacing `7.9` with whatever version you have installed) ### usage -`tt (FOLLOW-FILE)` +Read your timeline: +`tt r (FOLLOW-FILE)` + +See the rest of the usage options: +`tt -h` +`tt r -h` notes diff --git a/TODO b/TODO index 3249706..61a753d 100644 --- a/TODO +++ b/TODO @@ -2,10 +2,10 @@ - [ ] remove dependency on http-client - [ ] optional text wrap - [ ] write -- [ ] caching (use cache by default, unless explicitly asked for update) +- [-] caching (use cache by default, unless explicitly asked for update) - [x] value --> cache - [x] value <-- cache - requires: commands + requires: d command - [ ] timeline limits - [ ] feed set operations (perhaps better done externally?) - [ ] timeline as a result of a query (feed set op + filter expressions) @@ -23,17 +23,17 @@ - [ ] query language - [ ] console logger colors by level ('error) - [ ] file logger ('debug) -- [ ] commands: - - r | read +- [-] commands: + - [x] r | read - see timeline ops above - - w | write + - [ ] w | write - arg or stdin - nick expand to URI - - q | query + - [ ] q | query - see timeline ops above - see hashtag and channels above - - d | download - - u | upload + - [ ] d | download + - [ ] u | upload - calls user-configured command to upload user's own feed file to their server - Looks like a better CLI parser than "racket/cmdline": - https://docs.racket-lang.org/natural-cli/ + Looks like a better CLI parser than "racket/cmdline": https://docs.racket-lang.org/natural-cli/ + But it is no longer necessary now that I've figured out how to chain (command-line ..) calls. diff --git a/info.rkt b/info.rkt index a01aff9..a02a808 100644 --- a/info.rkt +++ b/info.rkt @@ -6,7 +6,7 @@ (define pkg-desc "twtxt client") (define version - "0.5.0") + "0.6.0") (define pkg-authors '("Siraaj Khandkar ")) (define deps diff --git a/tt.rkt b/tt.rkt index ce76863..e834505 100644 --- a/tt.rkt +++ b/tt.rkt @@ -271,47 +271,58 @@ (current-logger logger))) (module+ main - (require setup/getinfo) + (require (prefix-in info: setup/getinfo)) - (current-http-client/response-auto #f) - (let* ([prog-name "tt"] - [prog-version ((get-info (list prog-name)) 'version)] - [user-agent (user-agent prog-name prog-version)]) - (current-http-client/user-agent user-agent)) - (let* ([use-cache - #f] - [log-level - 'info] - [out-format - 'multi-line] - [num_workers - 15]) ; 15 was fastest out of the tried 1, 5, 10, 15 and 20. + (let ([log-level 'info]) (command-line + #:program + "tt" #:once-each - [("-c" "--cached") - "Read cached data instead of downloading." - (set! use-cache #t)] - [("-d" "--debug") "Enable debug log level." (set! log-level 'debug)] - - [("-j" "--jobs") - njobs "Number of concurrent jobs." - (set! num_workers (string->number njobs))] - - #:once-any - [("-s" "--short") - "Short output format" - (set! out-format 'single-line)] - - [("-l" "--long") - "Long output format" - (set! out-format 'multi-line)] - - #:args (filename) - (start-logger log-level) - (timeline-print out-format - (timeline use-cache - num_workers - (file->feeds filename)))))) + #:help-labels + "" + "and is one of" + "r, read : Read the timeline." + "" + #:args (command . args) + (match command + [(or "r" "read") + (current-command-line-arguments (list->vector args)) + (let ([use-cache + #f] + [out-format + 'multi-line] + [num_workers + ; 15 was fastest out of the tried 1, 5, 10, 15 and 20. + 15]) + (command-line + #:program + "tt read" + #:once-each + [("-j" "--jobs") + njobs "Number of concurrent jobs." + (set! num_workers (string->number njobs))] + [("-c" "--cached") + "Read cached data instead of downloading." + (set! use-cache #t)] + #:once-any + [("-s" "--short") + "Short output format" + (set! out-format 'single-line)] + [("-l" "--long") + "Long output format" + (set! out-format 'multi-line)] + #:args (filename) + (start-logger log-level) + (current-http-client/response-auto #f) + (let* ([prog-name "tt"] + [prog-version ((info:get-info (list prog-name)) 'version)] + [user-agent (user-agent prog-name prog-version)]) + (current-http-client/user-agent user-agent)) + (timeline-print out-format + (timeline use-cache + num_workers + (file->feeds filename)))))] + )))) -- 2.20.1