Skip to content

Fix subcommand in windows #105

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

Merged
merged 3 commits into from
Oct 9, 2017
Merged
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
44 changes: 32 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const spawn = require('child_process').spawn;
const path = require('path');
const pkginfo = require('pkginfo');
const camelcase = require('camelcase');
const stringSimilarity = require('string-similarity');
Expand Down Expand Up @@ -216,9 +217,10 @@ module.exports = {
initial = items[item].init;
}

usage += initial && isVersion === -1
? ' ' + this.handleType(initial)[0]
: '';
usage +=
initial && isVersion === -1
? ' ' + this.handleType(initial)[0]
: '';
}
}

Expand All @@ -244,7 +246,9 @@ module.exports = {
// Add some space around it as well
if (typeof defaultValue !== 'undefined') {
if (typeof defaultValue === 'boolean') {
description += ` (${defaultValue ? 'enabled' : 'disabled'} by default)`;
description += ` (${defaultValue
? 'enabled'
: 'disabled'} by default)`;
} else {
description += ` (defaults to ${JSON.stringify(defaultValue)})`;
}
Expand Down Expand Up @@ -275,10 +279,10 @@ module.exports = {
}

// Generate full name of binary
const full =
this.binary +
'-' +
(Array.isArray(details.usage) ? details.usage[0] : details.usage);
const subCommand = Array.isArray(details.usage)
? details.usage[0]
: details.usage;
let full = this.binary + '-' + subCommand;

const args = process.argv;
let i = 0;
Expand All @@ -288,10 +292,26 @@ module.exports = {
i++;
}

// Run binary of sub command
this.child = spawn(full, args, {
stdio: 'inherit'
});
if (process.platform === 'win32') {
const binaryExt = path.extname(this.binary);
const mainModule = process.mainModule.filename;

full = `${mainModule}-${subCommand}`;

if (path.extname(this.binary)) {
full = `${mainModule.replace(binaryExt, '')}-${subCommand}${binaryExt}`;
}
// Run binary of sub command on windows
args.unshift(full);
this.child = spawn(process.execPath, args, {
stdio: 'inherit'
});
} else {
// Run binary of sub command
this.child = spawn(full, args, {
stdio: 'inherit'
});
}

// Throw an error if something fails within that binary
this.child.on('error', err => {
Expand Down