Skip to content

Commit

Permalink
Simplify clasp --version. Import commander to get TS benefits
Browse files Browse the repository at this point in the history
  • Loading branch information
grant committed Dec 12, 2018
1 parent c4d2c1a commit 17f2c13
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import 'connect';

import * as commander from 'commander';
import {
apis,
clone,
Expand All @@ -46,7 +47,7 @@ import {
} from './commands';
import { PROJECT_NAME, handleError } from './utils';

const commander = require('commander');
// const commander = require('commander');

// CLI

Expand Down Expand Up @@ -336,22 +337,16 @@ commander
* @example random
*/
commander
.command('*', { isDefault: true })
.command('*', undefined, { isDefault: true })
.description('Any other command is not supported')
.action(handleError(defaultCmd));

const versionOption = Symbol('version');
/**
* Displays clasp version
*/
commander.option('-v, --version').on('option:version', () => {
commander[versionOption] = true;
});

// Specified `--version` option with no sub-command
if (commander[versionOption] && !commander.args[0]) {
console.log(require('../package.json').version);
}
});

// defaults to help if commands are not provided
if (!process.argv.slice(2).length) {
Expand Down

0 comments on commit 17f2c13

Please sign in to comment.