# gils: better than Gnu utILS global commands = {} fn register(usage, group, help, handler) do const name = usage:split(" ")[0] commands:push({ name = name, usage = usage, group = group, help = help, handler = handler }) end fn lookup(name) do for index in 0..commands:len() do if commands[index].name == name return commands[index] end return :nil end fn make_ctx(line, argv) do const name = argv[0] let rest = "" const cut = name:len() + 1 if line:len() > cut do rest = line[cut..] end return { line = line, argv = argv, rest = rest } end # scripts read their args off env.ctx, stashed here before eval global env = { ctx = :nil } # first use of unless in history global expand_path = fn(path) do if path:len() == 0 return wd.path unless (path[0] == "/") do const slash = unless (wd.path == "/") "/" else "" path = "#{wd.path}#{slash}#{path}" end return path end fn run_script_path(path, label, ctx) do const size = fs:size(path) if size < 0 return :false env.ctx = ctx const error_msg = eval_script(fs:read_bytes(path, 0, size)) if error_msg != :nil do fail("#{label}: #{error_msg}\n") end return :true end fn run_script(name, ctx) run_script_path("/bin/#{name}.rv", name, ctx)