boostr
Version:
Build and deploy your Layr apps
43 lines • 1.67 kB
JavaScript
import mri from 'mri';
import { throwError } from './utilities.js';
export const GLOBAL_OPTIONS_HELP_OBJECT = {
'--stage': "Selects a stage (default: 'development').",
'--development': 'A shorthand for `--stage=development`.',
'--staging': 'A shorthand for `--stage=staging`.',
'--production': 'A shorthand for `--stage=production`.',
'--version, -v': 'Displays the current Boostr version.',
'--help, -h': 'Displays inline help for a specified service or command.'
};
const BUILT_IN_STAGES = ['development', 'staging', 'production'];
export function parseRawArguments(rawArguments) {
const { _: parsedArguments, ...parsedOptions } = mri(rawArguments);
return { parsedArguments, parsedOptions };
}
export function pullGlobalOptions(parsedOptions) {
const globalOptions = {};
if (parsedOptions.help || parsedOptions.h) {
globalOptions.showHelp = true;
delete parsedOptions.help;
delete parsedOptions.h;
}
if (parsedOptions.version || parsedOptions.v) {
globalOptions.showVersion = true;
delete parsedOptions.version;
delete parsedOptions.v;
}
if (parsedOptions.stage !== undefined) {
if (typeof parsedOptions.stage !== 'string') {
throwError(`The value of the --stage option should be a string`);
}
globalOptions.stage = parsedOptions.stage;
delete parsedOptions.stage;
}
for (const stage of BUILT_IN_STAGES) {
if (parsedOptions[stage]) {
globalOptions.stage = stage;
delete parsedOptions[stage];
}
}
return globalOptions;
}
//# sourceMappingURL=argument-parser.js.map