1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-01 00:10:45 +00:00

Added support for the dump and verbose commands

This commit is contained in:
Jeremy Ruston 2012-05-02 15:02:58 +01:00
parent dac06537e5
commit 71ec12a784
4 changed files with 145 additions and 3 deletions

View File

@ -59,9 +59,16 @@ Commander.prototype.executeNextCommand = function() {
this.callback("Unknown command: " + commandName);
} else {
if(command.info.synchronous) {
var c = new command.Command(params,this);
c.execute();
this.executeNextCommand();
if(this.verbose) {
this.streams.output.write("Executing command: " + commandName + " " + params.join(" ") + "\n");
}
var c = new command.Command(params,this),
err = c.execute();
if(err) {
this.callback(err);
} else {
this.executeNextCommand();
}
}
}
}

View File

@ -0,0 +1,101 @@
/*\
title: $:/core/commands/dump.js
type: application/javascript
module-type: command
Dump command
\*/
(function(){
/*jslint node: true, browser: true */
"use strict";
exports.info = {
name: "dump",
synchronous: true,
params: {}
}
var Command = function(params,commander) {
this.params = params;
this.commander = commander;
this.output = commander.streams.output;
};
Command.prototype.execute = function() {
if(this.params.length < 1) {
return "Too few parameters for dump command";
}
var subcommand = this.subcommands[this.params[0]];
if(subcommand) {
return subcommand.call(this);
} else {
return "Unknown subcommand (" + this.params[0] + ") for dump command";
}
}
Command.prototype.subcommands = {};
Command.prototype.subcommands.tiddlers = function() {
var tiddlers = this.commander.wiki.sortTiddlers()
this.output.write("Wiki contains these tiddlers:\n");
for(var t=0; t<tiddlers.length; t++) {
this.output.write(tiddlers[t] + "\n");
}
return null; // No error
};
Command.prototype.subcommands.shadows = function() {
var tiddlers = this.commander.wiki.shadows.sortTiddlers()
this.output.write("Wiki contains these shadow tiddlers:\n");
for(var t=0; t<tiddlers.length; t++) {
this.output.write(tiddlers[t] + "\n");
}
return null; // No error
};
Command.prototype.subcommands.config = function() {
var self = this;
var quotePropertyName = function(p) {
var unquotedPattern = /^[A-Za-z0-9_]*$/mg;
if(unquotedPattern.test(p)) {
return p;
} else {
return "[\"" + $tw.utils.stringify(p) + "\"]";
}
},
dumpConfig = function(object,prefix) {
for(var n in object) {
var v = object[n];
if(typeof v === "object") {
dumpConfig(v,prefix + "." + quotePropertyName(n));
} else if(typeof v === "string") {
self.output.write(prefix + "." + quotePropertyName(n) + ": \"" + $tw.utils.stringify(v) + "\"\n");
} else {
self.output.write(prefix + "." + quotePropertyName(n) + ": " + v.toString() + "\n");
}
}
},
dumpObject = function(heading,object) {
self.output.write(heading +"\n");
for(var n in object) {
self.output.write(" " + n + "\n");
}
};
this.output.write("Configuration:\n");
dumpConfig($tw.config," $tw.config");
dumpObject("Tiddler field plugins:",$tw.Tiddler.fieldPlugins);
dumpObject("Loaded modules:",$tw.modules.titles);
dumpObject("Loaded plugins:",$tw.plugins.moduleTypes);
dumpObject("Command plugins:",$tw.commands);
dumpObject("Parser plugins:",$tw.wiki.parsers);
dumpObject("Macro plugins:",$tw.wiki.macros);
dumpObject("Deserializer plugins:",$tw.Wiki.tiddlerDeserializerPlugins);
return null; // No error
};
exports.Command = Command;
})();

View File

@ -0,0 +1,32 @@
/*\
title: $:/core/commands/verbose.js
type: application/javascript
module-type: command
Verbose command
\*/
(function(){
/*jslint node: true, browser: true */
"use strict";
exports.info = {
name: "verbose",
synchronous: true,
params: {}
}
var Command = function(params,commander) {
this.params = params;
this.commander = commander;
};
Command.prototype.execute = function() {
this.commander.verbose = true;
return null; // No error
}
exports.Command = Command;
})();

View File

@ -3,6 +3,7 @@ title: $:/core/commands/version.js
type: application/javascript
module-type: command
Version command
\*/
(function(){
@ -23,6 +24,7 @@ var Command = function(params,commander) {
Command.prototype.execute = function() {
this.commander.streams.output.write($tw.utils.getVersionString() + "\n");
return null; // No error
}
exports.Command = Command;