Created
December 16, 2011 05:50
-
-
Save justinvh/1484679 to your computer and use it in GitHub Desktop.
Taking advantage of function->string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function files(where, opts) { | |
/*** | |
Generates a list of files from the output of `ls`. | |
Arguments: | |
where -- From where to list files (default '.') | |
opts -- Optional parameters that can be passed to `ls`. | |
***/ | |
where = where || "."; | |
opts = opts || []; | |
calling = opts.length ? String.format("ls %s %s", opts.join(""), where) : | |
String.format("ls %s", where); | |
return s8.cmd(calling).split("\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function help(fun) { | |
/*** | |
Prints the help text of a function. | |
Arguments: | |
fun -- The function (or alternatively an object with help defined) | |
***/ | |
if (fun === undefined) | |
return stdout.writeln("What function do you need help with?"); | |
if (!(fun instanceof Function)) { | |
if (fun.help) | |
return stdout.writeln(fun.help); | |
return stdout.writeln("I can not help you with that topic."); | |
} | |
var sf = new String(fun); | |
var matches = sf.match(/\/\*\*\*([\s\S]*)\*\*\*\//m); | |
if (matches) | |
return stdout.writeln(matches[1]); | |
return stdout.writeln("I can not help you with that function."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment