Fossil SCM
minor tweaks to the prototype shell.
Commit
d30b20a56c620c6f9f5a97bee8f34dc6ea9e5bce
Parent
7ab5d85487f2300…
1 file changed
+29
-9
+29
-9
| --- ajax/i-test/rhino-shell.js | ||
| +++ ajax/i-test/rhino-shell.js | ||
| @@ -51,11 +51,11 @@ | ||
| 51 | 51 | if(resp && resp.resultCode){ |
| 52 | 52 | print("Response contains error info: "+resp.resultCode+": "+resp.resultText); |
| 53 | 53 | } |
| 54 | 54 | print("GOT RESPONSE: "+(('string'===typeof resp) ? resp : WhAjaj.stringify(resp))); |
| 55 | 55 | }; |
| 56 | - FShell.fossil.whoami({ | |
| 56 | + FShell.fossil.HAI({ | |
| 57 | 57 | onResponse:function(resp,opt){ |
| 58 | 58 | assertResponseOK(resp); |
| 59 | 59 | } |
| 60 | 60 | }); |
| 61 | 61 | })(); |
| @@ -114,26 +114,34 @@ | ||
| 114 | 114 | }()); |
| 115 | 115 | |
| 116 | 116 | FShell.dispatchLine = function(line){ |
| 117 | 117 | var av = line.split(' '); // FIXME: to shell-like tokenization. Too tired! |
| 118 | 118 | 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]; | |
| 120 | 124 | 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); | |
| 122 | 128 | } |
| 123 | 129 | else{ |
| 124 | - print("Sending ["+cmd+"] command... "); | |
| 130 | + print("Sending ["+key+"] command... "); | |
| 125 | 131 | try{h(av);} |
| 126 | 132 | catch(e){ print("EXCEPTION: "+e); } |
| 127 | 133 | } |
| 128 | 134 | }; |
| 129 | 135 | |
| 130 | -FShell.onResponseDefault = function(){ | |
| 131 | - var self = this; | |
| 132 | - return function(resp){ | |
| 136 | +FShell.onResponseDefault = function(callback){ | |
| 137 | + return function(resp,req){ | |
| 133 | 138 | 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 | + } | |
| 135 | 143 | }; |
| 136 | 144 | }; |
| 137 | 145 | FShell.commandHandlers = { |
| 138 | 146 | "/":function(args){ |
| 139 | 147 | FShell.fossil.sendCommand('/json'+args[0],undefined,{ |
| @@ -153,17 +161,29 @@ | ||
| 153 | 161 | }, |
| 154 | 162 | "whoami":function(args){ |
| 155 | 163 | FShell.fossil.whoami({ |
| 156 | 164 | onResponse:FShell.onResponseDefault() |
| 157 | 165 | }); |
| 166 | + }, | |
| 167 | + "HAI":function(args){ | |
| 168 | + FShell.fossil.HAI({ | |
| 169 | + onResponse:FShell.onResponseDefault() | |
| 170 | + }); | |
| 158 | 171 | } |
| 159 | 172 | }; |
| 160 | - | |
| 173 | +FShell.commandAliases = { | |
| 174 | + "li":"login", | |
| 175 | + "lo":"logout", | |
| 176 | + "who":"whoami", | |
| 177 | + "hi":"HAI", | |
| 178 | + "tci":"/timeline/ci?limit=3" | |
| 179 | +}; | |
| 161 | 180 | FShell.mainLoop = function(){ |
| 162 | 181 | var line; |
| 163 | 182 | while( null != (line = this.readline(this.prompt)) ){ |
| 164 | 183 | //print("Got line: "+line); |
| 165 | 184 | this.dispatchLine(line); |
| 185 | + print(""); | |
| 166 | 186 | } |
| 167 | 187 | }; |
| 168 | 188 | |
| 169 | 189 | FShell.mainLoop(); |
| 170 | 190 |
| --- 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 |