Skip to content

Commit

Permalink
fix: snyk --version
Browse files Browse the repository at this point in the history
Fix typescript issues causing version to no longer work.
Fix issue running snyk --version on windows with dirty files.
  • Loading branch information
lili2311 authored and gitphill committed Jan 24, 2020
1 parent 0ea23d5 commit 73d070b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/protect/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as _ from 'lodash';
import { exec } from 'child_process';
import { apiTokenExists } from '../../../lib/api-token';
import * as auth from '../auth/is-authed';
import { getVersion } from '../version';
import getVersion = require('../version');
import * as allPrompts from './prompts';
import answersToTasks = require('./tasks');
import * as snyk from '../../../lib/';
Expand Down
4 changes: 3 additions & 1 deletion src/cli/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from '../../lib/version';
import { getVersion } from '../../lib/version';

export = getVersion;
8 changes: 2 additions & 6 deletions src/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function getBranchCommitAndDirty(promises): Promise<string> {
const branchName = res[0];
const commitStr = res[1];
const filesCount = res[2];
const dirtyCount = parseInt(filesCount, 10);
const dirtyCount = parseInt(filesCount, 10) || 0;
let curr = branchName + ': ' + commitStr;
if (dirtyCount !== 0) {
curr += ' (' + dirtyCount + ' dirty files)';
Expand All @@ -41,8 +41,4 @@ async function getBranchCommitAndDirty(promises): Promise<string> {

const commit = () => executeCommand('git rev-parse HEAD', root);
const branch = () => executeCommand('git rev-parse --abbrev-ref HEAD', root);
const dirty = () =>
executeCommand(
'expr $(git status --porcelain 2>/dev/null| ' + 'egrep "^(M| M)" | wc -l)',
root,
);
const dirty = () => executeCommand('git diff --shortstat', root);
14 changes: 14 additions & 0 deletions test/acceptance/cli-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ test('snyk test command should fail when --file is not specified correctly', (t)
});
});

test('snyk version command should show cli version or sha', (t) => {
t.plan(1);
exec(`node ${main} --version`, (err, stdout) => {
if (err) {
throw err;
}
t.match(
stdout.trim(),
':', // can't guess branch or sha or dirty files, but we do always add `:`
'version is shown',
);
});
});

test('snyk test command should fail when --packageManager is not specified correctly', (t) => {
t.plan(1);
exec(`node ${main} test --packageManager=hello`, (err, stdout) => {
Expand Down

0 comments on commit 73d070b

Please sign in to comment.