+ #:help-labels
+ ""
+ "and <command> is one of"
+ "r, read : Read the timeline (offline operation)."
+ "d, download : Download the timeline."
+ ; TODO Add path dynamically
+ "u, upload : Upload your twtxt file (alias to execute ~/.tt/upload)."
+ "c, crawl : Discover new peers mentioned by known peers (offline operation)."
+ ""
+ #:args (command . args)
+ (define log-writer (log-writer-start log-level))
+ (current-command-line-arguments (list->vector args))
+ (match command
+ [(or "d" "download")
+ ; Initially, 15 was fastest out of the tried: 1, 5, 10, 20. Then I
+ ; started noticing significant slowdowns. Reducing to 5 seems to help.
+ (let ([num-workers 5])
+ (command-line
+ #:program
+ "tt download"
+ #:once-each
+ [("-j" "--jobs")
+ njobs "Number of concurrent jobs."
+ (set! num-workers (string->number njobs))]
+ #:args file-paths
+ (let ([peers (paths->peers file-paths)])
+ (define-values (_res _cpu real-ms _gc)
+ (time-apply timeline-download (list num-workers peers)))
+ (log-info "Downloaded timelines from ~a peers in ~a seconds."
+ (length peers)
+ (/ real-ms 1000.0)))))]
+ [(or "u" "upload")
+ (command-line
+ #:program
+ "tt upload"
+ #:args ()
+ (if (system (path->string (build-path tt-home-dir "upload")))
+ (exit 0)
+ (exit 1)))]
+ [(or "r" "read")
+ (let ([out-format 'multi-line]
+ [order 'old->new])
+ (command-line
+ #:program
+ "tt read"
+ #:once-each
+ [("-r" "--rev")
+ "Reverse displayed timeline order."
+ (set! order 'new->old)]
+ #:once-any
+ [("-s" "--short")
+ "Short output format"
+ (set! out-format 'single-line)]
+ [("-l" "--long")
+ "Long output format"
+ (set! out-format 'multi-line)]
+ #:args file-paths
+ (let* ([peers
+ (paths->peers file-paths)]
+ [timeline
+ (timeline-sort (peers->timeline peers) order)])
+ (timeline-print out-format timeline))))]
+ [(or "c" "crawl")
+ (command-line
+ #:program
+ "tt crawl"
+ #:args file-paths
+ (let* ([peers-all-file
+ (build-path tt-home-dir "peers-all")]
+ [peers-mentioned-file
+ (build-path tt-home-dir "peers-mentioned")]
+ [peers
+ (paths->peers
+ (match file-paths
+ ; TODO Refactor such that path->string not needed
+ ['() (list (path->string peers-all-file))]
+ [_ file-paths]))]
+ [timeline
+ (peers->timeline peers)]
+ [peers-mentioned-curr
+ (uniq (append* (map Msg-mentions timeline)))]
+ [peers-mentioned-prev
+ (file->peers peers-mentioned-file)]
+ [peers-mentioned
+ (uniq (append peers-mentioned-prev
+ peers-mentioned-curr))]
+ [peers-all-prev
+ (file->peers peers-all-file)]
+ [peers-all
+ (uniq (append peers
+ peers-mentioned
+ peers-all-prev))])
+ (peers->file peers-mentioned
+ peers-mentioned-file)
+ (peers->file peers-all
+ peers-all-file)))]
+ [command
+ (eprintf "Error: invalid command: ~v\n" command)
+ (eprintf "Please use the \"--help\" option to see a list of available commands.\n")
+ (exit 1)])
+ (log-writer-stop log-writer))))