Skip to content

Commit

Permalink
CLI: Fix empty --version output (#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saka7 authored and kibertoad committed Jun 30, 2019
1 parent aa124bf commit 0a85331
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/cli.js
Expand Up @@ -128,16 +128,18 @@ function invoke(env) {
const filetypes = ['js', 'coffee', 'ts', 'eg', 'ls'];
let pending = null;

const cliVersion = [
color.blue('Knex CLI version:'),
color.green(cliPkg.version),
].join(' ');

const localVersion = [
color.blue('Knex Local version:'),
color.green(env.modulePackage.version || 'None'),
].join(' ');

commander
.version(
color.blue('Knex CLI version: ', color.green(cliPkg.version)) +
'\n' +
color.blue(
'Local Knex version: ',
color.green(env.modulePackage.version)
) +
'\n'
)
.version(`${cliVersion}\n${localVersion}`)
.option('--debug', 'Run with debugging.')
.option('--knexfile [path]', 'Specify the knexfile path.')
.option('--knexpath [path]', 'Specify the path to knex instance.')
Expand Down
25 changes: 25 additions & 0 deletions test/cli/version.spec.js
@@ -0,0 +1,25 @@
'use strict';

const path = require('path');
const { execCommand } = require('cli-testlab');

const cliPkg = require('../../package');
const KNEX = path.normalize(__dirname + '/../../bin/cli.js');

describe('version', () => {
it('Print correct knex CLI version', () => {
const expectedKnexCliVersion = cliPkg.version;

return execCommand(`node ${KNEX} --version`, {
expectedOutput: expectedKnexCliVersion,
});
});

it('Print correct knex CLI version using -V flag', () => {
const expectedKnexCliVersion = cliPkg.version;

return execCommand(`node ${KNEX} -V`, {
expectedOutput: expectedKnexCliVersion,
});
});
});
1 change: 1 addition & 0 deletions test/index.js
Expand Up @@ -63,4 +63,5 @@ describe('CLI tests', function() {
this.timeout(process.env.KNEX_TEST_TIMEOUT || 5000);
require('./cli/knexfile-test.spec');
require('./cli/migrate-make.spec');
require('./cli/version.spec');
});

0 comments on commit 0a85331

Please sign in to comment.