Created
January 17, 2009 11:58
-
-
Save greut/48321 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env seed | |
var __author__ = "Yoan Blanc <yoan.blanc@gmail.com>"; | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// | |
// You should have received a copy of the GNU General Public License | |
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
function toArray(ary) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return Array.prototype.slice.apply(ary, args); | |
} | |
if(Seed.argv.length < 3) { | |
Seed.print("Seed module explorer.\n"); | |
Seed.printf("\tauthor: %s", __author__); | |
Seed.print("\tlicense: GPL"); | |
Seed.printf("\tusage: %s MODULE <PATTERN>", toArray(Seed.argv, 0, 2).join(" ")); | |
} else { | |
var modulename = Seed.argv[2], | |
namespace = modulename.split(".")[0], | |
pattern = Seed.argv[3]||null, | |
module; | |
if (namespace !== "Seed") { | |
try { | |
Seed.import_namespace(namespace); | |
module = eval(modulename); | |
} catch(e) { | |
Seed.printf("%s occurs while loading %s", e.name, namespace); | |
Seed.print(e.message); | |
Seed.quit(); | |
} | |
if(typeof module === "undefined") { | |
Seed.printf("%s isn't part of %s", modulename, namespace); | |
Seed.quit(); | |
} | |
} else { | |
module = Seed; | |
} | |
var items = []; | |
for(var name in module) { | |
items.push(name); | |
} | |
if(pattern) { | |
var re = new RegExp(pattern, "i"); | |
items = items.filter(function(item){ | |
return item.match(re); | |
}); | |
} | |
Seed.print(items.join(", ")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment