mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-19 00:04:51 +00:00
Added support for the dump and verbose commands
This commit is contained in:
parent
dac06537e5
commit
71ec12a784
@ -59,9 +59,16 @@ Commander.prototype.executeNextCommand = function() {
|
|||||||
this.callback("Unknown command: " + commandName);
|
this.callback("Unknown command: " + commandName);
|
||||||
} else {
|
} else {
|
||||||
if(command.info.synchronous) {
|
if(command.info.synchronous) {
|
||||||
var c = new command.Command(params,this);
|
if(this.verbose) {
|
||||||
c.execute();
|
this.streams.output.write("Executing command: " + commandName + " " + params.join(" ") + "\n");
|
||||||
this.executeNextCommand();
|
}
|
||||||
|
var c = new command.Command(params,this),
|
||||||
|
err = c.execute();
|
||||||
|
if(err) {
|
||||||
|
this.callback(err);
|
||||||
|
} else {
|
||||||
|
this.executeNextCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
101
rabbithole/core/modules/commands/dump.js
Normal file
101
rabbithole/core/modules/commands/dump.js
Normal 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;
|
||||||
|
|
||||||
|
})();
|
32
rabbithole/core/modules/commands/verbose.js
Normal file
32
rabbithole/core/modules/commands/verbose.js
Normal 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;
|
||||||
|
|
||||||
|
})();
|
@ -3,6 +3,7 @@ title: $:/core/commands/version.js
|
|||||||
type: application/javascript
|
type: application/javascript
|
||||||
module-type: command
|
module-type: command
|
||||||
|
|
||||||
|
Version command
|
||||||
|
|
||||||
\*/
|
\*/
|
||||||
(function(){
|
(function(){
|
||||||
@ -23,6 +24,7 @@ var Command = function(params,commander) {
|
|||||||
|
|
||||||
Command.prototype.execute = function() {
|
Command.prototype.execute = function() {
|
||||||
this.commander.streams.output.write($tw.utils.getVersionString() + "\n");
|
this.commander.streams.output.write($tw.utils.getVersionString() + "\n");
|
||||||
|
return null; // No error
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Command = Command;
|
exports.Command = Command;
|
||||||
|
Loading…
Reference in New Issue
Block a user