1
0
Fork 0

fix(config): switch args to an async call, options map

This commit is contained in:
Sean Sube 2022-11-23 07:46:31 -06:00 committed by supreme-lamp[bot]
parent 2a5d649d48
commit 7311407d9e
3 changed files with 26 additions and 27 deletions

View File

@ -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({
config: {
alias: ['c'], alias: ['c'],
demand: true, demand: true,
desc: 'Config file path', desc: 'Config file path',
type: 'string', type: 'string',
}) },
.option('dryrun', { dryrun: {
alias: ['d'], alias: ['d'],
default: true, default: true,
demand: false, demand: false,
desc: 'Run without updating remote labels', desc: 'Run without updating remote labels',
type: 'boolean', type: 'boolean',
}) },
.option('project', { project: {
alias: ['p'], alias: ['p'],
array: true, array: true,
demand: false, demand: false,
desc: 'Project names to be run', desc: 'Project names to be run',
type: 'string', 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,

View File

@ -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);

View File

@ -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,