Skip to content
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
21 changes: 13 additions & 8 deletions spec/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ var cli = require("../src/cli"),
cordova_lib = require('cordova-lib'),
events = cordova_lib.events,
cordova = cordova_lib.cordova,
telemetry = require('../src/telemetry');

//avoid node complaining of too many event listener added
process.setMaxListeners(0);
telemetry = require('../src/telemetry'),
logger = require('cordova-common').CordovaLogger.get();

//avoid node complaining of too many event listener added
process.setMaxListeners(0);

describe("cordova cli", function () {
beforeEach(function () {
Expand All @@ -41,8 +42,12 @@ describe("cordova cli", function () {
};

spyOn(events, "on").andReturn(new FakeEvents());

// Spy and mute output
spyOn(logger, 'results');
spyOn(logger, 'warn');
spyOn(console, 'log');

// Prevent accidentally turning telemetry on/off during testing
telemetry.turnOn = function() {};
telemetry.turnOff = function() {};
Expand All @@ -58,21 +63,21 @@ describe("cordova cli", function () {

it("will spit out the version with -v", function (done) {
cli(["node", "cordova", "-v"], function() {
expect(console.log.mostRecentCall.args[0]).toMatch(version);
expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done();
});
});

it("will spit out the version with --version", function (done) {
cli(["node", "cordova", "--version"], function () {
expect(console.log.mostRecentCall.args[0]).toMatch(version);
expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done()
});
});

it("will spit out the version with -v anywhere", function (done) {
cli(["node", "cordova", "one", "-v", "three"], function () {
expect(console.log.mostRecentCall.args[0]).toMatch(version);
expect(logger.results.mostRecentCall.args[0]).toMatch(version);
done();
});
});
Expand Down
35 changes: 21 additions & 14 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,6 @@ function cli(inputArgs) {

var args = nopt(knownOpts, shortHands, inputArgs);

if (args.version) {
var cliVersion = require('../package').version;
var libVersion = require('cordova-lib/package').version;
var toPrint = cliVersion;
if (cliVersion != libVersion || /-dev$/.exec(libVersion)) {
toPrint += ' (cordova-lib@' + libVersion + ')';
}
console.log(toPrint);
return Q();
}


// For CordovaError print only the message without stack trace unless we
// are in a verbose mode.
process.on('uncaughtException', function(err) {
Expand All @@ -262,7 +250,7 @@ function cli(inputArgs) {
}
process.exit(1);
});

logger.subscribe(events);

if (args.silent) {
Expand All @@ -273,6 +261,25 @@ function cli(inputArgs) {
logger.setLevel('verbose');
}

var cliVersion = require('../package').version;
// TODO: Use semver.prerelease when it gets released
var usingPrerelease = /-nightly|-dev$/.exec(cliVersion);
if (args.version || usingPrerelease) {
var libVersion = require('cordova-lib/package').version;
var toPrint = cliVersion;
if (cliVersion != libVersion || usingPrerelease) {
toPrint += ' (cordova-lib@' + libVersion + ')';
}

if (args.version) {
logger.results(toPrint);
return Q();
} else {
// Show a warning and continue
logger.warn('Warning: using prerelease version ' + toPrint);
}
}

// TODO: Example wanted, is this functionality ever used?
// If there were arguments protected from nopt with a double dash, keep
// them in unparsedArgs. For example:
Expand Down Expand Up @@ -320,7 +327,7 @@ function cli(inputArgs) {
nohooks: args.nohooks || [],
searchpath : args.searchpath
};


if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run' || cmd === 'clean') {
// All options without dashes are assumed to be platform names
Expand Down