Restructure to handle subcommands 0.6.0
authorSiraaj Khandkar <siraaj@khandkar.net>
Sat, 20 Mar 2021 20:09:05 +0000 (16:09 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sat, 20 Mar 2021 20:09:05 +0000 (16:09 -0400)
README.md
TODO
info.rkt
tt.rkt

index c8a62af..0ce900c 100644 (file)
--- 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 (file)
--- 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)
 - [ ] 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.
index a01aff9..a02a808 100644 (file)
--- 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 <siraaj@khandkar.net>"))
 (define deps
diff --git a/tt.rkt b/tt.rkt
index ce76863..e834505 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
     (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 <command> 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)))))]
+        ))))
This page took 0.040299 seconds and 4 git commands to generate.