(module tick-cmd () (import scheme) (import (chicken base) (chicken file) (chicken process-context)) (import commands simple-logger optimism xdg-basedir) (import tick tick-params) (include "version.scm") (log-level (or (and-let* ((level (get-environment-variable "TICK_LOG_LEVEL"))) (string->number level)) 30)) (declare (uses tick-attach)) (declare (uses tick-comment)) (declare (uses tick-check-db)) (declare (uses tick-create)) (declare (uses tick-edit)) (declare (uses tick-info)) (declare (uses tick-init)) (declare (uses tick-list)) (declare (uses tick-pull)) (declare (uses tick-query)) (declare (uses tick-set)) (declare (uses tick-get)) (declare (uses tick-push)) (declare (uses tick-show)) (let ((args (command-line-arguments))) ;; Load conf file if it exists (when (and (file-exists? +conf-file+) (file-readable? +conf-file+)) (log-debug "Loading configuration file: ~a" +conf-file+) (load +conf-file+)) (when (null? args) ;; No paging here, as the help message in case of invalid usage ;; goes to stderr. (show-main-help 1)) (when (member (car args) (help-options)) (with-output-to-pager (lambda () ;; Use #f here to avoid exiting while paging, which might ;; garble the output. (show-main-help #f))) (exit 0)) (when (member (car args) '("-v" "-version" "--version")) (print tick-version) (exit 0)) (or (and-let* ((cmd (string->symbol (car args))) (handler (alist-ref cmd (commands)))) (cleanup-environment!) (unless (eq? cmd 'init) (db-check-compatibility)) ((command-proc handler) (cdr args))) (if (valid-ticket? (car args)) ((command-proc (alist-ref 'show (commands))) args) (die! "Invalid command: ~a" (car args))))) ) ;; end module