Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Commander terminal, input, and output options #185

Merged
merged 2 commits into from
Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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