changeset 647: |
74e563ed4537 |
parent: |
3e6a17fb5712
|
child: |
af486e0a40c9 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Wed, 11 Sep 2024 21:40:01 -0400 |
permissions: |
-rw-r--r-- |
description: |
cli and rt/fuzz |
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) 14 (in-package :bin/skel) 17 (defopt skc-help (print-help *cli*)) 18 (defopt skc-version (print-version *cli*)) 19 (defopt skc-level *log-level* 20 (setq *log-level* (if *arg* (if (stringp *arg*) 21 (sb-int:keywordicate (string-upcase *arg*)) 25 ;; TODO 2023-10-13: almost there 32 (let ((file (or (when *args* (pop *args*)) (sk-path *skel-project*)))) 33 (cli/ed:run-emacsclient (namestring file)))) 36 (let ((file (when *args* (pop *args*))) 37 (name (when (> *argc* 1) (pop *args*)))) 38 ;; TODO: test, may need to be 39 ;; sequential for side-effect 44 (std:println (format nil "file already exists: ~A" (or file *default-skelfile*))) 45 (let ((f2 (read-line))) 49 (init-skelfile file name)))) 54 (find-skelfile (pathname (car *args*)) :load t) 55 (or *skel-project* *skel-user-config* *skel-system-config*)))) 59 (sb-ext:enable-debugger) 63 (if *args* (pathname (car *args*)) 70 (let ((stuff (loop for a in *args* 71 collect (sk-slot-case a)))) 72 (sk-view (if (= 1 (length stuff)) (car stuff) stuff))) 73 (sk-view (if (boundp '*skel-project*) *skel-project* 74 (if (boundp '*skel-user-config*) *skel-user-config* 75 (if (boundp '*skel-system-config*) *skel-system-config* 76 (skel-simple-error "skel config files not installed"))))))) 79 (println (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t))))) 81 (defun call-with-args (action args) 82 (let* ((*default-pathname-defaults* *skel-path*)) 84 (sk-call *skel-project* action) 86 (sk-call *skel-project* (keywordicate action '- (string-upcase x)))) 90 (call-with-args :compile *args*)) 92 (call-with-args :build *args*)) 94 (call-with-args :dist *args*)) 96 (call-with-args :install *args*)) 98 (call-with-args :pack *args*)) 100 (call-with-args :unpack *args*)) 102 (call-with-args :bundle *args*)) 104 (call-with-args :unbundle *args*)) 106 (call-with-args :clean *args*)) 108 (call-with-args :test *args*)) 110 (call-with-args :bench *args*)) 112 (call-with-args :save *args*)) 114 (defun sk-slot-case (sel) 115 (std/string:string-case (sel :default (skel-simple-error "invalid slot")) 116 (":id" (std:format-sxhash (obj/id:id *skel-project*))) 117 (":name" (sk-name *skel-project*)) 118 (":author" (sk-author *skel-project*)) 119 (":version" (sk-version *skel-project*)) 120 (":description" (sk-description *skel-project*)) 121 (":tags" (sk-tags *skel-project*)) 122 (":license" (sk-license *skel-project*)) 123 (":vc" (sk-vc *skel-project*)) 124 (":components" (sk-components *skel-project*)) 125 (":scripts" (sk-scripts *skel-project*)) 126 (":rules" (sk-rules *skel-project*)) 127 (":phases" (hash-table-alist (sk-phases *skel-project*))) 128 (":env" (sk-env *skel-project*)) 129 (":bind" (sk-bind *skel-project*)) 130 (":include" (sk-include *skel-project*)) 131 (":stash" (sk-stash *skel-project*)) 132 (":store" (sk-store *skel-project*)) 133 (":config" *skel-user-config*) 134 (":sys" *skel-system-config*) 135 (":cache" (sk-cache *skel-user-config*)))) 139 (mapc (lambda (x) (when-let ((ret (sk-slot-case x))) (println ret))) *args*) 140 (describe (if (boundp '*skel-project*) *skel-project* 141 (if (boundp '*skel-user-config*) *skel-user-config* 142 (if (boundp '*skel-system-config*) *skel-system-config* 143 (skel-simple-error "skel config files not installed"))))))) 146 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 147 (:git (run-git-command "push" *args* t)) 148 (:hg (run-hg-command "push" *args* t)) 149 (t (skel-simple-error "unknown VC type")))) 152 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 153 (:git (run-git-command "pull" *args* t)) 154 (:hg (run-hg-command "pull" (append '("-u") *args*) t)) 155 (t (skel-simple-error "unknown VC type")))) 158 (with-open-stream (proc (process-output (run-hg-command "status" nil :stream))) 159 (loop for x = (read-line proc nil) 164 (with-open-stream (proc (run-git-command "status" nil :stream)) 165 (loop for x = (read-line proc nil) 170 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 176 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 177 (:git (run-git-command "clone" *args* t)) 178 (:hg (run-hg-command "clone" *args* t)) 179 (t (skel-simple-error "unknown VC type")))) 182 ;; (debug! *optc* *argc*) 183 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 184 (:git (run-git-command "commit" *args* t)) 185 (:hg (run-hg-command "commit" *args* t)) 186 (t (skel-simple-error "unknown VC type")))) 189 (let ((sk (find-skelfile #P"." :load t))) 190 (sb-ext:enable-debugger) 191 (log:debug! "cli args" *args*) 192 ;; (setq *no-exit* t) 194 (loop for a in *args* 196 (if-let ((rule (sk-find-rule a sk))) 198 ;; TODO 2024-08-23: restart condition here 199 (skel-simple-error "rule not found: ~A" a)))) 200 (debug! (sk-make sk (aref (sk-rules sk) 0)))))) 204 (mapc (lambda (script) 205 (when-let ((script (sk-find-script 206 (pathname-name script) 207 (find-skelfile #P"." :load t)))) 208 (debug! (sk-run script)))) 210 (required-argument 'name))) 214 (std/string:string-case ((car *args*) :default (skel-simple-error "invalid command")) 215 ("status" (skc-status nil nil))) 216 (skc-status nil *opts*))) 219 (sb-ext:enable-debugger) 220 (trace! "starting skel shell") 222 (cli/clap::with-cli-handlers 224 (in-package :sk-user) 225 (use-package :cl-user) 226 (use-package :sb-ext) 227 (use-package :std-user) 229 (println "Welcome to SKEL") 230 (sb-impl::toplevel-repl nil)))) 233 (trace! *args* *opts*)) 237 :version #.(format nil "0.1.1:~A" (read-line (sb-ext:process-output (vc:run-hg-command "id" '("-i") :stream)))) 238 :description "A hacker's project compiler." 240 :opts ((:name "help" :global t :description "print this message" 242 (:name "version" :global t :description "print version" 244 (:name "level" :global t :description "set log level (warn,info,debug,trace)" 246 (:name "config" :global t :description "set a custom skel user config" :kind file) 247 (:name "input" :global t :description "input source" :kind string) 248 (:name "output" :global t :description "output target" :kind string)) 250 :description "initialize a skelfile in the current directory" 251 :opts (:name "name" :description "project name" :kind string) 254 :description "make a new skel project" 255 :opts ((:name "name" :description "project name" :kind string)) 258 :description "describe a skelfile" 261 :description "show project slots" 262 :opts ((:name "file" :description "path to skelfile" :kind file) 263 (:name "user" :description "print user configuration") 264 (:name "system" :description "print system configuration")) 267 :description "version control" 269 :opts ((:name "root" :description "repository path" :kind directory))) 271 :description "print the project id" 274 :description "inspect the project skelfile" 275 :opts ((:name "file" :description "path to skelfile" :kind file)) 279 :description "view an object in a new GUI window" 282 :description "build project targets" 283 :opts ((:name "target" :description "target to build" :kind string)) 286 :description "run a script or command" 289 :description "compile source code" 292 :description "build programs and libraries" 295 :description "distribute build artifacts" 298 :description "install stuff" 301 :description "pack stuff" 304 :description "unpack stuff" 307 :description "bundle source code" 310 :description "unbundle source code" 313 :description "clean up the project" 316 :description "run tests" 319 :description "run benchmark" 322 :description "print the vc status" 325 :description "push the current project upstream" 328 :description "pull the current project from remote" 331 :description "clone a remote project" 334 :description "commit changes to the project vc" 337 :description "edit a project file in emacs." 340 :description "open the sk-shell interpreter" 344 (in-package :sk-user) 345 (let ((*log-level* :info)) 346 (in-readtable :shell) 347 (with-cli (*cli* opts cmds) (cli:args) 350 (when-let ((project (find-skelfile #P"."))) 351 (let ((*default-pathname-defaults* (pathname (directory-namestring project)))) 352 (setq *skel-project* (load-skelfile project)) 353 (setq *skel-path* (sk-src *skel-project*)) 354 (setq *shell-directory* (sk-src *skel-project*))))