-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssdoc.scm
99 lines (81 loc) · 2.64 KB
/
ssdoc.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env gsi-script
;;!!! SSDoc documentation system for SchemeSpheres
;; .author Alvaro Castro-Castilla, 2014
;; Debugging notes:
;; 1) Uncomment shebang line
;; 2) Comment the last line to avoid running main twice
(include "arguments.scm")
(include "minimal.scm")
(define *help:general* #<<end-help-string
Usage: ssdoc [command] [operand]
Commands:
search [string] [flags]
search the documentation for functions and des
-f Include functions in search (default if nothing else)
-d Include descriptions in search
generate [flags]
generate documentation for local libraries
-p List of paths separated by colon (:)
update (not implemented)
pull an updated documentation file of all packages
end-help-string
)
;; Flag listing
;; 1 means that takes an argument, 0 it doesn't
(define *options*
'((#\f 0 "functions")
(#\d 0 "descriptions")
(#\p 1 "paths")))
;; Command: HELP
(define (help-cmd cmd opts args)
(define help-topics
`(("search" ,@*help:general*)
("generate" ,@*help:general*)
("update" ,@*help:general*)))
(define num-args (length args))
(handle-opts! opts `(("help" ,@(lambda (val) #t))))
(cond
((zero? num-args) (println *help:general*))
((= 1 num-args)
(let* ((arg (car args))
(res (assoc arg help-topics)))
(if res
(println (cdr res))
(die/error "Unknown help topic:" arg))))
(else
(die/error "Invalid arguments passed to help:" args))))
;; Command: SEARCH
(define (search-cmd cmd opts args)
'search)
;; Command: GENERATE
(define (generate-cmd cmd opts args)
'generate)
;; Command: UPDATE
(define (update-cmd cmd opts args)
'update)
;; Command Unknown
(define (unknown-cmd cmd opts args-sans-opts)
(die/error "Unknown command:"
cmd "-- To get a list of options, type 'ssdoc help'"))
(define (main . args)
(let ((commands
`(("help" ,@help-cmd)
("search" ,@search-cmd)
("generate" ,@generate-cmd)
("update" ,@update-cmd)
("unknown-command" ,@unknown-cmd))))
(parse-arguments
args
(lambda (actual-args-sans-opts opts)
(let* ((args-sans-opts (if (null? actual-args-sans-opts)
'("help")
actual-args-sans-opts))
(cmd-pair (assoc (car args-sans-opts) commands))
(cmd (if cmd-pair
(cdr cmd-pair)
(cdr (assoc "unknown-command" commands)))))
(cmd (car args-sans-opts)
opts
(cdr args-sans-opts))))
*options*)))
;;(apply main (cdr (command-line)))