@artus-cli/artus-cli
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -113,3 +113,3 @@ "use strict"; | ||
const isSameCommandOrCompatible = (matched === null || matched === void 0 ? void 0 : matched.clz) === ctor || (matched && targetCommand && (0, utils_1.checkCommandCompatible)(targetCommand, matched)); | ||
this[optionCacheSymbol] = isSameCommandOrCompatible ? args : parsedCommands.parseArgs(argv, targetCommand); | ||
this[optionCacheSymbol] = isSameCommandOrCompatible ? args : parsedCommands.parseArgs(argv, targetCommand).args; | ||
return this[optionCacheSymbol]; | ||
@@ -116,0 +116,0 @@ }, |
@@ -96,3 +96,6 @@ /// <reference types="yargs-parser" /> | ||
/** parse argv with yargs-parser */ | ||
parseArgs(argv: string | string[], parseCommand?: ParsedCommand): import("yargs-parser").Arguments; | ||
parseArgs(argv: string | string[], parseCommand?: ParsedCommand): { | ||
args: import("yargs-parser").Arguments; | ||
error: ArtusCliError | undefined; | ||
}; | ||
/** match command by argv */ | ||
@@ -99,0 +102,0 @@ matchCommand(argv: string | string[]): MatchResult; |
@@ -236,3 +236,3 @@ "use strict"; | ||
fuzzyMatched: this.root, | ||
args: this.parseArgs(argv), | ||
args: this.parseArgs(argv).args, | ||
// parsed positional result; | ||
@@ -300,19 +300,12 @@ positionalArgs: {}, | ||
}); | ||
return result.argv; | ||
return result; | ||
} | ||
/** match command by argv */ | ||
matchCommand(argv) { | ||
let newArgs; | ||
const result = this._matchCommand(argv); | ||
if (result.matched) { | ||
try { | ||
// parse again with parserOption | ||
newArgs = this.parseArgs(argv, result.matched); | ||
} | ||
catch (e) { | ||
result.error = e; | ||
} | ||
} | ||
// parse again with parserOption and validation | ||
const parseResult = this.parseArgs(argv, result.fuzzyMatched); | ||
result.error = result.error || parseResult.error; | ||
// merge args and positional args | ||
result.args = Object.assign(newArgs || result.args, result.positionalArgs); | ||
result.args = Object.assign(parseResult.args, result.positionalArgs); | ||
return result; | ||
@@ -319,0 +312,0 @@ } |
import parser from 'yargs-parser'; | ||
import { OptionConfig } from '../types'; | ||
import { ArtusCliError } from '../errors'; | ||
export interface ParsedCommandStruct { | ||
@@ -24,3 +25,6 @@ uid: string; | ||
optionConfig?: OptionConfig; | ||
}): parser.DetailedArguments; | ||
}): { | ||
args: parser.Arguments; | ||
error: ArtusCliError | undefined; | ||
}; | ||
/** parse `<options>` or `[option]` and collect args */ | ||
@@ -27,0 +31,0 @@ export declare function parseArgvWithPositional(argv: string[], pos: Positional[], options?: OptionConfig): { |
@@ -53,12 +53,14 @@ "use strict"; | ||
} | ||
const result = yargs_parser_1.default.detailed(argv, parserOption); | ||
const requiredNilOptions = requiredOptions.filter(k => (0, utils_1.isNil)(result.argv[k])); | ||
const parseResult = yargs_parser_1.default.detailed(argv, parserOption); | ||
let error; | ||
const requiredNilOptions = requiredOptions.filter(k => (0, utils_1.isNil)(parseResult.argv[k])); | ||
if (requiredNilOptions.length) { | ||
throw errors_1.errors.required_options(requiredNilOptions); | ||
// check required option | ||
error = errors_1.errors.required_options(requiredNilOptions); | ||
} | ||
// checking for strict options | ||
if (option.optionConfig && option.strictOptions) { | ||
else if (option.optionConfig && option.strictOptions) { | ||
// checking for strict options | ||
const argvs = parseArgvKeySimple(argv); | ||
const notSupportArgvs = new Set(); | ||
Object.keys(result.argv).forEach(key => { | ||
Object.keys(parseResult.argv).forEach(key => { | ||
var _a; | ||
@@ -69,3 +71,3 @@ // _ and -- is built-in key | ||
// checking with alias list | ||
const alias = (result.aliases[key] || []).concat(key); | ||
const alias = (parseResult.aliases[key] || []).concat(key); | ||
if (alias.every(n => !notSupportArgvs.has(n) && !option.optionConfig[n])) { | ||
@@ -79,13 +81,16 @@ const flag = (_a = argvs.find(a => a.parsed === key || a.raw === key)) === null || _a === void 0 ? void 0 : _a.raw; | ||
argvs.forEach(a => { | ||
if (result.argv[a.parsed] === undefined) | ||
if (parseResult.argv[a.parsed] === undefined) | ||
notSupportArgvs.add(a.raw); | ||
}); | ||
if (notSupportArgvs.size) { | ||
throw errors_1.errors.unknown_options(Array.from(notSupportArgvs)); | ||
error = errors_1.errors.unknown_options(Array.from(notSupportArgvs)); | ||
} | ||
} | ||
if (result.error) { | ||
throw errors_1.errors.unknown(result.error.message); | ||
else if (parseResult.error) { | ||
error = errors_1.errors.unknown(parseResult.error.message); | ||
} | ||
return result; | ||
return { | ||
args: parseResult.argv, | ||
error, | ||
}; | ||
} | ||
@@ -92,0 +97,0 @@ exports.parseArgvToArgs = parseArgvToArgs; |
{ | ||
"name": "@artus-cli/artus-cli", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "CLI framework with modern features", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/artus-cli/artus-cli", |
@@ -53,7 +53,3 @@ # @artus-cli/artus-cli | ||
Still in progress, but you can check the following links: | ||
https://artus-cli.github.io | ||
- QuickStart: https://www.yuque.com/atian25/blog/artus-cli | ||
- RFC: https://github.com/artus-cli/artus-cli/issues/18 | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73390
1710
55