prefixed all of rodo.rkt and args.rkt

main
m455 2018-10-10 13:55:52 -04:00
parent afaaf5094d
commit d56570dcc2
10 changed files with 529 additions and 547 deletions

View File

@ -1,11 +1,11 @@
#lang racket/base #lang racket/base
(require racket/vector (require (prefix-in vector: racket/vector)
racket/list (prefix-in list: racket/list)
"config.rkt" (prefix-in config: "config.rkt")
"init.rkt" (prefix-in init: "init.rkt")
"util.rkt" (prefix-in util: "util.rkt")
"messages.rkt") (prefix-in messages: "messages.rkt"))
(provide (all-defined-out)) (provide (all-defined-out))
@ -14,34 +14,31 @@
([args-length (vector-length args)]) ([args-length (vector-length args)])
(cond (cond
[(equal? args-length 0) [(equal? args-length 0)
(d-hash-ref messages 'show-usage)] (util:display-hash-ref messages:messages 'show-usage)]
[(and [(and
(equal? args-length 1) (equal? args-length 1)
(equal? (vector-member list-command args) 0)) (equal? (vector:vector-member config:list-command args) 0))
(show-list)] (util:show-list)]
[(and [(and
(equal? args-length 2) (equal? args-length 2)
(equal? (vector-ref args 0) add-command)) (equal? (vector-ref args 0) config:add-command))
(add-item args)] (util:add-item args)]
[(and [(and
(equal? args-length 2) (equal? args-length 2)
(equal? (vector-member remove-command args) 0) (equal? (vector:vector-member config:remove-command args) 0)
(not (equal? (vector-member "0" args) 1)) (not (equal? (vector:vector-member "0" args) 1))
(vector-member (vector-ref args 1) (list->vector (map number->string (rest (range (length (file->string-list path)))))))) (vector:vector-member
(remove-item args)] (vector-ref args 1)
(list->vector
(map number->string (list:rest (list:range (length (util:file->string-list config:path))))))))
(util:remove-item args)]
[(and [(and
(equal? args-length 1) (equal? args-length 1)
(equal? (vector-member initialize-command args) 0)) (equal? (vector:vector-member config:initialize-command args) 0))
(initialize)] (init:initialize)]
[(and [(and
(equal? args-length 1) (equal? args-length 1)
(member (vector-ref args 0) help-command)) (member (vector-ref args 0) config:help-command))
(d-hash-ref messages 'show-help)] (util:display-hash-ref messages:messages 'show-help)]
[else [else
(d-hash-ref messages 'show-usage)]))) (util:display-hash-ref messages:messages 'show-usage)])))

View File

@ -3,8 +3,7 @@
(require racket/file (require racket/file
"config.rkt" "config.rkt"
"util.rkt" "util.rkt"
"messages.rkt" "messages.rkt")
"io.rkt")
(provide (all-defined-out)) (provide (all-defined-out))
@ -16,14 +15,14 @@
#:exists 'replace)) #:exists 'replace))
(define (init-prompt hash-list key) (define (init-prompt hash-list key)
(d-hash-ref hash-list key) (display-hash-ref hash-list key)
(display "> ") (display "> ")
(let (let
([user-input (read-line)]) ([user-input (read-line)])
(cond (cond
[(member user-input (hash-ref y/n 'yes)) [(member user-input (hash-ref y/n 'yes))
(d-hash-ref messages 'creating-folder) (display-hash-ref messages 'creating-folder)
(d-hash-ref messages 'creating-file) (display-hash-ref messages 'creating-file)
(create-folder) (create-folder)
(create-file) (create-file)
(initialize-file) (initialize-file)
@ -31,17 +30,17 @@
(and (and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(d-hash-ref messages 'successfully-created) (display-hash-ref messages 'successfully-created)
(d-hash-ref messages 'creation-error))] (display-hash-ref messages 'creation-error))]
[(member user-input (hash-ref y/n 'no)) [(member user-input (hash-ref y/n 'no))
(d-hash-ref messages 'terminating)] (display-hash-ref messages 'terminating)]
[else [else
(init-prompt messages 'choose-y/n)]))) (init-prompt messages 'choose-y/n)])))
(define (initialize) (define (initialize)
(if (check-for-file) (if (check-for-file)
(d-hash-ref messages 'file-already-exists) (display-hash-ref messages 'file-already-exists)
(begin (begin
(init-prompt messages 'init-y/n)))) (init-prompt messages 'init-y/n))))

32
io.rkt
View File

@ -1,32 +0,0 @@
#lang racket/base
(require racket/file
"config.rkt")
(provide (all-defined-out))
(define (check-for-file)
(file-exists? path))
(define (create-file)
(let
([opened-file
(open-output-file
path
#:mode 'text
#:exists 'can-update)])
(close-output-port opened-file)))
(define (check-for-folder)
(directory-exists?
(expand-user-path
(string-append
program-path
program-directory))))
(define (create-folder)
(make-directory
(expand-user-path
(string-append
program-path
program-directory))))

BIN
rodo

Binary file not shown.

View File

@ -1,9 +1,9 @@
#! /usr/bin/env racket #! /usr/bin/env racket
#lang racket/base #lang racket/base
(require "args.rkt") (require (prefix-in args: "args.rkt"))
(define (main) (define (main)
(check-args (current-command-line-arguments))) (args:check-args (current-command-line-arguments)))
(main) (main)

View File

@ -4,22 +4,40 @@
racket/file racket/file
racket/string racket/string
"config.rkt" "config.rkt"
"io.rkt"
"messages.rkt") "messages.rkt")
(provide (all-defined-out)) (provide (all-defined-out))
(define (d-hash-ref hash-list key) (define (check-for-file)
(file-exists? path))
(define (create-file)
(let ([opened-file
(open-output-file path
#:mode 'text
#:exists 'can-update)])
(close-output-port opened-file)))
(define (check-for-folder)
(directory-exists? (expand-user-path
(string-append
program-path
program-directory))))
(define (create-folder)
(make-directory (expand-user-path
(string-append
program-path
program-directory))))
(define (display-hash-ref hash-list key)
(display (hash-ref hash-list key))) (display (hash-ref hash-list key)))
(define (d-vector-ref args key) (define (d-vector-ref args key)
(display (vector-ref args key))) (display (vector-ref args key)))
(define (file->string-list path-to-file) (define (file->string-list path-to-file)
(let (let ([todo-list (file->lines path-to-file
([todo-list
(file->lines
path-to-file
#:mode 'text #:mode 'text
#:line-mode 'any)]) #:line-mode 'any)])
todo-list)) todo-list))
@ -34,63 +52,66 @@
(display (display
(string-append "\"" args "\""))) (string-append "\"" args "\"")))
(define (number-list lst) (define (prefix-with-number lst)
(map string-append (map string-append
(map number->string (rest (range (length lst)))) (map number->string (rest (range (length lst))))
(rest lst))) (rest lst)))
(define (indent-list lst) (define (prefix-with-period lst)
(string-append ". " lst)) (string-append ". " lst))
(define (prettify-list) (define (prettify-list)
(display (display
(string-join (string-join (prefix-with-number (map prefix-with-period (file->string-list path)))
(number-list (map indent-list (file->string-list path)))
"\n" "\n"
#:after-last "\n"))) #:after-last "\n")))
(define (append-to-end args lst)
(reverse (cons args (reverse (file->string-list lst)))))
(define (display-item-added args)
(display-hash-ref messages 'item-added-prefix)
(quote-item args)
(display-hash-ref messages 'item-added-suffix))
(define (display-item-removed args)
(display-hash-ref messages 'item-removed-prefix)
(quote-item args)
(display-hash-ref messages 'item-removed-suffix))
(define (show-list) (define (show-list)
(cond (cond [(and
[(and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(if (if
(list-empty? path) (list-empty? path)
(d-hash-ref messages 'empty-todo-list) (display-hash-ref messages 'empty-todo-list)
(prettify-list))] (prettify-list))]
[else [else
(d-hash-ref messages 'file-not-found) (display-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)])) (display-hash-ref messages 'try-init)]))
(define (add-item-to-file args) (define (add-item-to-file args)
(let ([new-list (let ([new-list (append-to-end args path)])
(reverse
(cons args
(reverse (file->string-list path))))])
(display-to-file (display-to-file
(string-join new-list "\n" #:after-last "\n") (string-join new-list "\n" #:after-last "\n")
path path
#:mode 'text #:mode 'text
#:exists 'replace) #:exists 'replace)
(d-hash-ref messages 'item-added-prefix) (display-item-added args)))
(quote-item args)
(d-hash-ref messages 'item-added-suffix)))
(define (add-item args) (define (add-item args)
(if (if (and
(and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(add-item-to-file (vector-ref args 1)) (add-item-to-file (vector-ref args 1))
(begin (begin
(d-hash-ref messages 'file-not-found) (display-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (display-hash-ref messages 'try-init))))
(define (remove-item-from-file args) (define (remove-item-from-file args)
(let ([removed-item (let ([removed-item (get-removed-item (file->string-list path) args)]
(get-removed-item (file->string-list path) args)] [new-list (remove
[new-list
(remove
(list-ref (file->string-list path) (string->number args)) (list-ref (file->string-list path) (string->number args))
(file->string-list path))]) (file->string-list path))])
(display-to-file (display-to-file
@ -98,19 +119,16 @@
path path
#:mode 'text #:mode 'text
#:exists 'replace) #:exists 'replace)
(d-hash-ref messages 'item-removed-prefix) (display-item-removed removed-item)))
(quote-item removed-item)
(d-hash-ref messages 'item-removed-suffix)))
(define (remove-item args) (define (remove-item args)
(cond (cond [(list-empty? path)
[(list-empty? path) (display-hash-ref messages 'empty-todo-list)]
(d-hash-ref messages 'empty-todo-list)]
[(and [(and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(remove-item-from-file (vector-ref args 1))] (remove-item-from-file (vector-ref args 1))]
[(and (not (check-for-folder)) (not (check-for-file))) [(and (not (check-for-folder)) (not (check-for-file)))
(begin (begin
(d-hash-ref messages 'file-not-found) (display-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init))])) (display-hash-ref messages 'try-init))]))