(declare (unit tick-init)) (module tick-init () (import scheme) (import (chicken base) (chicken file) (chicken format)) (import simple-logger commands optimism) (import tick tick-params) (define-command 'init (sprintf "\ init --username [--server-url ] [--force] Initialize configuration and the git repository of tickets. This command assumes that git is properly configured on your system to clone and, if necessary, create commits. --username|-u Username that will be used to identify you when you change tickets. If you don't intend to modify tickets, use any string (e.g., your first name). If you intend to modify tickets, use your current CHICKEN bugtracker username if you have it, otherwise request one. --server-url|-s URL to the server keeping the canonical tickets database. If not provided, the default URL will be used (~a). --force|-f Force the [re]creation of the credentials configuration file (~a)." +default-server-url+ +credentials-file+) (lambda (args*) (let* ((args (parse-command-line args* `(((--username -u) . username) ((--server-url -s) . server-url) ((--force -f)) ))) (username (get-opt '(--username -u) args)) (server-url (get-opt '(--server-url -s) args)) (force? (get-opt '(--force -f) args flag?: #t)) (creds-exist? (file-exists? +credentials-file+))) (if (and creds-exist? (not force?)) (begin (log-warning "Credentials file (~a) already exists. Use --force to overwrite it." +credentials-file+) (exit 1)) (write-credentials (or username (prompt "Username")) server-url)) (if (db-exists?) (begin (display "Tickets database already exists. ") (if server-url (begin (printf "Updating its remote to ~a\n" server-url) (git `("-C" ,(db-dir) "remote" "set-url" "origin" ,server-url))) (print "Nothing to do.")) (exit 0)) (db-init))))) ) ;; end module