1+ import { parseArgs } from 'util'
12import { either , option , type Option } from '../../adts.js'
23import { writeJSON } from '../cli/output.js'
34import { keywordHandlers as compilerKeywordHandlers } from '../compiling.js'
@@ -22,6 +23,48 @@ const unserializableFunction = () =>
2223 } )
2324
2425const runtimeContext = makeObjectNode ( {
26+ arguments : makeObjectNode ( {
27+ lookup : makeFunctionNode (
28+ {
29+ parameter : types . string ,
30+ return : types . option ( types . string ) ,
31+ } ,
32+ unserializableFunction ,
33+ option . none ,
34+ key => {
35+ if ( typeof key !== 'string' ) {
36+ return either . makeLeft ( {
37+ kind : 'panic' ,
38+ message : 'key was not an atom' ,
39+ } )
40+ } else {
41+ const { values : argumentValues } = parseArgs ( {
42+ args : process . argv ,
43+ strict : false ,
44+ options : {
45+ [ key ] : { type : 'string' } ,
46+ } ,
47+ } )
48+ const argument = argumentValues [ key ]
49+ if ( typeof argument !== 'string' ) {
50+ return either . makeRight (
51+ makeObjectNode ( {
52+ tag : 'none' ,
53+ value : makeObjectNode ( { } ) ,
54+ } ) ,
55+ )
56+ } else {
57+ return either . makeRight (
58+ makeObjectNode ( {
59+ tag : 'some' ,
60+ value : argument ,
61+ } ) ,
62+ )
63+ }
64+ }
65+ } ,
66+ ) ,
67+ } ) ,
2568 environment : makeObjectNode ( {
2669 lookup : makeFunctionNode (
2770 {
0 commit comments