Runtime library interfaces for command-line applications ======================================================== See also `environment_variables.txt` Maybe the aspects of command-line libraries should be some injected objects. Low level interface: CommandMain "mycommand" inject CommandEnvironment env inject CommandParameters params inject CommandExitStatus exitstatus entry main end High level interface: CommandMain "mycommand" # XXX should it be possible to inject environment variables # into classes? maybe it's safer/clearer to not allow that? inject String target = from_environment "TARGET" inject ?Dir sourcedir = from_commandparam "--srcdir" "-s" # shorter syntax: inject ?String target = from_environment "TARGET" ?Dir sourcedir = from_commandparam "--srcdir" "-s" OutStream stdout = from_stdout OutStream stderr = from_stderr CommandExiter exiter = from_system end # even shorter syntax, with implied "constructor" names: # could even only allow one `inject` block to prevent obfuscated code. inject ?String target environ "TARGET" ?Dir sourcedir cmdparam "--srcdir" "-s" # using default "constructor" OutStream stdout OutStream stderr CmdExiter exiter # capabilities can be specified here, too NativeBinary somebinary with # scoping rules could make this possible stderr = stderr # multi-valued parameters? filesystem = read "/" filesystem = writeonly_tempdir exec = "somebinary" # looked up in PATH end end entry main CapabilityWrapper cw = new cw.add "stderr" stderr cw.add "somebinary" somebinary SomeOperation op = new cw op.run sourcedir target end Alternative name of the `inject` keyword? inject require demand environment env system request params parameters parametric config configuration unbound free dynamic hosted from_host provided (ok) need (ok) needed giveme (best?) Handling injection errors ------------------------- giveme String name httpparam File data resource_directory "data" else # these are specific implementations of services MyMissingHttpParam new "this_page" MyMissingFile new "this_page" end