Skip to content

Commit

Permalink
Merge pull request #185 from sintaxi/ko-commander-fix
Browse files Browse the repository at this point in the history
Fixes Commander terminal, input, and output options
  • Loading branch information
kennethormandy committed Jan 18, 2016
2 parents 74a23bc + e25cfa9 commit b023089
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function(req, next, abort){
read({
prompt: " forgot password?".grey,
default: "yes",
terminal: req.config.terminal,
output: req.config.output,
input: req.config.input
}, function(err, reply){
if (reply == "yes" || reply == "y" || reply == "Y") {

Expand Down
3 changes: 3 additions & 0 deletions lib/middleware/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function(req, next, abort){
prompt: label,
default: suggestion || "",
edit: true,
terminal: req.config.terminal,
output: req.config.output,
input: req.config.input
}, function(err, domain){
if (domain === undefined) return abort("Please try again with a valid domain name.")
if (err || !helpers.validDomain(domain)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/middleware/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function(req, next, abort){
prompt: label,
default: suggestion,
edit: true,
terminal: req.config.terminal,
output: req.config.output,
input: req.config.input
}, function(err, projectPath){
if (projectPath === undefined) return abort("publishing not initiated.")
if (!fs.existsSync(path.resolve(projectPath))){
Expand Down
3 changes: 3 additions & 0 deletions lib/middleware/ssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ module.exports = function(req, next, abort){
prompt: label,
default: placeholder,
edit: true,
terminal: req.config.terminal,
output: req.config.output,
input: req.config.input
}, function(err, pem){
if (pem === undefined) return abort("no PEM file provided")
if (pem === "") return getPem()
Expand Down
34 changes: 23 additions & 11 deletions test/actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var should = require('should')
var minimist = require('minimist')(process.argv.slice(2))
var yargs = require('yargs')
var commander = require('commander')
var nixt = require('nixt')
var Surge = require('../')
var surge = new Surge
var pkg = require('../package.json')
var minimist = 'node ./test/fixtures/bin/minimist.js'
var yargs = 'node ./test/fixtures/bin/yargs.js'
var hooks = {}

describe('actions', function (done) {
Expand All @@ -26,18 +27,29 @@ describe('actions', function (done) {
})

it('minimist', function (done) {
var program = minimist
should(program._.length).equal(1)
done()
nixt({ colors: false })
.run(minimist + ' login')
.on(/.*email:.*/).respond('kenneth+test@chloi.io\n')
.on(/.*password:.*/).respond('12345\n')
.expect(function (result) {
should(result.stdout).match(/Logged in as kenneth/)
should(result.stdout).match(/surge.sh/)
})
.exec(minimist + ' logout')
.end(done)
})

it('yargs', function (done) {
var program = yargs
program
.command('teardown', 'Login to Surge.', surge.login(hooks))
.argv
should(program.argv._.length).equal(1)
done()
nixt({ colors: false })
.run(yargs + ' login')
.on(/.*email:.*/).respond('kenneth+test@chloi.io\n')
.on(/.*password:.*/).respond('12345\n')
.expect(function (result) {
should(result.stdout).match(/Logged in as kenneth/)
should(result.stdout).match(/surge.sh/)
})
.exec(yargs + ' logout')
.end(done)
})
})

Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/bin/minimist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env node

var argv = require('minimist')(process.argv.slice(2))
var surge = require('../../../')({
name: 'minimist'
})

var hooks = {}

if (argv._[0] === 'login') {
return surge.login(hooks)(argv._.slice(1))
}

if (argv._[0] === 'whoami') {
return surge.whoami(hooks)(argv._.slice(1))
}
18 changes: 18 additions & 0 deletions test/fixtures/bin/yargs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env node

var program = require('yargs')
var surge = require('../../../')({
name: 'yargs'
})

var hooks = {}

program
.command('login', 'Login to your account', surge.login(hooks))
.usage('$0 <command>')
.argv

program
.command('whoami', 'Check who you are logged in as.', surge.whoami(hooks))
.usage('$0 <command>')
.argv

0 comments on commit b023089

Please sign in to comment.