diff --git a/clite/commands.js b/clite/commands.js index 9054a61..a58e844 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -2,7 +2,24 @@ clite.commands.data = function() { // insert commands below this line clite.commands.load('help',function(args,env,io) { - io.write('yeah, I should probably implement this'); + if (args.length > 1) { + // TODO: implement command help lookup + io.write('help with arguments is a work in progress'); + } + io.write(` +Welcome to CLIte (pronounced like 'site' with an added L). + +Various unix-like commands are available for navigating the CLIte shell: + +ls - list directory contents +cat - concatenate files and print to std output or local file +touch - create a new file +less - simple text file viewer + +Running any command with the argument -? will give you help for that program. +Or you can run help <command> to get the same info. + + `); return 0; }); diff --git a/clite/core.js b/clite/core.js index 182cf22..82f1667 100644 --- a/clite/core.js +++ b/clite/core.js @@ -794,16 +794,21 @@ clite.shell = { clite.shell.writeLine(clite.shell.prompt.getHTML()+txt); clite.shell.prompt.push(''); clite.term.preventInput(); - // ready stdio (stdout,stdin) + // split command line into arguments + var args = clite.lib.strToArgs(txt); + // TODO: check for io redirects and piping, then setup stdio accordingly + // prepare stdio (stdin,stdout,stderr) var stdio = { - error:clite.term.writeLine, - write:clite.term.writeLine, read:clite.shell.readLine, - exit:clite.shell.exit, - istty:true + write:clite.term.writeLine, + error:clite.term.writeLine, + exit:clite.shell.exit, // equivalent to C's exit(), needed by asynchronous programs + istty:{ + stdin:true, // false if stdin (read) is not clite.shell.readLine + stdout:true // false if stdout (write) is not clite.term.writeLine + } }; // check for a macro - var args = clite.lib.strToArgs(txt); // then either run the macro or expand the program to be executed via PATH if (typeof clite.shell.macro[args[0]] != 'undefined') { var r = clite.shell.macro[args[0]](args,stdio); @@ -990,6 +995,7 @@ clite.lib = { base = clite.shell.env.PWD; if (base[0] != '/') base = clite.shell.env.PWD+'/'+base; + // TODO: support . and .. return base+'/'+txt; }, // convert a string into an argument array: 'ls /etc' -> ['ls',/etc]