Skip to content

Commit

Permalink
Use safe-commander wrapper to circumvent name collision bug in comman…
Browse files Browse the repository at this point in the history
…der.js

The --domain command line option was colliding with a property on the
commander object.  See: tj/commander.js#404

This fixes the app crashing when --domain is not the last option passed
on the command line.
  • Loading branch information
specious committed Oct 11, 2017
1 parent 7889102 commit c719a59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var manifest = require('./package.json'),
Bitly = require('bitly'),
app = require('commander'),
app = require('safe-commander'),
rc = require('rc')(manifest.name),
homedir = require('os').homedir(),
url = require('url'),
Expand Down Expand Up @@ -99,7 +99,7 @@ var bitly,
action = history,
arg0 = app.args[0]

if( app.archive ) {
if( app.optsObj.archive ) {
if( arg0 ) {
action = archive
} else
Expand Down Expand Up @@ -163,7 +163,7 @@ function applyAltCount( args ) {
let arg = args[i], rest = arg.slice( 1 )

if( arg[0] === "-" && /^\d+$/.test( rest ) ) {
app.count = parseInt( rest )
app.optsObj.count = parseInt( rest )
break
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ function preValidateToken( token ) {

function getBitlyToken() {
return new Promise( function( resolve, reject ) {
if( app.ask || (!app.key && !preValidateToken( rc.key )) ) {
if( app.optsObj.ask || (!app.optsObj.key && !preValidateToken( rc.key )) ) {
print( "Please enter your Bitly access token." )
print( "You can obtain your token from: " + "https://bitly.com/a/oauth_apps".yellow )
print()
Expand All @@ -201,22 +201,22 @@ function getBitlyToken() {
print()
if( key !== undefined ) {
// Save the key if there isn't one saved already, or if --save option is passed
if( app.save || !rc.key )
if( app.optsObj.save || !rc.key )
saveConfig( key )

resolve( key )
} else {
reject()
}
} )
} else if( app.key ) {
if( !preValidateToken( app.key ) ) {
} else if( app.optsObj.key ) {
if( !preValidateToken( app.optsObj.key ) ) {
reject( 'The authentication token you have provided does not appear to be valid' )
} else {
if( app.save )
saveConfig( app.key )
if( app.optsObj.save )
saveConfig( app.optsObj.key )

resolve( app.key )
resolve( app.optsObj.key )
}
} else {
resolve( rc.key )
Expand All @@ -234,7 +234,7 @@ function expandOrShorten( arg ) {
if( domains.default.indexOf( u.hostname ) !== -1 || domains.extended.indexOf( u.hostname ) !== -1 ) {
expand( arg )
} else {
shorten( uri, app.domain )
shorten( uri, app.optsObj.domain )
}
} else
expand( arg )
Expand Down Expand Up @@ -286,10 +286,10 @@ function archive( shortUrl ) {

function history( offset ) {
offset = offset || 0
let count = Math.min( app.count, BITLY_MAX_HISTORY_CHUNK )
let count = Math.min( app.optsObj.count, BITLY_MAX_HISTORY_CHUNK )

if( count !== 0 ) {
app.count -= count
app.optsObj.count -= count

bitly._doRequest( bitly._generateNiceUrl( { offset, limit: count }, 'user/link_history' ) ).then( res => {
printHistory( res.data.link_history )
Expand All @@ -310,7 +310,7 @@ function printHistory( link_history ) {
' - ' + item.long_url.red )

// Print additional details (if "--verbose")
if( app.verbose ) {
if( app.optsObj.verbose ) {
const INDENT = ' '

if( item.title !== "" )
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitly-client",
"version": "1.5.4",
"version": "1.5.5",
"description": "Use Bitly from the command line",
"author": "Ildar Sagdejev <specious@gmail.com> (http://specious.github.io)",
"license": "ISC",
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"bitly": "^3.0.3",
"colors": "^1.1.2",
"commander": "^2.11.0",
"safe-commander": "^2.11.0",
"rc": "^1.2.1",
"read": "^1.0.7"
}
Expand Down

0 comments on commit c719a59

Please sign in to comment.