Fossil SCM

minor tweaks to the prototype shell.

stephan 2011-10-07 13:32 json-multitag-test
Commit d30b20a56c620c6f9f5a97bee8f34dc6ea9e5bce
1 file changed +29 -9
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -51,11 +51,11 @@
5151
if(resp && resp.resultCode){
5252
print("Response contains error info: "+resp.resultCode+": "+resp.resultText);
5353
}
5454
print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp)));
5555
};
56
- FShell.fossil.whoami({
56
+ FShell.fossil.HAI({
5757
onResponse:function(resp,opt){
5858
assertResponseOK(resp);
5959
}
6060
});
6161
})();
@@ -114,26 +114,34 @@
114114
}());
115115
116116
FShell.dispatchLine = function(line){
117117
var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
118118
var cmd = av[0];
119
- var h = this.commandHandlers[('/' == cmd[0]) ? '/' : cmd];
119
+ var key, h;
120
+ if('/' == cmd[0]) key = '/';
121
+ else key = this.commandAliases[cmd];
122
+ if(!key) key = cmd;
123
+ h = this.commandHandlers[key];
120124
if(!h){
121
- print("Command not known: "+cmd);
125
+ print("Command not known: "+cmd +" ("+key+")");
126
+ }else if(!WhAjaj.isFunction(h)){
127
+ print("Not a function: "+key);
122128
}
123129
else{
124
- print("Sending ["+cmd+"] command... ");
130
+ print("Sending ["+key+"] command... ");
125131
try{h(av);}
126132
catch(e){ print("EXCEPTION: "+e); }
127133
}
128134
};
129135
130
-FShell.onResponseDefault = function(){
131
- var self = this;
132
- return function(resp){
136
+FShell.onResponseDefault = function(callback){
137
+ return function(resp,req){
133138
assertResponseOK(resp);
134
- print(WhAjaj.stringify(resp.payload));
139
+ print("Payload: "+(resp.payload ? WhAjaj.stringify(resp.payload) : "none"));
140
+ if(WhAjaj.isFunction(callback)){
141
+ callback(resp,req);
142
+ }
135143
};
136144
};
137145
FShell.commandHandlers = {
138146
"/":function(args){
139147
FShell.fossil.sendCommand('/json'+args[0],undefined,{
@@ -153,17 +161,29 @@
153161
},
154162
"whoami":function(args){
155163
FShell.fossil.whoami({
156164
onResponse:FShell.onResponseDefault()
157165
});
166
+ },
167
+ "HAI":function(args){
168
+ FShell.fossil.HAI({
169
+ onResponse:FShell.onResponseDefault()
170
+ });
158171
}
159172
};
160
-
173
+FShell.commandAliases = {
174
+ "li":"login",
175
+ "lo":"logout",
176
+ "who":"whoami",
177
+ "hi":"HAI",
178
+ "tci":"/timeline/ci?limit=3"
179
+};
161180
FShell.mainLoop = function(){
162181
var line;
163182
while( null != (line = this.readline(this.prompt)) ){
164183
//print("Got line: "+line);
165184
this.dispatchLine(line);
185
+ print("");
166186
}
167187
};
168188
169189
FShell.mainLoop();
170190
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -51,11 +51,11 @@
51 if(resp && resp.resultCode){
52 print("Response contains error info: "+resp.resultCode+": "+resp.resultText);
53 }
54 print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp)));
55 };
56 FShell.fossil.whoami({
57 onResponse:function(resp,opt){
58 assertResponseOK(resp);
59 }
60 });
61 })();
@@ -114,26 +114,34 @@
114 }());
115
116 FShell.dispatchLine = function(line){
117 var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
118 var cmd = av[0];
119 var h = this.commandHandlers[('/' == cmd[0]) ? '/' : cmd];
 
 
 
 
120 if(!h){
121 print("Command not known: "+cmd);
 
 
122 }
123 else{
124 print("Sending ["+cmd+"] command... ");
125 try{h(av);}
126 catch(e){ print("EXCEPTION: "+e); }
127 }
128 };
129
130 FShell.onResponseDefault = function(){
131 var self = this;
132 return function(resp){
133 assertResponseOK(resp);
134 print(WhAjaj.stringify(resp.payload));
 
 
 
135 };
136 };
137 FShell.commandHandlers = {
138 "/":function(args){
139 FShell.fossil.sendCommand('/json'+args[0],undefined,{
@@ -153,17 +161,29 @@
153 },
154 "whoami":function(args){
155 FShell.fossil.whoami({
156 onResponse:FShell.onResponseDefault()
157 });
 
 
 
 
 
158 }
159 };
160
 
 
 
 
 
 
161 FShell.mainLoop = function(){
162 var line;
163 while( null != (line = this.readline(this.prompt)) ){
164 //print("Got line: "+line);
165 this.dispatchLine(line);
 
166 }
167 };
168
169 FShell.mainLoop();
170
--- ajax/i-test/rhino-shell.js
+++ ajax/i-test/rhino-shell.js
@@ -51,11 +51,11 @@
51 if(resp && resp.resultCode){
52 print("Response contains error info: "+resp.resultCode+": "+resp.resultText);
53 }
54 print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp)));
55 };
56 FShell.fossil.HAI({
57 onResponse:function(resp,opt){
58 assertResponseOK(resp);
59 }
60 });
61 })();
@@ -114,26 +114,34 @@
114 }());
115
116 FShell.dispatchLine = function(line){
117 var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired!
118 var cmd = av[0];
119 var key, h;
120 if('/' == cmd[0]) key = '/';
121 else key = this.commandAliases[cmd];
122 if(!key) key = cmd;
123 h = this.commandHandlers[key];
124 if(!h){
125 print("Command not known: "+cmd +" ("+key+")");
126 }else if(!WhAjaj.isFunction(h)){
127 print("Not a function: "+key);
128 }
129 else{
130 print("Sending ["+key+"] command... ");
131 try{h(av);}
132 catch(e){ print("EXCEPTION: "+e); }
133 }
134 };
135
136 FShell.onResponseDefault = function(callback){
137 return function(resp,req){
 
138 assertResponseOK(resp);
139 print("Payload: "+(resp.payload ? WhAjaj.stringify(resp.payload) : "none"));
140 if(WhAjaj.isFunction(callback)){
141 callback(resp,req);
142 }
143 };
144 };
145 FShell.commandHandlers = {
146 "/":function(args){
147 FShell.fossil.sendCommand('/json'+args[0],undefined,{
@@ -153,17 +161,29 @@
161 },
162 "whoami":function(args){
163 FShell.fossil.whoami({
164 onResponse:FShell.onResponseDefault()
165 });
166 },
167 "HAI":function(args){
168 FShell.fossil.HAI({
169 onResponse:FShell.onResponseDefault()
170 });
171 }
172 };
173 FShell.commandAliases = {
174 "li":"login",
175 "lo":"logout",
176 "who":"whoami",
177 "hi":"HAI",
178 "tci":"/timeline/ci?limit=3"
179 };
180 FShell.mainLoop = function(){
181 var line;
182 while( null != (line = this.readline(this.prompt)) ){
183 //print("Got line: "+line);
184 this.dispatchLine(line);
185 print("");
186 }
187 };
188
189 FShell.mainLoop();
190

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button