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