cexec 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. /* -*- Mode:Js */
  3. /* vim: set expandtab ts=4 sw=4: */
  4. /*
  5. * You may redistribute this program and/or modify it under the terms of
  6. * the GNU General Public License as published by the Free Software Foundation,
  7. * either version 3 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. var Cjdns = require('./lib/cjdnsadmin/cjdnsadmin');
  18. var nThen = require('nthen');
  19. var cjdns;
  20. nThen(function (waitFor) {
  21. Cjdns.connectWithAdminInfo(waitFor(function (c) { cjdns = c; }));
  22. }).nThen(function (waitFor) {
  23. var code;
  24. if (process.argv[process.argv.length-1].indexOf('cexec') !== -1) {
  25. code = 'functions(cb)';
  26. console.log("Usage: ./tools/cexec 'ping()' ## For example to send a ping request");
  27. console.log("List of available RPC requests with parameters is as follows:");
  28. } else {
  29. code = process.argv[process.argv.length-1].replace(/\).*$/, ',cb);');
  30. code = code.replace('(,cb);', '(cb);');
  31. }
  32. var f = new Function('x', 'cb', 'x.' + code);
  33. f(cjdns, function (err, ret) {
  34. if (err) { throw err; }
  35. console.log(JSON.stringify(ret, null, ' '));
  36. cjdns.disconnect();
  37. });
  38. });