changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/bin/skel.lisp

changeset 320: 3e3cce6ed1f0
parent: c5956756f9e5
child: 807018bcba4d
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 08 May 2024 23:13:13 -0400
permissions: -rw-r--r--
description: bugfix
1 ;;; Code:
2 (uiop:define-package :bin/skel
3  (:use :cl :std :cli/clap :vc :sb-ext)
4  (:use-reexport :skel :log)
5  (:export :main))
6 
7 (in-package :bin/skel)
8 (in-readtable :shell)
9 
10 (defopt skc-help (print-help $cli))
11 (defopt skc-version (print-version $cli))
12 (defopt skc-level *log-level* (setq *log-level* (or $val :info)))
13 
14 ;; TODO 2023-10-13: almost there
15 (defopt skc-config
16  (init-user-skelrc (when $val (parse-file-opt $val))))
17 
18 (defcmd skc-edit
19  (let ((file (or (when $args (pop $args)) (find-skelfile #P"."))))
20  (cli/ed:run-emacsclient (namestring file))))
21 
22 (defcmd skc-init
23  (let ((file (when $args (pop $args)))
24  (name (if (> $argc 1) (pop $args))))
25  (handler-bind
26  ((sb-ext:file-exists
27  #'(lambda (s)
28  (uiop:println (format nil "file already exists: ~A" (or file *default-skelfile*)))
29  (let ((f2 (read-line)))
30  (if (string= f2 "")
31  (error s)
32  (use-value f2 s))))))
33  (init-skelfile file name))))
34 
35 (defcmd skc-describe
36  (describe
37  (find-skelfile
38  (if $args (pathname (car $args))
39  #P".")
40  :load t)))
41 
42 (defcmd skc-inspect
43  (sb-ext:enable-debugger)
44  (inspect
45  (find-skelfile
46  (if $args (pathname (car $args))
47  #P".")
48  :load t)))
49 
50 (defcmd skc-id
51  (println (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t)))))
52 
53 (defun skc-show-case (sel)
54  (std/string:string-case (sel :default (nyi!))
55  (":id" (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t))))
56  (":config" (if (probe-file *user-skelrc*)
57  (describe (load-user-skelrc) t)
58  (describe *skel-user-config* nil)))
59  (":vc" (sk-vc (find-skelfile #P"." :load t)))
60  (":author" (sk-author (find-skelfile #P"." :load t)))
61  (":scripts" (sk-scripts (find-skelfile #P"." :load t)))
62  (":rules" (sk-rules (find-skelfile #P"." :load t)))
63  (":description" (sk-description (find-skelfile #P"." :load t)))
64  (":tags" (sk-tags (find-skelfile #P"." :load t)))
65  (":docs" (sk-docs (find-skelfile #P"." :load t)))
66  (":version" (sk-version (find-skelfile #P"." :load t)))
67  (":imports" (sk-imports (find-skelfile #P"." :load t)))
68  (":license" (sk-license (find-skelfile #P"." :load t)))
69  (":stash" (sk-stash (find-skelfile #P"." :load t)))
70  (":store" (sk-store (find-skelfile #P"." :load t)))
71  (":cache" (sk-cache (find-skelfile #P"." :load t)))))
72 
73 (defcmd skc-show
74  (if $args
75  (mapc (lambda (x) (when-let ((ret (skc-show-case x))) (println ret))) $args)
76  (describe (find-skelfile #P"." :load t))))
77 
78 (defcmd skc-push
79  (case (sk-vc (find-skelfile #P"." :load t))
80  (:hg (run-hg-command "push" $args t))))
81 
82 (defcmd skc-pull
83  (case (sk-vc (find-skelfile #P"." :load t))
84  (:hg (run-hg-command "pull" (push "-u" $args) t))))
85 
86 (defcmd skc-status
87  (case (sk-vc (find-skelfile #P"." :load t))
88  (:hg (progn
89  (let ((proc (run-hg-command "status" nil :stream)))
90  (copy-stream (process-output proc) *standard-output*)
91  (finish-output))))
92  (t (progn
93  (let ((proc (run-git-command "status" nil :stream)))
94  (copy-stream (process-output proc) *standard-output*)
95  (finish-output))))))
96 
97 (defcmd skc-make
98  (if $args
99  (mapc (lambda (rule) (debug! (sk-run (sk-find-rule rule (find-skelfile #P"." :load t))))) $args)
100  (debug! (sk-run (aref (sk-rules (find-skelfile #P"." :load t)) 0)))))
101 
102 (defcmd skc-run
103  (if $args
104  (mapc (lambda (script) (debug! (sk-run (sk-find-script script (find-skelfile #P"." :load t))))) $args)
105  (required-argument :script)))
106 
107 (defcmd skc-shell
108  (if $args
109  (nyi!)
110  (let ((*no-exit* t))
111  (in-package :skel)
112  (use-package :std-user)
113  ;; (sb-ext:enable-debugger)
114  (require :sb-aclrepl)
115  (init-skel-vars)
116  (sb-impl::toplevel-repl nil))))
117 
118 (define-cli $cli
119  :name "skel"
120  :version "0.1.1"
121  :description "A hacker's project compiler and build tool."
122  :thunk skc-describe
123  :opts (make-opts
124  (:name "help" :global t :description "print this message"
125  :thunk skc-help)
126  (:name "version" :global t :description "print version"
127  :thunk skc-version)
128  (:name "level" :global t :description "set log level (debug,info,trace,warn)"
129  :thunk skc-level)
130  (:name "config" :global t :description "set a custom skel user config" :kind file
131  :thunk skc-config)
132  (:name "input" :global t :description "input source" :kind string)
133  (:name "output" :global t :description "output target" :kind string))
134  :cmds (make-cmds
135  (:name init
136  :description "initialize a skelfile in the current directory"
137  :opts (make-opts (:name "name" :description "project name" :kind string))
138  :thunk skc-init)
139  (:name describe
140  :description "describe a skelfile"
141  :thunk skc-describe)
142  (:name show
143  :description "show project slots"
144  :opts (make-opts
145  (:name "file" :description "path to skelfile" :kind file)
146  (:name "user" :description "print user configuration")
147  (:name "system" :description "print system configuration"))
148  :thunk skc-show)
149  (:name id
150  :description "print the project id"
151  :thunk skc-id)
152  (:name inspect
153  :description "inspect the project skelfile"
154  :opts (make-opts (:name "file" :description "path to skelfile" :kind file))
155  :thunk skc-inspect)
156  (:name make
157  :description "build project targets"
158  :opts (make-opts (:name "target" :description "target to build" :kind string))
159  :thunk skc-make)
160  (:name run
161  :description "run a script or command"
162  :thunk skc-run)
163  (:name status
164  :description "print the vc status"
165  :thunk skc-status)
166  (:name push
167  :description "push the current project upstream"
168  :thunk skc-push)
169  (:name pull
170  :description "pull the current project from remote"
171  :thunk skc-pull)
172  (:name clone
173  :description "clone a remote project")
174  (:name commit
175  :description "commit changes to the project vc")
176  (:name edit
177  :description "edit a project file in emacs."
178  :thunk skc-edit)
179  (:name shell
180  :description "open the sk-shell interpreter"
181  :thunk skc-shell)))
182 
183 (defun run ()
184  (let ((*log-level* :info))
185  (in-readtable :shell)
186  (with-cli (opts cmds) $cli
187  (load-skelrc)
188  ;; TODO 2024-01-01: need to parse out CMD opts from args slot - they still there
189  (do-opt (find-opt $cli "level"))
190  (do-cmd $cli)
191  (debug-opts $cli))))
192 
193 (defmain ()
194  (run)
195  (sb-ext:exit :code 0))