fix(config): switch args to an async call, options map
This commit is contained in:
parent
2a5d649d48
commit
7311407d9e
|
@ -17,7 +17,7 @@ export interface ParsedArgs {
|
||||||
project?: Array<string>;
|
project?: Array<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseArgs(args: Array<string>): ParsedArgs {
|
export async function parseArgs(args: Array<string>): Promise<ParsedArgs> {
|
||||||
let mode = Commands.UNKNOWN;
|
let mode = Commands.UNKNOWN;
|
||||||
|
|
||||||
const parser = yargs(args)
|
const parser = yargs(args)
|
||||||
|
@ -44,25 +44,27 @@ export function parseArgs(args: Array<string>): ParsedArgs {
|
||||||
mode = Commands.LABELS;
|
mode = Commands.LABELS;
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.option('config', {
|
.option({
|
||||||
alias: ['c'],
|
config: {
|
||||||
demand: true,
|
alias: ['c'],
|
||||||
desc: 'Config file path',
|
demand: true,
|
||||||
type: 'string',
|
desc: 'Config file path',
|
||||||
})
|
type: 'string',
|
||||||
.option('dryrun', {
|
},
|
||||||
alias: ['d'],
|
dryrun: {
|
||||||
default: true,
|
alias: ['d'],
|
||||||
demand: false,
|
default: true,
|
||||||
desc: 'Run without updating remote labels',
|
demand: false,
|
||||||
type: 'boolean',
|
desc: 'Run without updating remote labels',
|
||||||
})
|
type: 'boolean',
|
||||||
.option('project', {
|
},
|
||||||
alias: ['p'],
|
project: {
|
||||||
array: true,
|
alias: ['p'],
|
||||||
demand: false,
|
array: true,
|
||||||
desc: 'Project names to be run',
|
demand: false,
|
||||||
type: 'string',
|
desc: 'Project names to be run',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.completion()
|
.completion()
|
||||||
.help()
|
.help()
|
||||||
|
@ -70,7 +72,7 @@ export function parseArgs(args: Array<string>): ParsedArgs {
|
||||||
.version(VERSION_INFO.package.version)
|
.version(VERSION_INFO.package.version)
|
||||||
.alias('version', 'v');
|
.alias('version', 'v');
|
||||||
|
|
||||||
const argsWithoutMode: Omit<ParsedArgs, 'mode'> = parser.argv;
|
const argsWithoutMode: Omit<ParsedArgs, 'mode'> = await parser.parse(args);
|
||||||
return {
|
return {
|
||||||
...argsWithoutMode,
|
...argsWithoutMode,
|
||||||
mode,
|
mode,
|
||||||
|
|
|
@ -25,7 +25,7 @@ export const STATUS_FAILURE = 1;
|
||||||
export const STATUS_SUCCESS = 0;
|
export const STATUS_SUCCESS = 0;
|
||||||
|
|
||||||
export async function main(argv: Array<string>): Promise<number> {
|
export async function main(argv: Array<string>): Promise<number> {
|
||||||
const args = parseArgs(argv.slice(ARGS_START));
|
const args = await parseArgs(argv.slice(ARGS_START));
|
||||||
const config = await initConfig(args.config);
|
const config = await initConfig(args.config);
|
||||||
const logger = BunyanLogger.create(config.logger);
|
const logger = BunyanLogger.create(config.logger);
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import sinon from 'sinon';
|
|
||||||
|
|
||||||
import { Commands, parseArgs } from '../../src/config/args';
|
import { Commands, parseArgs } from '../../src/config/args';
|
||||||
|
|
||||||
const { stub } = sinon;
|
|
||||||
|
|
||||||
describe('args', () => {
|
describe('args', () => {
|
||||||
it('should set command mode', () => {
|
it('should set command mode', async () => {
|
||||||
for (const command of [
|
for (const command of [
|
||||||
Commands.GRAPH,
|
Commands.GRAPH,
|
||||||
Commands.ISSUES,
|
Commands.ISSUES,
|
||||||
Commands.LABELS,
|
Commands.LABELS,
|
||||||
]) {
|
]) {
|
||||||
const args = parseArgs([command, '--config', 'foo.yml']);
|
const args = await parseArgs([command, '--config', 'foo.yml']);
|
||||||
expect(args).to.deep.include({
|
expect(args).to.deep.include({
|
||||||
dryrun: true,
|
dryrun: true,
|
||||||
mode: command,
|
mode: command,
|
||||||
|
|
Loading…
Reference in New Issue