|
1 | 1 | #!/usr/bin/env node
|
| 2 | +"use strict"; |
| 3 | + |
| 4 | +var net = require('net') |
| 5 | + , repl = require('repl') |
| 6 | + , underscore = require('underscore') |
| 7 | + , colors = require('colors') |
| 8 | + , appium = require('../server') |
| 9 | + , parser = require('./parser') |
| 10 | + ; |
| 11 | + |
| 12 | +var startRepl = function() { |
| 13 | + var help = function() { |
| 14 | + console.log("\nWelcome to the Appium CLI".cyan); |
| 15 | + console.log(" - Access the appium object via the object: 'appium'".grey); |
| 16 | + console.log(" - appium.run is the function to start the server".grey); |
| 17 | + console.log(" - args is the default params data structure".grey); |
| 18 | + console.log(" - set args.app then run appium.run(args);\n".grey); |
| 19 | + return 'Thanks for asking'; |
| 20 | + }; |
| 21 | + |
| 22 | + help(); |
| 23 | + |
| 24 | + var r = repl.start('(appium): '); |
| 25 | + r.context.appium = appium; |
| 26 | + r.context.parser = parser(); |
| 27 | + r.context.help = help; |
| 28 | + r.context.args = { |
| 29 | + app: '/path/to/test/app' |
| 30 | + , verbose: '1' |
| 31 | + , udid: null |
| 32 | + , address: '127.0.0.1' |
| 33 | + , port: 4723 |
| 34 | + , remove: true |
| 35 | + }; |
| 36 | + |
| 37 | + var connections = 0; |
| 38 | + var server = net.createServer(function (socket) { |
| 39 | + connections += 1; |
| 40 | + socket.setTimeout(5*60*1000, function() { |
| 41 | + socket.destroy(); |
| 42 | + }); |
| 43 | + repl.start("(appium): ", socket); |
| 44 | + }).listen(process.platform === "win32" ? "\\\\.\\pipe\\node-repl-sock-" + process.pid : "/tmp/node-repl-sock-" + process.pid); |
| 45 | + |
| 46 | + r.on('exit', function () { |
| 47 | + server.close(); |
| 48 | + process.exit(); |
| 49 | + }); |
| 50 | +}; |
| 51 | + |
| 52 | +if (process.argv[2] === "shell") { |
| 53 | + startRepl(); |
| 54 | +} |
| 55 | +else { |
| 56 | + var args = parser().parseArgs(); |
| 57 | + args.verbose = 1; |
| 58 | + console.log("Pre-flight check ...".grey); |
| 59 | + appium.run(args, function() { console.log('Rock and roll.'.grey); }); |
| 60 | +} |
0 commit comments