changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/bin/organ.lisp

changeset 647: 74e563ed4537
parent: 35bb0d5ec95e
child: 692dfd7f02d0
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 11 Sep 2024 21:40:01 -0400
permissions: -rw-r--r--
description: cli and rt/fuzz
1 ;;; organ.lisp --- Org-mode utility
2 
3 ;;
4 
5 ;;; Code:
6 (defpackage :bin/organ
7  (:use :cl :organ :std :cli :log :clap)
8  (:export :main))
9 
10 (in-package :bin/organ)
11 (defopt organ-help (print-help *cli*))
12 (defopt organ-version (print-version *cli*))
13 (defopt organ-log-level (setq *log-level* (if *arg* t :info)))
14 ;; (defopt organ-output (when *arg* (trace! (or *arg* "output.organ"))))
15 (defcmd organ-describe
16  (if *args*
17  ;; TODO typed args
18  (describe (org-parse :document (pathname (car *args*))))
19  (describe (org-parse :document #P"readme.org"))))
20 
21 (defcmd organ-inspect
22  (if *args*
23  ;; TODO typed args
24  (inspect (org-parse :document (pathname (car *args*))))
25  (inspect (org-parse :document #P"readme.org"))))
26 
27 (defcmd organ-show
28  (if *args*
29  (print (org-parse-lines t (uiop:read-file-string (car *args*))))
30  (error! "missing file arg")))
31 
32 (defcmd organ-parse
33  (let ((input (if *args* (car *args*) #P"readme.org")))
34  (describe (org-parse :document input))))
35 
36 (define-cli *cli*
37  :name "organ"
38  :version "0.0.1"
39  :description "org-mode toolbox"
40  :thunk 'organ-describe
41  :opts ((:name "level" :global t :description "set the log level" :thunk organ-log-level)
42  (:name "help" :global t :description "print help" :thunk organ-help)
43  (:name "version" :global t :description "print version" :thunk organ-version)
44  ;; (:name "output" :description "output file" :kind file :thunk organ-output)
45  )
46  :cmds ((:name inspect
47  :description "inspect an org file"
48  :thunk organ-inspect)
49  (:name show
50  :description "display local org info"
51  :thunk organ-show)
52  (:name describe
53  :description "describe local org info"
54  :thunk organ-describe)
55  (:name parse
56  :thunk organ-parse)))
57 
58 (defun run ()
59  (let ((*log-level* :info))
60  (with-cli (*cli* opts cmds args) ()
61  (do-cmd *cli*)
62  (debug-opts *cli*))))
63 
64 (defmain ()
65  (run)
66  (sb-ext:exit :code 0))