changeset 651: |
af486e0a40c9 |
parent: |
74e563ed4537
|
child: |
328e1ff73938 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sat, 14 Sep 2024 22:13:06 -0400 |
permissions: |
-rw-r--r-- |
description: |
multi-binaries, working on removing x.lisp |
3 ;; TODO 2024-05-09: add shell configurables to rules - maybe at sk-command 4 ;; level. :INPUT :WAIT :OUTPUT 8 :vc :sb-ext :skel :log :cli/clap/util 9 :dat/sxp #+tools :skel/tools/viz) 10 (:import-from :cli/shell :*shell-input* :*shell-directory*) 11 (:use :cli/tools/sbcl)) 13 (in-package :bin/skel) 16 (defopt skc-help (print-help *cli*)) 17 (defopt skc-version (print-version *cli*)) 18 (defopt skc-level *log-level* 19 (setq *log-level* (if *arg* (if (stringp *arg*) 20 (sb-int:keywordicate (string-upcase *arg*)) 24 ;; TODO 2023-10-13: almost there 31 (let ((file (or (when *args* (pop *args*)) (sk-path *skel-project*)))) 32 (cli/ed:run-emacsclient (namestring file)))) 35 (let ((file (when *args* (pop *args*))) 36 (name (when (> *argc* 1) (pop *args*)))) 37 ;; TODO: test, may need to be 38 ;; sequential for side-effect 43 (std:println (format nil "file already exists: ~A" (or file *default-skelfile*))) 44 (let ((f2 (read-line))) 48 (init-skelfile file name)))) 53 (find-skelfile (pathname (car *args*)) :load t) 54 (or *skel-project* *skel-user-config* *skel-system-config*)))) 58 (sb-ext:enable-debugger) 62 (if *args* (pathname (car *args*)) 69 (let ((stuff (loop for a in *args* 70 collect (sk-slot-case a)))) 71 (sk-view (if (= 1 (length stuff)) (car stuff) stuff))) 72 (sk-view (if (boundp '*skel-project*) *skel-project* 73 (if (boundp '*skel-user-config*) *skel-user-config* 74 (if (boundp '*skel-system-config*) *skel-system-config* 75 (skel-simple-error "skel config files not installed"))))))) 78 (println (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t))))) 80 (defun call-with-args (action args) 81 (let* ((*default-pathname-defaults* *skel-path*)) 83 (sk-call *skel-project* action) 85 (sk-call *skel-project* (keywordicate action '- (string-upcase x)))) 89 (call-with-args :compile *args*)) 91 (call-with-args :build *args*)) 93 (call-with-args :dist *args*)) 95 (call-with-args :install *args*)) 97 (call-with-args :pack *args*)) 99 (call-with-args :unpack *args*)) 101 (call-with-args :bundle *args*)) 103 (call-with-args :unbundle *args*)) 105 (call-with-args :clean *args*)) 107 (call-with-args :test *args*)) 109 (call-with-args :bench *args*)) 111 (call-with-args :save *args*)) 113 (defun sk-slot-case (sel) 114 (std/string:string-case (sel :default (skel-simple-error "invalid slot")) 115 (":id" (std:format-sxhash (obj/id:id *skel-project*))) 116 (":name" (sk-name *skel-project*)) 117 (":author" (sk-author *skel-project*)) 118 (":version" (sk-version *skel-project*)) 119 (":description" (sk-description *skel-project*)) 120 (":tags" (sk-tags *skel-project*)) 121 (":license" (sk-license *skel-project*)) 122 (":vc" (sk-vc *skel-project*)) 123 (":components" (sk-components *skel-project*)) 124 (":scripts" (sk-scripts *skel-project*)) 125 (":rules" (sk-rules *skel-project*)) 126 (":phases" (hash-table-alist (sk-phases *skel-project*))) 127 (":env" (sk-env *skel-project*)) 128 (":bind" (sk-bind *skel-project*)) 129 (":include" (sk-include *skel-project*)) 130 (":stash" (sk-stash *skel-project*)) 131 (":store" (sk-store *skel-project*)) 132 (":config" *skel-user-config*) 133 (":sys" *skel-system-config*) 134 (":cache" (sk-cache *skel-user-config*)))) 138 (mapc (lambda (x) (when-let ((ret (sk-slot-case x))) (println ret))) *args*) 139 (describe (if (boundp '*skel-project*) *skel-project* 140 (if (boundp '*skel-user-config*) *skel-user-config* 141 (if (boundp '*skel-system-config*) *skel-system-config* 142 (skel-simple-error "skel config files not installed"))))))) 145 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 146 (:git (run-git-command "push" *args* t)) 147 (:hg (run-hg-command "push" *args* t)) 148 (t (skel-simple-error "unknown VC type")))) 151 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 152 (:git (run-git-command "pull" *args* t)) 153 (:hg (run-hg-command "pull" (append '("-u") *args*) t)) 154 (t (skel-simple-error "unknown VC type")))) 157 (with-open-stream (proc (process-output (run-hg-command "status" nil :stream))) 158 (loop for x = (read-line proc nil) 163 (with-open-stream (proc (run-git-command "status" nil :stream)) 164 (loop for x = (read-line proc nil) 169 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 175 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 176 (:git (run-git-command "clone" *args* t)) 177 (:hg (run-hg-command "clone" *args* t)) 178 (t (skel-simple-error "unknown VC type")))) 181 ;; (debug! *optc* *argc*) 182 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 183 (:git (run-git-command "commit" *args* t)) 184 (:hg (run-hg-command "commit" *args* t)) 185 (t (skel-simple-error "unknown VC type")))) 188 (let ((sk (find-skelfile #P"." :load t))) 189 (sb-ext:enable-debugger) 190 (log:debug! "cli args" *args*) 191 ;; (setq *no-exit* t) 193 (loop for a in *args* 195 (if-let ((rule (sk-find-rule a sk))) 197 ;; TODO 2024-08-23: restart condition here 198 (skel-simple-error "rule not found: ~A" a)))) 199 (debug! (sk-make sk (aref (sk-rules sk) 0)))))) 203 (mapc (lambda (script) 204 (when-let ((script (sk-find-script 205 (pathname-name script) 206 (find-skelfile #P"." :load t)))) 207 (debug! (sk-run script)))) 209 (required-argument 'name))) 213 (std/string:string-case ((car *args*) :default (skel-simple-error "invalid command")) 214 ("status" (skc-status nil nil))) 215 (skc-status nil *opts*))) 218 (sb-ext:enable-debugger) 219 (trace! "starting skel shell") 221 (cli/clap::with-cli-handlers 223 (in-package :sk-user) 224 (use-package :cl-user) 225 (use-package :sb-ext) 226 (use-package :std-user) 228 (println "Welcome to SKEL") 229 (sb-impl::toplevel-repl nil)))) 232 (trace! *args* *opts*)) 234 (define-cli *skel-cli* 236 :version #.(format nil "0.1.1:~A" (read-line (sb-ext:process-output (vc:run-hg-command "id" '("-i") :stream)))) 237 :description "A hacker's project compiler." 239 :opts ((:name "help" :global t :description "print this message" 241 (:name "version" :global t :description "print version" 243 (:name "level" :global t :description "set log level (warn,info,debug,trace)" 245 (:name "config" :global t :description "set a custom skel user config" :kind file) 246 (:name "input" :global t :description "input source" :kind string) 247 (:name "output" :global t :description "output target" :kind string)) 249 :description "initialize a skelfile in the current directory" 250 :opts (:name "name" :description "project name" :kind string) 253 :description "make a new skel project" 254 :opts ((:name "name" :description "project name" :kind string)) 257 :description "describe a skelfile" 260 :description "show project slots" 261 :opts ((:name "file" :description "path to skelfile" :kind file) 262 (:name "user" :description "print user configuration") 263 (:name "system" :description "print system configuration")) 266 :description "version control" 268 :opts ((:name "root" :description "repository path" :kind directory))) 270 :description "print the project id" 273 :description "inspect the project skelfile" 274 :opts ((:name "file" :description "path to skelfile" :kind file)) 278 :description "view an object in a new GUI window" 281 :description "build project targets" 282 :opts ((:name "target" :description "target to build" :kind string)) 285 :description "run a script or command" 288 :description "compile source code" 291 :description "build programs and libraries" 294 :description "distribute build artifacts" 297 :description "install stuff" 300 :description "pack stuff" 303 :description "unpack stuff" 306 :description "bundle source code" 309 :description "unbundle source code" 312 :description "clean up the project" 315 :description "run tests" 318 :description "run benchmark" 321 :description "print the vc status" 324 :description "push the current project upstream" 327 :description "pull the current project from remote" 330 :description "clone a remote project" 333 :description "commit changes to the project vc" 336 :description "edit a project file in emacs." 339 :description "open the sk-shell interpreter" 342 (defmain start-skel () 343 (in-package :sk-user) 344 (let ((*log-level* :info)) 345 (in-readtable :shell) 346 (with-cli (*skel-cli* opts cmds) (cli:args) 349 (when-let ((project (find-skelfile #P"."))) 350 (let ((*default-pathname-defaults* (pathname (directory-namestring project)))) 351 (setq *skel-project* (load-skelfile project)) 352 (setq *skel-path* (sk-src *skel-project*)) 353 (setq cli/shell:*shell-directory* (sk-src *skel-project*))))