changeset 662: |
a53be64410c5 |
parent: |
65102f74d1ae
|
child: |
cc89b337384b |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sat, 21 Sep 2024 18:18:14 -0400 |
permissions: |
-rw-r--r-- |
description: |
removed skel project env/def, added to BIND |
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 (defopt skc-config (load-user-skelrc (or *arg* *user-skelrc*))) 27 (let ((file (or (when *args* (pop *args*)) (sk-path *skel-project*)))) 28 (cli/ed:run-emacsclient (namestring file)))) 31 (let ((file (when *args* (pop *args*))) 32 (name (when (> *argc* 1) (pop *args*)))) 33 ;; TODO: test, may need to be 34 ;; sequential for side-effect 39 (std:println (format nil "file already exists: ~A" (or file *default-skelfile*))) 40 (let ((f2 (read-line))) 44 (init-skelfile file name)))) 49 (find-skelfile (pathname (car *args*)) :load t) 50 (or *skel-project* *skel-user-config* *skel-system-config*)))) 54 (sb-ext:enable-debugger) 58 (if *args* (pathname (car *args*)) 65 (let ((stuff (loop for a in *args* 66 collect (sk-slot-case a)))) 67 (sk-view (if (= 1 (length stuff)) (car stuff) stuff))) 68 (sk-view (if (boundp '*skel-project*) *skel-project* 69 (if (boundp '*skel-user-config*) *skel-user-config* 70 (if (boundp '*skel-system-config*) *skel-system-config* 71 (skel-simple-error "skel config files not installed"))))))) 74 (println (std:format-sxhash (obj/id:id (find-skelfile #P"." :load t))))) 76 (defun call-with-args (action args) 77 (let* ((*default-pathname-defaults* *skel-path*)) 79 (sk-call *skel-project* action) 81 (sk-call *skel-project* (keywordicate (symbol-name action) '- (string-upcase x)))) 85 (call-with-args :compile *args*)) 87 (call-with-args :build *args*)) 89 (call-with-args :dist *args*)) 91 (call-with-args :install *args*)) 93 (call-with-args :pack *args*)) 95 (call-with-args :unpack *args*)) 97 (call-with-args :bundle *args*)) 99 (call-with-args :unbundle *args*)) 101 (call-with-args :clean *args*)) 103 (call-with-args :test *args*)) 105 (call-with-args :bench *args*)) 107 (call-with-args :save *args*)) 109 (defun sk-slot-case (sel) 110 (std/string:string-case ((string-left-trim ":" sel) :default (skel-simple-error "invalid slot")) 111 ("id" (std:format-sxhash (obj/id:id *skel-project*))) 112 ("name" (sk-name *skel-project*)) 113 ("author" (sk-author *skel-project*)) 114 ("version" (sk-version *skel-project*)) 115 ("description" (sk-description *skel-project*)) 116 ("tags" (sk-tags *skel-project*)) 117 ("license" (sk-license *skel-project*)) 118 ("vc" (sk-vc *skel-project*)) 119 ("components" (sk-components *skel-project*)) 120 ("scripts" (sk-scripts *skel-project*)) 121 ("rules" (sk-rules *skel-project*)) 122 ("phases" (hash-table-alist (sk-phases *skel-project*))) 123 ;; ("env" (sk-env *skel-project*)) 124 ("bind" (sk-bind *skel-project*)) 125 ("include" (sk-include *skel-project*)) 126 ("stash" (sk-stash *skel-project*)) 127 ("store" (sk-store *skel-project*)) 128 ("config" *skel-user-config*) 129 ("sys" *skel-system-config*) 130 ("cache" (sk-cache *skel-user-config*)))) 134 (mapc (lambda (x) (when-let ((ret (sk-slot-case x))) (println ret))) *args*) 135 (describe (if (boundp '*skel-project*) *skel-project* 136 (if (boundp '*skel-user-config*) *skel-user-config* 137 (if (boundp '*skel-system-config*) *skel-system-config* 138 (skel-simple-error "skel config files not installed"))))))) 141 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 142 (:git (run-git-command "push" *args* t)) 143 (:hg (run-hg-command "push" *args* t)) 144 (t (skel-simple-error "unknown VC type")))) 147 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 148 (:git (run-git-command "pull" *args* t)) 149 (:hg (run-hg-command "pull" (append '("-u") *args*) t)) 150 (t (skel-simple-error "unknown VC type")))) 153 (with-open-stream (proc (process-output (run-hg-command "status" nil :stream))) 154 (loop for x = (read-line proc nil) 159 (with-open-stream (proc (run-git-command "status" nil :stream)) 160 (loop for x = (read-line proc nil) 165 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 171 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 172 (:git (run-git-command "clone" *args* t)) 173 (:hg (run-hg-command "clone" *args* t)) 174 (t (skel-simple-error "unknown VC type")))) 177 (case (sk-vc-meta-kind (sk-vc (find-skelfile #P"." :load t))) 178 (:git (run-git-command "commit" (append '("-m") *args*) t)) 179 (:hg (run-hg-command "commit" (when *args* (append '("-m") *args*)) t)) 180 (t (skel-simple-error "unknown VC type")))) 183 (let ((sk (find-skelfile #P"." :load t))) 184 (sb-ext:enable-debugger) 185 (log:debug! "cli args" *args*) 186 ;; (setq *no-exit* t) 188 (loop for a in *args* 190 (if-let ((rule (sk-find-rule a sk))) 192 ;; TODO 2024-08-23: restart condition here 193 (skel-simple-error "rule not found: ~A" a)))) 194 (debug! (sk-make sk (aref (sk-rules sk) 0)))))) 198 (mapc (lambda (script) 199 ;; first check if a script with the same name exists, else check for a rule definition 200 (if-let ((script (sk-find-script 201 (pathname-name script) 202 (find-skelfile #P"." :load t)))) 204 (call-with-args :run (list script)))) 206 (required-argument 'name))) 210 (std/string:string-case ((car *args*) :default (skel-simple-error "invalid command")) 211 ("status" (skc-status nil nil))) 212 (skc-status nil *opts*))) 215 (sb-ext:enable-debugger) 216 (trace! "starting skel shell") 218 (cli/clap::with-cli-handlers 220 (in-package :sk-user) 221 (use-package :cl-user) 222 (use-package :sb-ext) 223 (use-package :std-user) 225 (println "Welcome to SKEL") 226 (sb-impl::toplevel-repl nil)))) 232 (define-cli *skel-cli* 234 :version #.(format nil "0.1.1:~A" (read-line (sb-ext:process-output (vc:run-hg-command "id" '("-i") :stream)))) 235 :description "A hacker's project compiler." 237 :opts ((:name "help" :global t :description "print this message" 239 (:name "version" :global t :description "print version" 241 (:name "level" :global t :description "set log level (warn,info,debug,trace)" 243 (:name "config" :global t :description "set a custom skel user config" :kind file) 244 (:name "input" :global t :description "input source" :kind string) 245 (:name "output" :global t :description "output target" :kind string)) 247 :description "initialize a skelfile in the current directory" 248 :opts (:name "name" :description "project name" :kind string) 251 :description "make a new skel project" 252 :opts ((:name "name" :description "project name" :kind string)) 255 :description "describe a skelfile" 258 :description "show project slots" 259 :opts ((:name "file" :description "path to skelfile" :kind file)) 262 :description "version control" 264 :opts ((:name "root" :description "repository path" :kind directory))) 266 :description "print the project id" 269 :description "inspect the project skelfile" 270 :opts ((:name "file" :description "path to skelfile" :kind file)) 274 :description "view an object in a new GUI window" 277 :description "build project targets" 278 :opts ((:name "target" :description "target to build" :kind string)) 281 :description "run a script or command" 284 :description "compile source code" 287 :description "build programs and libraries" 290 :description "save a file" 293 :description "distribute build artifacts" 296 :description "install stuff" 299 :description "pack stuff" 302 :description "unpack stuff" 305 :description "bundle source code" 308 :description "unbundle source code" 311 :description "clean up the project" 314 :description "run tests" 317 :description "run benchmark" 320 :description "print the vc status" 323 :description "push the current project upstream" 326 :description "pull the current project from remote" 329 :description "clone a remote project" 332 :description "commit changes to the project vc" 334 :opts ((:name "message" :description "commit message" :kind string))) 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) 348 (when-let ((project (find-skelfile #P"."))) 349 (let ((*default-pathname-defaults* (pathname (directory-namestring project)))) 350 (setq *skel-project* (load-skelfile project)) 351 (setq *skel-path* (sk-src *skel-project*)) 352 (setq cli/shell:*shell-directory* (sk-src *skel-project*)))) 354 (debug-opts *cli*))))