Get help information from arguments

This commit is contained in:
Jeroen Engels 2021-10-01 23:50:07 +02:00
parent 07dd5d2fe9
commit 89100d5ae9
3 changed files with 4 additions and 2 deletions

View File

@ -38,6 +38,7 @@ run(
verbose, verbose,
processOpts: { stdio: ['inherit', 'ignore', 'inherit'] }, processOpts: { stdio: ['inherit', 'ignore', 'inherit'] },
}, },
program.helpInformation(),
console.log.bind(console), console.log.bind(console),
).catch((e) => { ).catch((e) => {
if (verbose) { if (verbose) {

View File

@ -14,6 +14,7 @@ export async function run(options: {
verbose: false, verbose: false,
processOpts: options.processOpts || { stdio: ['inherit', 'ignore', 'inherit'] }, processOpts: options.processOpts || { stdio: ['inherit', 'ignore', 'inherit'] },
}, },
'',
() => { } () => { }
); );
} }

View File

@ -1,5 +1,4 @@
// tslint:disable-next-line no-require-imports no-var-requires // tslint:disable-next-line no-require-imports no-var-requires
import program from 'commander';
import * as path from 'path'; import * as path from 'path';
import * as Transform from './transform'; import * as Transform from './transform';
import { toolDefaults } from './types'; import { toolDefaults } from './types';
@ -17,6 +16,7 @@ export async function run(
verbose: boolean, verbose: boolean,
processOpts: { stdio: [string, string, string] }, processOpts: { stdio: [string, string, string] },
}, },
helpInformation: string,
log: (message?: any, ...optionalParams: any[]) => void log: (message?: any, ...optionalParams: any[]) => void
) { ) {
if (!options.outputFilePath) { if (!options.outputFilePath) {
@ -85,7 +85,7 @@ export async function run(
throw new Error('An error occurred when compiling your application with Elm 0.19.1.'); throw new Error('An error occurred when compiling your application with Elm 0.19.1.');
} }
} else { } else {
throw new Error('Please provide a path to an Elm file.\n' + program.helpInformation()); throw new Error(`Please provide a path to an Elm file.\n${helpInformation}`.trim());
} }
if (jsSource != '') { if (jsSource != '') {
const transformed = await Transform.transform( const transformed = await Transform.transform(