Phase 2, first part: values and value commands
- Values are Json of (text json); a record is JsonFields. - Value commands: files, procs, open, where, select, get, sort-by, first, last, count, reverse, uniq, lines, from-json, to-json, from-csv, to-csv, each with a short name. - Value commands next to each other run as one unit: a (std run) filter in a job, or in the shell when a line has no program. - Records are shown as a table; values go to programs as lines. - A name is a shell command, a short name, a program on PATH, then a long name. - 2>&1, with >FILE 2>&1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3518b7711d
commit
027acc84e6
12 changed files with 1142 additions and 37 deletions
|
|
@ -14,6 +14,7 @@
|
|||
(import (std run))
|
||||
(import (bjoterm line))
|
||||
(import (bjosh shell))
|
||||
(import (bjosh commands))
|
||||
|
||||
(export builtin? run-builtin builtin-names find-program)
|
||||
|
||||
|
|
@ -204,15 +205,31 @@
|
|||
(cond
|
||||
((builtin? name) (println (str name " is a shell command")) 0)
|
||||
(else
|
||||
(match (find-program name)
|
||||
((Some path) (println (str name " is " path)) 0)
|
||||
(None (shell-error (str "type: " name ": not found")) 1)))))))
|
||||
(match (value-command name (fun (n) (some? (find-program n))))
|
||||
((Some c)
|
||||
(println (str name " is a value command: "
|
||||
(record-ref c long) ", " (record-ref c short)))
|
||||
0)
|
||||
(None
|
||||
(match (find-program name)
|
||||
((Some path) (println (str name " is " path)) 0)
|
||||
(None (shell-error (str "type: " name ": not found")) 1)))))))))
|
||||
|
||||
(: (-> Builtin string))
|
||||
(defun (builtin-help-line b)
|
||||
(str " " (string-pad-right (record-ref b usage) 28) (record-ref b help)))
|
||||
|
||||
(: (-> ValueCommand string))
|
||||
(defun (value-help-line c)
|
||||
(str " " (string-pad-right (record-ref c usage) 26) (string-pad-right (record-ref c short) 5) (record-ref c help)))
|
||||
|
||||
(: (-> Shell (Vec string) int))
|
||||
(defun (help sh args)
|
||||
(for-each (fun (b)
|
||||
(println (str (string-pad-right (record-ref b usage) 28) (record-ref b help))))
|
||||
(builtins))
|
||||
(println "Shell commands:")
|
||||
(for-each (fun (b) (println (builtin-help-line b))) (builtins))
|
||||
(println "")
|
||||
(println "Value commands, by long and short name. A long name that is a program runs the program.")
|
||||
(for-each (fun (c) (println (value-help-line c))) (value-commands))
|
||||
0)
|
||||
|
||||
(: (-> Shell (Vec string) int))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue