2023-04-21 14:57:54 +00:00
var _ _classPrivateFieldSet = ( this && this . _ _classPrivateFieldSet ) || function ( receiver , state , value , kind , f ) {
if ( kind === "m" ) throw new TypeError ( "Private method is not writable" ) ;
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a setter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot write private member to an object whose class did not declare it" ) ;
return ( kind === "a" ? f . call ( receiver , value ) : f ? f . value = value : state . set ( receiver , value ) ) , value ;
} ;
var _ _classPrivateFieldGet = ( this && this . _ _classPrivateFieldGet ) || function ( receiver , state , kind , f ) {
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a getter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot read private member from an object whose class did not declare it" ) ;
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
} ;
2023-04-21 16:12:50 +00:00
var _YargsInstance _command , _YargsInstance _cwd , _YargsInstance _context , _YargsInstance _completion , _YargsInstance _completionCommand , _YargsInstance _defaultShowHiddenOpt , _YargsInstance _exitError , _YargsInstance _detectLocale , _YargsInstance _emittedWarnings , _YargsInstance _exitProcess , _YargsInstance _frozens , _YargsInstance _globalMiddleware , _YargsInstance _groups , _YargsInstance _hasOutput , _YargsInstance _helpOpt , _YargsInstance _isGlobalContext , _YargsInstance _logger , _YargsInstance _output , _YargsInstance _options , _YargsInstance _parentRequire , _YargsInstance _parserConfig , _YargsInstance _parseFn , _YargsInstance _parseContext , _YargsInstance _pkgs , _YargsInstance _preservedGroups , _YargsInstance _processArgs , _YargsInstance _recommendCommands , _YargsInstance _shim , _YargsInstance _strict , _YargsInstance _strictCommands , _YargsInstance _strictOptions , _YargsInstance _usage , _YargsInstance _usageConfig , _YargsInstance _versionOpt , _YargsInstance _validation ;
2023-04-21 14:57:54 +00:00
import { command as Command , } from './command.js' ;
import { assertNotStrictEqual , assertSingleKey , objectKeys , } from './typings/common-types.js' ;
import { YError } from './yerror.js' ;
import { usage as Usage } from './usage.js' ;
import { argsert } from './argsert.js' ;
import { completion as Completion , } from './completion.js' ;
import { validation as Validation , } from './validation.js' ;
import { objFilter } from './utils/obj-filter.js' ;
import { applyExtends } from './utils/apply-extends.js' ;
import { applyMiddleware , GlobalMiddleware , } from './middleware.js' ;
import { isPromise } from './utils/is-promise.js' ;
import { maybeAsyncResult } from './utils/maybe-async-result.js' ;
import setBlocking from './utils/set-blocking.js' ;
export function YargsFactory ( _shim ) {
return ( processArgs = [ ] , cwd = _shim . process . cwd ( ) , parentRequire ) => {
const yargs = new YargsInstance ( processArgs , cwd , parentRequire , _shim ) ;
Object . defineProperty ( yargs , 'argv' , {
get : ( ) => {
return yargs . parse ( ) ;
} ,
enumerable : true ,
} ) ;
yargs . help ( ) ;
yargs . version ( ) ;
return yargs ;
} ;
}
const kCopyDoubleDash = Symbol ( 'copyDoubleDash' ) ;
const kCreateLogger = Symbol ( 'copyDoubleDash' ) ;
const kDeleteFromParserHintObject = Symbol ( 'deleteFromParserHintObject' ) ;
const kEmitWarning = Symbol ( 'emitWarning' ) ;
const kFreeze = Symbol ( 'freeze' ) ;
const kGetDollarZero = Symbol ( 'getDollarZero' ) ;
const kGetParserConfiguration = Symbol ( 'getParserConfiguration' ) ;
2023-04-21 16:12:50 +00:00
const kGetUsageConfiguration = Symbol ( 'getUsageConfiguration' ) ;
2023-04-21 14:57:54 +00:00
const kGuessLocale = Symbol ( 'guessLocale' ) ;
const kGuessVersion = Symbol ( 'guessVersion' ) ;
const kParsePositionalNumbers = Symbol ( 'parsePositionalNumbers' ) ;
const kPkgUp = Symbol ( 'pkgUp' ) ;
const kPopulateParserHintArray = Symbol ( 'populateParserHintArray' ) ;
const kPopulateParserHintSingleValueDictionary = Symbol ( 'populateParserHintSingleValueDictionary' ) ;
const kPopulateParserHintArrayDictionary = Symbol ( 'populateParserHintArrayDictionary' ) ;
const kPopulateParserHintDictionary = Symbol ( 'populateParserHintDictionary' ) ;
const kSanitizeKey = Symbol ( 'sanitizeKey' ) ;
const kSetKey = Symbol ( 'setKey' ) ;
const kUnfreeze = Symbol ( 'unfreeze' ) ;
const kValidateAsync = Symbol ( 'validateAsync' ) ;
const kGetCommandInstance = Symbol ( 'getCommandInstance' ) ;
const kGetContext = Symbol ( 'getContext' ) ;
const kGetHasOutput = Symbol ( 'getHasOutput' ) ;
const kGetLoggerInstance = Symbol ( 'getLoggerInstance' ) ;
const kGetParseContext = Symbol ( 'getParseContext' ) ;
const kGetUsageInstance = Symbol ( 'getUsageInstance' ) ;
const kGetValidationInstance = Symbol ( 'getValidationInstance' ) ;
const kHasParseCallback = Symbol ( 'hasParseCallback' ) ;
2023-04-21 16:12:50 +00:00
const kIsGlobalContext = Symbol ( 'isGlobalContext' ) ;
2023-04-21 14:57:54 +00:00
const kPostProcess = Symbol ( 'postProcess' ) ;
const kRebase = Symbol ( 'rebase' ) ;
const kReset = Symbol ( 'reset' ) ;
const kRunYargsParserAndExecuteCommands = Symbol ( 'runYargsParserAndExecuteCommands' ) ;
const kRunValidation = Symbol ( 'runValidation' ) ;
const kSetHasOutput = Symbol ( 'setHasOutput' ) ;
const kTrackManuallySetKeys = Symbol ( 'kTrackManuallySetKeys' ) ;
export class YargsInstance {
constructor ( processArgs = [ ] , cwd , parentRequire , shim ) {
this . customScriptName = false ;
this . parsed = false ;
_YargsInstance _command . set ( this , void 0 ) ;
_YargsInstance _cwd . set ( this , void 0 ) ;
_YargsInstance _context . set ( this , { commands : [ ] , fullCommands : [ ] } ) ;
_YargsInstance _completion . set ( this , null ) ;
_YargsInstance _completionCommand . set ( this , null ) ;
_YargsInstance _defaultShowHiddenOpt . set ( this , 'show-hidden' ) ;
_YargsInstance _exitError . set ( this , null ) ;
_YargsInstance _detectLocale . set ( this , true ) ;
_YargsInstance _emittedWarnings . set ( this , { } ) ;
_YargsInstance _exitProcess . set ( this , true ) ;
_YargsInstance _frozens . set ( this , [ ] ) ;
_YargsInstance _globalMiddleware . set ( this , void 0 ) ;
_YargsInstance _groups . set ( this , { } ) ;
_YargsInstance _hasOutput . set ( this , false ) ;
_YargsInstance _helpOpt . set ( this , null ) ;
2023-04-21 16:12:50 +00:00
_YargsInstance _isGlobalContext . set ( this , true ) ;
2023-04-21 14:57:54 +00:00
_YargsInstance _logger . set ( this , void 0 ) ;
_YargsInstance _output . set ( this , '' ) ;
_YargsInstance _options . set ( this , void 0 ) ;
_YargsInstance _parentRequire . set ( this , void 0 ) ;
_YargsInstance _parserConfig . set ( this , { } ) ;
_YargsInstance _parseFn . set ( this , null ) ;
_YargsInstance _parseContext . set ( this , null ) ;
_YargsInstance _pkgs . set ( this , { } ) ;
_YargsInstance _preservedGroups . set ( this , { } ) ;
_YargsInstance _processArgs . set ( this , void 0 ) ;
_YargsInstance _recommendCommands . set ( this , false ) ;
_YargsInstance _shim . set ( this , void 0 ) ;
_YargsInstance _strict . set ( this , false ) ;
_YargsInstance _strictCommands . set ( this , false ) ;
_YargsInstance _strictOptions . set ( this , false ) ;
_YargsInstance _usage . set ( this , void 0 ) ;
2023-04-21 16:12:50 +00:00
_YargsInstance _usageConfig . set ( this , { } ) ;
2023-04-21 14:57:54 +00:00
_YargsInstance _versionOpt . set ( this , null ) ;
_YargsInstance _validation . set ( this , void 0 ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _shim , shim , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _processArgs , processArgs , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _cwd , cwd , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _parentRequire , parentRequire , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _globalMiddleware , new GlobalMiddleware ( this ) , "f" ) ;
this . $0 = this [ kGetDollarZero ] ( ) ;
this [ kReset ] ( ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _command , _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _usage , _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _validation , _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _options , _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) , "f" ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . showHiddenOpt = _ _classPrivateFieldGet ( this , _YargsInstance _defaultShowHiddenOpt , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _logger , this [ kCreateLogger ] ( ) , "f" ) ;
}
addHelpOpt ( opt , msg ) {
const defaultHelpOpt = 'help' ;
argsert ( '[string|boolean] [string]' , [ opt , msg ] , arguments . length ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ) {
this [ kDeleteFromParserHintObject ] ( _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _helpOpt , null , "f" ) ;
}
if ( opt === false && msg === undefined )
return this ;
_ _classPrivateFieldSet ( this , _YargsInstance _helpOpt , typeof opt === 'string' ? opt : defaultHelpOpt , "f" ) ;
this . boolean ( _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ) ;
this . describe ( _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) , msg || _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . deferY18nLookup ( 'Show help' ) ) ;
return this ;
}
help ( opt , msg ) {
return this . addHelpOpt ( opt , msg ) ;
}
addShowHiddenOpt ( opt , msg ) {
argsert ( '[string|boolean] [string]' , [ opt , msg ] , arguments . length ) ;
if ( opt === false && msg === undefined )
return this ;
const showHiddenOpt = typeof opt === 'string' ? opt : _ _classPrivateFieldGet ( this , _YargsInstance _defaultShowHiddenOpt , "f" ) ;
this . boolean ( showHiddenOpt ) ;
this . describe ( showHiddenOpt , msg || _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . deferY18nLookup ( 'Show hidden options' ) ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . showHiddenOpt = showHiddenOpt ;
return this ;
}
showHidden ( opt , msg ) {
return this . addShowHiddenOpt ( opt , msg ) ;
}
alias ( key , value ) {
argsert ( '<object|string|array> [string|array]' , [ key , value ] , arguments . length ) ;
this [ kPopulateParserHintArrayDictionary ] ( this . alias . bind ( this ) , 'alias' , key , value ) ;
return this ;
}
array ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'array' , keys ) ;
this [ kTrackManuallySetKeys ] ( keys ) ;
return this ;
}
boolean ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'boolean' , keys ) ;
this [ kTrackManuallySetKeys ] ( keys ) ;
return this ;
}
check ( f , global ) {
argsert ( '<function> [boolean]' , [ f , global ] , arguments . length ) ;
this . middleware ( ( argv , _yargs ) => {
return maybeAsyncResult ( ( ) => {
return f ( argv , _yargs . getOptions ( ) ) ;
} , ( result ) => {
if ( ! result ) {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . fail ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . y18n . _ _ ( 'Argument check failed: %s' , f . toString ( ) ) ) ;
}
else if ( typeof result === 'string' || result instanceof Error ) {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . fail ( result . toString ( ) , result ) ;
}
return argv ;
} , ( err ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . fail ( err . message ? err . message : err . toString ( ) , err ) ;
return argv ;
} ) ;
} , false , global ) ;
return this ;
}
choices ( key , value ) {
argsert ( '<object|string|array> [string|array]' , [ key , value ] , arguments . length ) ;
this [ kPopulateParserHintArrayDictionary ] ( this . choices . bind ( this ) , 'choices' , key , value ) ;
return this ;
}
coerce ( keys , value ) {
argsert ( '<object|string|array> [function]' , [ keys , value ] , arguments . length ) ;
if ( Array . isArray ( keys ) ) {
if ( ! value ) {
throw new YError ( 'coerce callback must be provided' ) ;
}
for ( const key of keys ) {
this . coerce ( key , value ) ;
}
return this ;
}
else if ( typeof keys === 'object' ) {
for ( const key of Object . keys ( keys ) ) {
this . coerce ( key , keys [ key ] ) ;
}
return this ;
}
if ( ! value ) {
throw new YError ( 'coerce callback must be provided' ) ;
}
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . key [ keys ] = true ;
_ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . addCoerceMiddleware ( ( argv , yargs ) => {
let aliases ;
2023-04-21 16:12:50 +00:00
const shouldCoerce = Object . prototype . hasOwnProperty . call ( argv , keys ) ;
if ( ! shouldCoerce ) {
return argv ;
}
2023-04-21 14:57:54 +00:00
return maybeAsyncResult ( ( ) => {
aliases = yargs . getAliases ( ) ;
return value ( argv [ keys ] ) ;
} , ( result ) => {
argv [ keys ] = result ;
2023-04-21 16:12:50 +00:00
const stripAliased = yargs
. getInternalMethods ( )
. getParserConfiguration ( ) [ 'strip-aliased' ] ;
if ( aliases [ keys ] && stripAliased !== true ) {
2023-04-21 14:57:54 +00:00
for ( const alias of aliases [ keys ] ) {
argv [ alias ] = result ;
}
}
return argv ;
} , ( err ) => {
throw new YError ( err . message ) ;
} ) ;
} , keys ) ;
return this ;
}
conflicts ( key1 , key2 ) {
argsert ( '<string|object> [string|array]' , [ key1 , key2 ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . conflicts ( key1 , key2 ) ;
return this ;
}
config ( key = 'config' , msg , parseFn ) {
argsert ( '[object|string] [string|function] [function]' , [ key , msg , parseFn ] , arguments . length ) ;
if ( typeof key === 'object' && ! Array . isArray ( key ) ) {
key = applyExtends ( key , _ _classPrivateFieldGet ( this , _YargsInstance _cwd , "f" ) , this [ kGetParserConfiguration ] ( ) [ 'deep-merge-config' ] || false , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects = ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects || [ ] ) . concat ( key ) ;
return this ;
}
if ( typeof msg === 'function' ) {
parseFn = msg ;
msg = undefined ;
}
this . describe ( key , msg || _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . deferY18nLookup ( 'Path to JSON config file' ) ) ;
( Array . isArray ( key ) ? key : [ key ] ) . forEach ( k => {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . config [ k ] = parseFn || true ;
} ) ;
return this ;
}
completion ( cmd , desc , fn ) {
argsert ( '[string] [string|boolean|function] [function]' , [ cmd , desc , fn ] , arguments . length ) ;
if ( typeof desc === 'function' ) {
fn = desc ;
desc = undefined ;
}
_ _classPrivateFieldSet ( this , _YargsInstance _completionCommand , cmd || _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) || 'completion' , "f" ) ;
if ( ! desc && desc !== false ) {
desc = 'generate completion script' ;
}
this . command ( _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) , desc ) ;
if ( fn )
_ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . registerFunction ( fn ) ;
return this ;
}
command ( cmd , description , builder , handler , middlewares , deprecated ) {
argsert ( '<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]' , [ cmd , description , builder , handler , middlewares , deprecated ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . addHandler ( cmd , description , builder , handler , middlewares , deprecated ) ;
return this ;
}
commands ( cmd , description , builder , handler , middlewares , deprecated ) {
return this . command ( cmd , description , builder , handler , middlewares , deprecated ) ;
}
commandDir ( dir , opts ) {
argsert ( '<string> [object]' , [ dir , opts ] , arguments . length ) ;
const req = _ _classPrivateFieldGet ( this , _YargsInstance _parentRequire , "f" ) || _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . require ;
_ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . addDirectory ( dir , req , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getCallerFile ( ) , opts ) ;
return this ;
}
count ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'count' , keys ) ;
this [ kTrackManuallySetKeys ] ( keys ) ;
return this ;
}
default ( key , value , defaultDescription ) {
argsert ( '<object|string|array> [*] [string]' , [ key , value , defaultDescription ] , arguments . length ) ;
if ( defaultDescription ) {
assertSingleKey ( key , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . defaultDescription [ key ] = defaultDescription ;
}
if ( typeof value === 'function' ) {
assertSingleKey ( key , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . defaultDescription [ key ] )
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . defaultDescription [ key ] =
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . functionDescription ( value ) ;
value = value . call ( ) ;
}
this [ kPopulateParserHintSingleValueDictionary ] ( this . default . bind ( this ) , 'default' , key , value ) ;
return this ;
}
defaults ( key , value , defaultDescription ) {
return this . default ( key , value , defaultDescription ) ;
}
demandCommand ( min = 1 , max , minMsg , maxMsg ) {
argsert ( '[number] [number|string] [string|null|undefined] [string|null|undefined]' , [ min , max , minMsg , maxMsg ] , arguments . length ) ;
if ( typeof max !== 'number' ) {
minMsg = max ;
max = Infinity ;
}
this . global ( '_' , false ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . demandedCommands . _ = {
min ,
max ,
minMsg ,
maxMsg ,
} ;
return this ;
}
demand ( keys , max , msg ) {
if ( Array . isArray ( max ) ) {
max . forEach ( key => {
assertNotStrictEqual ( msg , true , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
this . demandOption ( key , msg ) ;
} ) ;
max = Infinity ;
}
else if ( typeof max !== 'number' ) {
msg = max ;
max = Infinity ;
}
if ( typeof keys === 'number' ) {
assertNotStrictEqual ( msg , true , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
this . demandCommand ( keys , max , msg , msg ) ;
}
else if ( Array . isArray ( keys ) ) {
keys . forEach ( key => {
assertNotStrictEqual ( msg , true , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
this . demandOption ( key , msg ) ;
} ) ;
}
else {
if ( typeof msg === 'string' ) {
this . demandOption ( keys , msg ) ;
}
else if ( msg === true || typeof msg === 'undefined' ) {
this . demandOption ( keys ) ;
}
}
return this ;
}
demandOption ( keys , msg ) {
argsert ( '<object|string|array> [string]' , [ keys , msg ] , arguments . length ) ;
this [ kPopulateParserHintSingleValueDictionary ] ( this . demandOption . bind ( this ) , 'demandedOptions' , keys , msg ) ;
return this ;
}
deprecateOption ( option , message ) {
argsert ( '<string> [string|boolean]' , [ option , message ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . deprecatedOptions [ option ] = message ;
return this ;
}
describe ( keys , description ) {
argsert ( '<object|string|array> [string]' , [ keys , description ] , arguments . length ) ;
this [ kSetKey ] ( keys , true ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . describe ( keys , description ) ;
return this ;
}
detectLocale ( detect ) {
argsert ( '<boolean>' , [ detect ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _detectLocale , detect , "f" ) ;
return this ;
}
env ( prefix ) {
argsert ( '[string|boolean]' , [ prefix ] , arguments . length ) ;
if ( prefix === false )
delete _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . envPrefix ;
else
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . envPrefix = prefix || '' ;
return this ;
}
epilogue ( msg ) {
argsert ( '<string>' , [ msg ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . epilog ( msg ) ;
return this ;
}
epilog ( msg ) {
return this . epilogue ( msg ) ;
}
example ( cmd , description ) {
argsert ( '<string|array> [string]' , [ cmd , description ] , arguments . length ) ;
if ( Array . isArray ( cmd ) ) {
cmd . forEach ( exampleParams => this . example ( ... exampleParams ) ) ;
}
else {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . example ( cmd , description ) ;
}
return this ;
}
exit ( code , err ) {
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _exitError , err , "f" ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) )
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . exit ( code ) ;
}
exitProcess ( enabled = true ) {
argsert ( '[boolean]' , [ enabled ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _exitProcess , enabled , "f" ) ;
return this ;
}
fail ( f ) {
argsert ( '<function|boolean>' , [ f ] , arguments . length ) ;
if ( typeof f === 'boolean' && f !== false ) {
throw new YError ( "Invalid first argument. Expected function or boolean 'false'" ) ;
}
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . failFn ( f ) ;
return this ;
}
getAliases ( ) {
return this . parsed ? this . parsed . aliases : { } ;
}
async getCompletion ( args , done ) {
argsert ( '<array> [function]' , [ args , done ] , arguments . length ) ;
if ( ! done ) {
return new Promise ( ( resolve , reject ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . getCompletion ( args , ( err , completions ) => {
if ( err )
reject ( err ) ;
else
resolve ( completions ) ;
} ) ;
} ) ;
}
else {
return _ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . getCompletion ( args , done ) ;
}
}
getDemandedOptions ( ) {
argsert ( [ ] , 0 ) ;
return _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . demandedOptions ;
}
getDemandedCommands ( ) {
argsert ( [ ] , 0 ) ;
return _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . demandedCommands ;
}
getDeprecatedOptions ( ) {
argsert ( [ ] , 0 ) ;
return _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . deprecatedOptions ;
}
getDetectLocale ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _detectLocale , "f" ) ;
}
getExitProcess ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) ;
}
getGroups ( ) {
return Object . assign ( { } , _ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _preservedGroups , "f" ) ) ;
}
getHelp ( ) {
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . hasCachedHelpMessage ( ) ) {
if ( ! this . parsed ) {
const parse = this [ kRunYargsParserAndExecuteCommands ] ( _ _classPrivateFieldGet ( this , _YargsInstance _processArgs , "f" ) , undefined , undefined , 0 , true ) ;
if ( isPromise ( parse ) ) {
return parse . then ( ( ) => {
return _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . help ( ) ;
} ) ;
}
}
const builderResponse = _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . runDefaultBuilderOn ( this ) ;
if ( isPromise ( builderResponse ) ) {
return builderResponse . then ( ( ) => {
return _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . help ( ) ;
} ) ;
}
}
return Promise . resolve ( _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . help ( ) ) ;
}
getOptions ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) ;
}
getStrict ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _strict , "f" ) ;
}
getStrictCommands ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _strictCommands , "f" ) ;
}
getStrictOptions ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _strictOptions , "f" ) ;
}
global ( globals , global ) {
argsert ( '<string|array> [boolean]' , [ globals , global ] , arguments . length ) ;
globals = [ ] . concat ( globals ) ;
if ( global !== false ) {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . local = _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . local . filter ( l => globals . indexOf ( l ) === - 1 ) ;
}
else {
globals . forEach ( g => {
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . local . includes ( g ) )
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . local . push ( g ) ;
} ) ;
}
return this ;
}
group ( opts , groupName ) {
argsert ( '<string|array> <string>' , [ opts , groupName ] , arguments . length ) ;
const existing = _ _classPrivateFieldGet ( this , _YargsInstance _preservedGroups , "f" ) [ groupName ] || _ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) [ groupName ] ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _preservedGroups , "f" ) [ groupName ] ) {
delete _ _classPrivateFieldGet ( this , _YargsInstance _preservedGroups , "f" ) [ groupName ] ;
}
const seen = { } ;
_ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) [ groupName ] = ( existing || [ ] ) . concat ( opts ) . filter ( key => {
if ( seen [ key ] )
return false ;
return ( seen [ key ] = true ) ;
} ) ;
return this ;
}
hide ( key ) {
argsert ( '<string>' , [ key ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . hiddenOptions . push ( key ) ;
return this ;
}
implies ( key , value ) {
argsert ( '<string|object> [number|string|array]' , [ key , value ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . implies ( key , value ) ;
return this ;
}
locale ( locale ) {
argsert ( '[string]' , [ locale ] , arguments . length ) ;
2023-04-21 16:12:50 +00:00
if ( locale === undefined ) {
2023-04-21 14:57:54 +00:00
this [ kGuessLocale ] ( ) ;
return _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . y18n . getLocale ( ) ;
}
_ _classPrivateFieldSet ( this , _YargsInstance _detectLocale , false , "f" ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . y18n . setLocale ( locale ) ;
return this ;
}
middleware ( callback , applyBeforeValidation , global ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . addMiddleware ( callback , ! ! applyBeforeValidation , global ) ;
}
nargs ( key , value ) {
argsert ( '<string|object|array> [number]' , [ key , value ] , arguments . length ) ;
this [ kPopulateParserHintSingleValueDictionary ] ( this . nargs . bind ( this ) , 'narg' , key , value ) ;
return this ;
}
normalize ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'normalize' , keys ) ;
return this ;
}
number ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'number' , keys ) ;
this [ kTrackManuallySetKeys ] ( keys ) ;
return this ;
}
option ( key , opt ) {
argsert ( '<string|object> [object]' , [ key , opt ] , arguments . length ) ;
if ( typeof key === 'object' ) {
Object . keys ( key ) . forEach ( k => {
this . options ( k , key [ k ] ) ;
} ) ;
}
else {
if ( typeof opt !== 'object' ) {
opt = { } ;
}
this [ kTrackManuallySetKeys ] ( key ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) && ( key === 'version' || ( opt === null || opt === void 0 ? void 0 : opt . alias ) === 'version' ) ) {
this [ kEmitWarning ] ( [
'"version" is a reserved word.' ,
'Please do one of the following:' ,
'- Disable version with `yargs.version(false)` if using "version" as an option' ,
'- Use the built-in `yargs.version` method instead (if applicable)' ,
'- Use a different option key' ,
'https://yargs.js.org/docs/#api-reference-version' ,
] . join ( '\n' ) , undefined , 'versionWarning' ) ;
}
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . key [ key ] = true ;
if ( opt . alias )
this . alias ( key , opt . alias ) ;
const deprecate = opt . deprecate || opt . deprecated ;
if ( deprecate ) {
this . deprecateOption ( key , deprecate ) ;
}
const demand = opt . demand || opt . required || opt . require ;
if ( demand ) {
this . demand ( key , demand ) ;
}
if ( opt . demandOption ) {
this . demandOption ( key , typeof opt . demandOption === 'string' ? opt . demandOption : undefined ) ;
}
if ( opt . conflicts ) {
this . conflicts ( key , opt . conflicts ) ;
}
if ( 'default' in opt ) {
this . default ( key , opt . default ) ;
}
if ( opt . implies !== undefined ) {
this . implies ( key , opt . implies ) ;
}
if ( opt . nargs !== undefined ) {
this . nargs ( key , opt . nargs ) ;
}
if ( opt . config ) {
this . config ( key , opt . configParser ) ;
}
if ( opt . normalize ) {
this . normalize ( key ) ;
}
if ( opt . choices ) {
this . choices ( key , opt . choices ) ;
}
if ( opt . coerce ) {
this . coerce ( key , opt . coerce ) ;
}
if ( opt . group ) {
this . group ( key , opt . group ) ;
}
if ( opt . boolean || opt . type === 'boolean' ) {
this . boolean ( key ) ;
if ( opt . alias )
this . boolean ( opt . alias ) ;
}
if ( opt . array || opt . type === 'array' ) {
this . array ( key ) ;
if ( opt . alias )
this . array ( opt . alias ) ;
}
if ( opt . number || opt . type === 'number' ) {
this . number ( key ) ;
if ( opt . alias )
this . number ( opt . alias ) ;
}
if ( opt . string || opt . type === 'string' ) {
this . string ( key ) ;
if ( opt . alias )
this . string ( opt . alias ) ;
}
if ( opt . count || opt . type === 'count' ) {
this . count ( key ) ;
}
if ( typeof opt . global === 'boolean' ) {
this . global ( key , opt . global ) ;
}
if ( opt . defaultDescription ) {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . defaultDescription [ key ] = opt . defaultDescription ;
}
if ( opt . skipValidation ) {
this . skipValidation ( key ) ;
}
const desc = opt . describe || opt . description || opt . desc ;
2023-04-21 16:12:50 +00:00
const descriptions = _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . getDescriptions ( ) ;
if ( ! Object . prototype . hasOwnProperty . call ( descriptions , key ) ||
typeof desc === 'string' ) {
this . describe ( key , desc ) ;
}
2023-04-21 14:57:54 +00:00
if ( opt . hidden ) {
this . hide ( key ) ;
}
if ( opt . requiresArg ) {
this . requiresArg ( key ) ;
}
}
return this ;
}
options ( key , opt ) {
return this . option ( key , opt ) ;
}
parse ( args , shortCircuit , _parseFn ) {
argsert ( '[string|array] [function|boolean|object] [function]' , [ args , shortCircuit , _parseFn ] , arguments . length ) ;
this [ kFreeze ] ( ) ;
if ( typeof args === 'undefined' ) {
args = _ _classPrivateFieldGet ( this , _YargsInstance _processArgs , "f" ) ;
}
if ( typeof shortCircuit === 'object' ) {
_ _classPrivateFieldSet ( this , _YargsInstance _parseContext , shortCircuit , "f" ) ;
shortCircuit = _parseFn ;
}
if ( typeof shortCircuit === 'function' ) {
_ _classPrivateFieldSet ( this , _YargsInstance _parseFn , shortCircuit , "f" ) ;
shortCircuit = false ;
}
if ( ! shortCircuit )
_ _classPrivateFieldSet ( this , _YargsInstance _processArgs , args , "f" ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) )
_ _classPrivateFieldSet ( this , _YargsInstance _exitProcess , false , "f" ) ;
const parsed = this [ kRunYargsParserAndExecuteCommands ] ( args , ! ! shortCircuit ) ;
const tmpParsed = this . parsed ;
_ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . setParsed ( this . parsed ) ;
if ( isPromise ( parsed ) ) {
return parsed
. then ( argv => {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) )
_ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) . call ( this , _ _classPrivateFieldGet ( this , _YargsInstance _exitError , "f" ) , argv , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) ) ;
return argv ;
} )
. catch ( err => {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) ) {
_ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) ( err , this . parsed . argv , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) ) ;
}
throw err ;
} )
. finally ( ( ) => {
this [ kUnfreeze ] ( ) ;
this . parsed = tmpParsed ;
} ) ;
}
else {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) )
_ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) . call ( this , _ _classPrivateFieldGet ( this , _YargsInstance _exitError , "f" ) , parsed , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) ) ;
this [ kUnfreeze ] ( ) ;
this . parsed = tmpParsed ;
}
return parsed ;
}
parseAsync ( args , shortCircuit , _parseFn ) {
const maybePromise = this . parse ( args , shortCircuit , _parseFn ) ;
return ! isPromise ( maybePromise )
? Promise . resolve ( maybePromise )
: maybePromise ;
}
parseSync ( args , shortCircuit , _parseFn ) {
const maybePromise = this . parse ( args , shortCircuit , _parseFn ) ;
if ( isPromise ( maybePromise ) ) {
throw new YError ( '.parseSync() must not be used with asynchronous builders, handlers, or middleware' ) ;
}
return maybePromise ;
}
parserConfiguration ( config ) {
argsert ( '<object>' , [ config ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _parserConfig , config , "f" ) ;
return this ;
}
pkgConf ( key , rootPath ) {
argsert ( '<string> [string]' , [ key , rootPath ] , arguments . length ) ;
let conf = null ;
const obj = this [ kPkgUp ] ( rootPath || _ _classPrivateFieldGet ( this , _YargsInstance _cwd , "f" ) ) ;
if ( obj [ key ] && typeof obj [ key ] === 'object' ) {
conf = applyExtends ( obj [ key ] , rootPath || _ _classPrivateFieldGet ( this , _YargsInstance _cwd , "f" ) , this [ kGetParserConfiguration ] ( ) [ 'deep-merge-config' ] || false , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects = ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects || [ ] ) . concat ( conf ) ;
}
return this ;
}
positional ( key , opts ) {
argsert ( '<string> <object>' , [ key , opts ] , arguments . length ) ;
const supportedOpts = [
'default' ,
'defaultDescription' ,
'implies' ,
'normalize' ,
'choices' ,
'conflicts' ,
'coerce' ,
'type' ,
'describe' ,
'desc' ,
'description' ,
'alias' ,
] ;
opts = objFilter ( opts , ( k , v ) => {
if ( k === 'type' && ! [ 'string' , 'number' , 'boolean' ] . includes ( v ) )
return false ;
return supportedOpts . includes ( k ) ;
} ) ;
const fullCommand = _ _classPrivateFieldGet ( this , _YargsInstance _context , "f" ) . fullCommands [ _ _classPrivateFieldGet ( this , _YargsInstance _context , "f" ) . fullCommands . length - 1 ] ;
const parseOptions = fullCommand
? _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . cmdToParseOptions ( fullCommand )
: {
array : [ ] ,
alias : { } ,
default : { } ,
demand : { } ,
} ;
objectKeys ( parseOptions ) . forEach ( pk => {
const parseOption = parseOptions [ pk ] ;
if ( Array . isArray ( parseOption ) ) {
if ( parseOption . indexOf ( key ) !== - 1 )
opts [ pk ] = true ;
}
else {
if ( parseOption [ key ] && ! ( pk in opts ) )
opts [ pk ] = parseOption [ key ] ;
}
} ) ;
this . group ( key , _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . getPositionalGroupName ( ) ) ;
return this . option ( key , opts ) ;
}
recommendCommands ( recommend = true ) {
argsert ( '[boolean]' , [ recommend ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _recommendCommands , recommend , "f" ) ;
return this ;
}
required ( keys , max , msg ) {
return this . demand ( keys , max , msg ) ;
}
require ( keys , max , msg ) {
return this . demand ( keys , max , msg ) ;
}
requiresArg ( keys ) {
argsert ( '<array|string|object> [number]' , [ keys ] , arguments . length ) ;
if ( typeof keys === 'string' && _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . narg [ keys ] ) {
return this ;
}
else {
this [ kPopulateParserHintSingleValueDictionary ] ( this . requiresArg . bind ( this ) , 'narg' , keys , NaN ) ;
}
return this ;
}
showCompletionScript ( $0 , cmd ) {
argsert ( '[string] [string]' , [ $0 , cmd ] , arguments . length ) ;
$0 = $0 || this . $0 ;
_ _classPrivateFieldGet ( this , _YargsInstance _logger , "f" ) . log ( _ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . generateCompletionScript ( $0 , cmd || _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) || 'completion' ) ) ;
return this ;
}
showHelp ( level ) {
argsert ( '[string|function]' , [ level ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . hasCachedHelpMessage ( ) ) {
if ( ! this . parsed ) {
const parse = this [ kRunYargsParserAndExecuteCommands ] ( _ _classPrivateFieldGet ( this , _YargsInstance _processArgs , "f" ) , undefined , undefined , 0 , true ) ;
if ( isPromise ( parse ) ) {
parse . then ( ( ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showHelp ( level ) ;
} ) ;
return this ;
}
}
const builderResponse = _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . runDefaultBuilderOn ( this ) ;
if ( isPromise ( builderResponse ) ) {
builderResponse . then ( ( ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showHelp ( level ) ;
} ) ;
return this ;
}
}
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showHelp ( level ) ;
return this ;
}
scriptName ( scriptName ) {
this . customScriptName = true ;
this . $0 = scriptName ;
return this ;
}
showHelpOnFail ( enabled , message ) {
argsert ( '[boolean|string] [string]' , [ enabled , message ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showHelpOnFail ( enabled , message ) ;
return this ;
}
showVersion ( level ) {
argsert ( '[string|function]' , [ level ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showVersion ( level ) ;
return this ;
}
skipValidation ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'skipValidation' , keys ) ;
return this ;
}
strict ( enabled ) {
argsert ( '[boolean]' , [ enabled ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _strict , enabled !== false , "f" ) ;
return this ;
}
strictCommands ( enabled ) {
argsert ( '[boolean]' , [ enabled ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _strictCommands , enabled !== false , "f" ) ;
return this ;
}
strictOptions ( enabled ) {
argsert ( '[boolean]' , [ enabled ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _strictOptions , enabled !== false , "f" ) ;
return this ;
}
string ( keys ) {
argsert ( '<array|string>' , [ keys ] , arguments . length ) ;
this [ kPopulateParserHintArray ] ( 'string' , keys ) ;
this [ kTrackManuallySetKeys ] ( keys ) ;
return this ;
}
terminalWidth ( ) {
argsert ( [ ] , 0 ) ;
return _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . stdColumns ;
}
updateLocale ( obj ) {
return this . updateStrings ( obj ) ;
}
updateStrings ( obj ) {
argsert ( '<object>' , [ obj ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _detectLocale , false , "f" ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . y18n . updateLocale ( obj ) ;
return this ;
}
usage ( msg , description , builder , handler ) {
argsert ( '<string|null|undefined> [string|boolean] [function|object] [function]' , [ msg , description , builder , handler ] , arguments . length ) ;
if ( description !== undefined ) {
assertNotStrictEqual ( msg , null , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
if ( ( msg || '' ) . match ( /^\$0( |$)/ ) ) {
return this . command ( msg , description , builder , handler ) ;
}
else {
throw new YError ( '.usage() description must start with $0 if being used as alias for .command()' ) ;
}
}
else {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . usage ( msg ) ;
return this ;
}
}
2023-04-21 16:12:50 +00:00
usageConfiguration ( config ) {
argsert ( '<object>' , [ config ] , arguments . length ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _usageConfig , config , "f" ) ;
return this ;
}
2023-04-21 14:57:54 +00:00
version ( opt , msg , ver ) {
const defaultVersionOpt = 'version' ;
argsert ( '[boolean|string] [string] [string]' , [ opt , msg , ver ] , arguments . length ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) ) {
this [ kDeleteFromParserHintObject ] ( _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . version ( undefined ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _versionOpt , null , "f" ) ;
}
if ( arguments . length === 0 ) {
ver = this [ kGuessVersion ] ( ) ;
opt = defaultVersionOpt ;
}
else if ( arguments . length === 1 ) {
if ( opt === false ) {
return this ;
}
ver = opt ;
opt = defaultVersionOpt ;
}
else if ( arguments . length === 2 ) {
ver = msg ;
msg = undefined ;
}
_ _classPrivateFieldSet ( this , _YargsInstance _versionOpt , typeof opt === 'string' ? opt : defaultVersionOpt , "f" ) ;
msg = msg || _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . deferY18nLookup ( 'Show version number' ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . version ( ver || undefined ) ;
this . boolean ( _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) ) ;
this . describe ( _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) , msg ) ;
return this ;
}
wrap ( cols ) {
argsert ( '<number|null|undefined>' , [ cols ] , arguments . length ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . wrap ( cols ) ;
return this ;
}
2023-04-21 16:12:50 +00:00
[ ( _YargsInstance _command = new WeakMap ( ) , _YargsInstance _cwd = new WeakMap ( ) , _YargsInstance _context = new WeakMap ( ) , _YargsInstance _completion = new WeakMap ( ) , _YargsInstance _completionCommand = new WeakMap ( ) , _YargsInstance _defaultShowHiddenOpt = new WeakMap ( ) , _YargsInstance _exitError = new WeakMap ( ) , _YargsInstance _detectLocale = new WeakMap ( ) , _YargsInstance _emittedWarnings = new WeakMap ( ) , _YargsInstance _exitProcess = new WeakMap ( ) , _YargsInstance _frozens = new WeakMap ( ) , _YargsInstance _globalMiddleware = new WeakMap ( ) , _YargsInstance _groups = new WeakMap ( ) , _YargsInstance _hasOutput = new WeakMap ( ) , _YargsInstance _helpOpt = new WeakMap ( ) , _YargsInstance _isGlobalContext = new WeakMap ( ) , _YargsInstance _logger = new WeakMap ( ) , _YargsInstance _output = new WeakMap ( ) , _YargsInstance _options = new WeakMap ( ) , _YargsInstance _parentRequire = new WeakMap ( ) , _YargsInstance _parserConfig = new WeakMap ( ) , _YargsInstance _parseFn = new WeakMap ( ) , _YargsInstance _parseContext = new WeakMap ( ) , _YargsInstance _pkgs = new WeakMap ( ) , _YargsInstance _preservedGroups = new WeakMap ( ) , _YargsInstance _processArgs = new WeakMap ( ) , _YargsInstance _recommendCommands = new WeakMap ( ) , _YargsInstance _shim = new WeakMap ( ) , _YargsInstance _strict = new WeakMap ( ) , _YargsInstance _strictCommands = new WeakMap ( ) , _YargsInstance _strictOptions = new WeakMap ( ) , _YargsInstance _usage = new WeakMap ( ) , _YargsInstance _usageConfig = new WeakMap ( ) , _YargsInstance _versionOpt = new WeakMap ( ) , _YargsInstance _validation = new WeakMap ( ) , kCopyDoubleDash ) ] ( argv ) {
2023-04-21 14:57:54 +00:00
if ( ! argv . _ || ! argv [ '--' ] )
return argv ;
argv . _ . push . apply ( argv . _ , argv [ '--' ] ) ;
try {
delete argv [ '--' ] ;
}
catch ( _err ) { }
return argv ;
}
[ kCreateLogger ] ( ) {
return {
log : ( ... args ) => {
if ( ! this [ kHasParseCallback ] ( ) )
console . log ( ... args ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) . length )
_ _classPrivateFieldSet ( this , _YargsInstance _output , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) + '\n' , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _output , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) + args . join ( ' ' ) , "f" ) ;
} ,
error : ( ... args ) => {
if ( ! this [ kHasParseCallback ] ( ) )
console . error ( ... args ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) . length )
_ _classPrivateFieldSet ( this , _YargsInstance _output , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) + '\n' , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _output , _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) + args . join ( ' ' ) , "f" ) ;
} ,
} ;
}
[ kDeleteFromParserHintObject ] ( optionKey ) {
objectKeys ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) ) . forEach ( ( hintKey ) => {
if ( ( ( key ) => key === 'configObjects' ) ( hintKey ) )
return ;
const hint = _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ hintKey ] ;
if ( Array . isArray ( hint ) ) {
if ( hint . includes ( optionKey ) )
hint . splice ( hint . indexOf ( optionKey ) , 1 ) ;
}
else if ( typeof hint === 'object' ) {
delete hint [ optionKey ] ;
}
} ) ;
delete _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . getDescriptions ( ) [ optionKey ] ;
}
[ kEmitWarning ] ( warning , type , deduplicationId ) {
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _emittedWarnings , "f" ) [ deduplicationId ] ) {
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . emitWarning ( warning , type ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _emittedWarnings , "f" ) [ deduplicationId ] = true ;
}
}
[ kFreeze ] ( ) {
_ _classPrivateFieldGet ( this , _YargsInstance _frozens , "f" ) . push ( {
options : _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) ,
configObjects : _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects . slice ( 0 ) ,
exitProcess : _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) ,
groups : _ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) ,
strict : _ _classPrivateFieldGet ( this , _YargsInstance _strict , "f" ) ,
strictCommands : _ _classPrivateFieldGet ( this , _YargsInstance _strictCommands , "f" ) ,
strictOptions : _ _classPrivateFieldGet ( this , _YargsInstance _strictOptions , "f" ) ,
completionCommand : _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) ,
output : _ _classPrivateFieldGet ( this , _YargsInstance _output , "f" ) ,
exitError : _ _classPrivateFieldGet ( this , _YargsInstance _exitError , "f" ) ,
hasOutput : _ _classPrivateFieldGet ( this , _YargsInstance _hasOutput , "f" ) ,
parsed : this . parsed ,
parseFn : _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) ,
parseContext : _ _classPrivateFieldGet ( this , _YargsInstance _parseContext , "f" ) ,
} ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . freeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . freeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . freeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . freeze ( ) ;
}
[ kGetDollarZero ] ( ) {
let $0 = '' ;
let default $0 ;
if ( /\b(node|iojs|electron)(\.exe)?$/ . test ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . argv ( ) [ 0 ] ) ) {
default $0 = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . argv ( ) . slice ( 1 , 2 ) ;
}
else {
default $0 = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . argv ( ) . slice ( 0 , 1 ) ;
}
$0 = default $0
. map ( x => {
const b = this [ kRebase ] ( _ _classPrivateFieldGet ( this , _YargsInstance _cwd , "f" ) , x ) ;
return x . match ( /^(\/|([a-zA-Z]:)?\\)/ ) && b . length < x . length ? b : x ;
} )
. join ( ' ' )
. trim ( ) ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( '_' ) &&
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getProcessArgvBin ( ) === _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( '_' ) ) {
$0 = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" )
. getEnv ( '_' )
. replace ( ` ${ _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . path . dirname ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . process . execPath ( ) ) } / ` , '' ) ;
}
return $0 ;
}
[ kGetParserConfiguration ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _parserConfig , "f" ) ;
}
2023-04-21 16:12:50 +00:00
[ kGetUsageConfiguration ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _usageConfig , "f" ) ;
}
2023-04-21 14:57:54 +00:00
[ kGuessLocale ] ( ) {
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _detectLocale , "f" ) )
return ;
const locale = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( 'LC_ALL' ) ||
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( 'LC_MESSAGES' ) ||
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( 'LANG' ) ||
_ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . getEnv ( 'LANGUAGE' ) ||
'en_US' ;
this . locale ( locale . replace ( /[.:].*/ , '' ) ) ;
}
[ kGuessVersion ] ( ) {
const obj = this [ kPkgUp ] ( ) ;
return obj . version || 'unknown' ;
}
[ kParsePositionalNumbers ] ( argv ) {
const args = argv [ '--' ] ? argv [ '--' ] : argv . _ ;
for ( let i = 0 , arg ; ( arg = args [ i ] ) !== undefined ; i ++ ) {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . Parser . looksLikeNumber ( arg ) &&
Number . isSafeInteger ( Math . floor ( parseFloat ( ` ${ arg } ` ) ) ) ) {
args [ i ] = Number ( arg ) ;
}
}
return argv ;
}
[ kPkgUp ] ( rootPath ) {
const npath = rootPath || '*' ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _pkgs , "f" ) [ npath ] )
return _ _classPrivateFieldGet ( this , _YargsInstance _pkgs , "f" ) [ npath ] ;
let obj = { } ;
try {
let startDir = rootPath || _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . mainFilename ;
if ( ! rootPath && _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . path . extname ( startDir ) ) {
startDir = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . path . dirname ( startDir ) ;
}
const pkgJsonPath = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . findUp ( startDir , ( dir , names ) => {
if ( names . includes ( 'package.json' ) ) {
return 'package.json' ;
}
else {
return undefined ;
}
} ) ;
assertNotStrictEqual ( pkgJsonPath , undefined , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
obj = JSON . parse ( _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . readFileSync ( pkgJsonPath , 'utf8' ) ) ;
}
catch ( _noop ) { }
_ _classPrivateFieldGet ( this , _YargsInstance _pkgs , "f" ) [ npath ] = obj || { } ;
return _ _classPrivateFieldGet ( this , _YargsInstance _pkgs , "f" ) [ npath ] ;
}
[ kPopulateParserHintArray ] ( type , keys ) {
keys = [ ] . concat ( keys ) ;
keys . forEach ( key => {
key = this [ kSanitizeKey ] ( key ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ type ] . push ( key ) ;
} ) ;
}
[ kPopulateParserHintSingleValueDictionary ] ( builder , type , key , value ) {
this [ kPopulateParserHintDictionary ] ( builder , type , key , value , ( type , key , value ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ type ] [ key ] = value ;
} ) ;
}
[ kPopulateParserHintArrayDictionary ] ( builder , type , key , value ) {
this [ kPopulateParserHintDictionary ] ( builder , type , key , value , ( type , key , value ) => {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ type ] [ key ] = ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ type ] [ key ] || [ ] ) . concat ( value ) ;
} ) ;
}
[ kPopulateParserHintDictionary ] ( builder , type , key , value , singleKeyHandler ) {
if ( Array . isArray ( key ) ) {
key . forEach ( k => {
builder ( k , value ) ;
} ) ;
}
else if ( ( ( key ) => typeof key === 'object' ) ( key ) ) {
for ( const k of objectKeys ( key ) ) {
builder ( k , key [ k ] ) ;
}
}
else {
singleKeyHandler ( type , this [ kSanitizeKey ] ( key ) , value ) ;
}
}
[ kSanitizeKey ] ( key ) {
if ( key === '__proto__' )
return '___proto___' ;
return key ;
}
[ kSetKey ] ( key , set ) {
this [ kPopulateParserHintSingleValueDictionary ] ( this [ kSetKey ] . bind ( this ) , 'key' , key , set ) ;
return this ;
}
[ kUnfreeze ] ( ) {
var _a , _b , _c , _d , _e , _f , _g , _h , _j , _k , _l , _m ;
const frozen = _ _classPrivateFieldGet ( this , _YargsInstance _frozens , "f" ) . pop ( ) ;
assertNotStrictEqual ( frozen , undefined , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) ;
let configObjects ;
( _a = this , _b = this , _c = this , _d = this , _e = this , _f = this , _g = this , _h = this , _j = this , _k = this , _l = this , _m = this , {
options : ( { set value ( _o ) { _ _classPrivateFieldSet ( _a , _YargsInstance _options , _o , "f" ) ; } } ) . value ,
configObjects ,
exitProcess : ( { set value ( _o ) { _ _classPrivateFieldSet ( _b , _YargsInstance _exitProcess , _o , "f" ) ; } } ) . value ,
groups : ( { set value ( _o ) { _ _classPrivateFieldSet ( _c , _YargsInstance _groups , _o , "f" ) ; } } ) . value ,
output : ( { set value ( _o ) { _ _classPrivateFieldSet ( _d , _YargsInstance _output , _o , "f" ) ; } } ) . value ,
exitError : ( { set value ( _o ) { _ _classPrivateFieldSet ( _e , _YargsInstance _exitError , _o , "f" ) ; } } ) . value ,
hasOutput : ( { set value ( _o ) { _ _classPrivateFieldSet ( _f , _YargsInstance _hasOutput , _o , "f" ) ; } } ) . value ,
parsed : this . parsed ,
strict : ( { set value ( _o ) { _ _classPrivateFieldSet ( _g , _YargsInstance _strict , _o , "f" ) ; } } ) . value ,
strictCommands : ( { set value ( _o ) { _ _classPrivateFieldSet ( _h , _YargsInstance _strictCommands , _o , "f" ) ; } } ) . value ,
strictOptions : ( { set value ( _o ) { _ _classPrivateFieldSet ( _j , _YargsInstance _strictOptions , _o , "f" ) ; } } ) . value ,
completionCommand : ( { set value ( _o ) { _ _classPrivateFieldSet ( _k , _YargsInstance _completionCommand , _o , "f" ) ; } } ) . value ,
parseFn : ( { set value ( _o ) { _ _classPrivateFieldSet ( _l , _YargsInstance _parseFn , _o , "f" ) ; } } ) . value ,
parseContext : ( { set value ( _o ) { _ _classPrivateFieldSet ( _m , _YargsInstance _parseContext , _o , "f" ) ; } } ) . value ,
} = frozen ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects = configObjects ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . unfreeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . unfreeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . unfreeze ( ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . unfreeze ( ) ;
}
[ kValidateAsync ] ( validation , argv ) {
return maybeAsyncResult ( argv , result => {
validation ( result ) ;
return result ;
} ) ;
}
getInternalMethods ( ) {
return {
getCommandInstance : this [ kGetCommandInstance ] . bind ( this ) ,
getContext : this [ kGetContext ] . bind ( this ) ,
getHasOutput : this [ kGetHasOutput ] . bind ( this ) ,
getLoggerInstance : this [ kGetLoggerInstance ] . bind ( this ) ,
getParseContext : this [ kGetParseContext ] . bind ( this ) ,
getParserConfiguration : this [ kGetParserConfiguration ] . bind ( this ) ,
2023-04-21 16:12:50 +00:00
getUsageConfiguration : this [ kGetUsageConfiguration ] . bind ( this ) ,
2023-04-21 14:57:54 +00:00
getUsageInstance : this [ kGetUsageInstance ] . bind ( this ) ,
getValidationInstance : this [ kGetValidationInstance ] . bind ( this ) ,
hasParseCallback : this [ kHasParseCallback ] . bind ( this ) ,
2023-04-21 16:12:50 +00:00
isGlobalContext : this [ kIsGlobalContext ] . bind ( this ) ,
2023-04-21 14:57:54 +00:00
postProcess : this [ kPostProcess ] . bind ( this ) ,
reset : this [ kReset ] . bind ( this ) ,
runValidation : this [ kRunValidation ] . bind ( this ) ,
runYargsParserAndExecuteCommands : this [ kRunYargsParserAndExecuteCommands ] . bind ( this ) ,
setHasOutput : this [ kSetHasOutput ] . bind ( this ) ,
} ;
}
[ kGetCommandInstance ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) ;
}
[ kGetContext ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _context , "f" ) ;
}
[ kGetHasOutput ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _hasOutput , "f" ) ;
}
[ kGetLoggerInstance ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _logger , "f" ) ;
}
[ kGetParseContext ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _parseContext , "f" ) || { } ;
}
[ kGetUsageInstance ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) ;
}
[ kGetValidationInstance ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) ;
}
[ kHasParseCallback ] ( ) {
return ! ! _ _classPrivateFieldGet ( this , _YargsInstance _parseFn , "f" ) ;
}
2023-04-21 16:12:50 +00:00
[ kIsGlobalContext ] ( ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _isGlobalContext , "f" ) ;
}
2023-04-21 14:57:54 +00:00
[ kPostProcess ] ( argv , populateDoubleDash , calledFromCommand , runGlobalMiddleware ) {
if ( calledFromCommand )
return argv ;
if ( isPromise ( argv ) )
return argv ;
if ( ! populateDoubleDash ) {
argv = this [ kCopyDoubleDash ] ( argv ) ;
}
const parsePositionalNumbers = this [ kGetParserConfiguration ] ( ) [ 'parse-positional-numbers' ] ||
this [ kGetParserConfiguration ] ( ) [ 'parse-positional-numbers' ] === undefined ;
if ( parsePositionalNumbers ) {
argv = this [ kParsePositionalNumbers ] ( argv ) ;
}
if ( runGlobalMiddleware ) {
argv = applyMiddleware ( argv , this , _ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . getMiddleware ( ) , false ) ;
}
return argv ;
}
[ kReset ] ( aliases = { } ) {
_ _classPrivateFieldSet ( this , _YargsInstance _options , _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) || { } , "f" ) ;
const tmpOptions = { } ;
tmpOptions . local = _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . local || [ ] ;
tmpOptions . configObjects = _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configObjects || [ ] ;
const localLookup = { } ;
tmpOptions . local . forEach ( l => {
localLookup [ l ] = true ;
( aliases [ l ] || [ ] ) . forEach ( a => {
localLookup [ a ] = true ;
} ) ;
} ) ;
Object . assign ( _ _classPrivateFieldGet ( this , _YargsInstance _preservedGroups , "f" ) , Object . keys ( _ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) ) . reduce ( ( acc , groupName ) => {
const keys = _ _classPrivateFieldGet ( this , _YargsInstance _groups , "f" ) [ groupName ] . filter ( key => ! ( key in localLookup ) ) ;
if ( keys . length > 0 ) {
acc [ groupName ] = keys ;
}
return acc ;
} , { } ) ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _groups , { } , "f" ) ;
const arrayOptions = [
'array' ,
'boolean' ,
'string' ,
'skipValidation' ,
'count' ,
'normalize' ,
'number' ,
'hiddenOptions' ,
] ;
const objectOptions = [
'narg' ,
'key' ,
'alias' ,
'default' ,
'defaultDescription' ,
'config' ,
'choices' ,
'demandedOptions' ,
'demandedCommands' ,
'deprecatedOptions' ,
] ;
arrayOptions . forEach ( k => {
tmpOptions [ k ] = ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ k ] || [ ] ) . filter ( ( k ) => ! localLookup [ k ] ) ;
} ) ;
objectOptions . forEach ( ( k ) => {
tmpOptions [ k ] = objFilter ( _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) [ k ] , k => ! localLookup [ k ] ) ;
} ) ;
tmpOptions . envPrefix = _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . envPrefix ;
_ _classPrivateFieldSet ( this , _YargsInstance _options , tmpOptions , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _usage , _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" )
? _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . reset ( localLookup )
: Usage ( this , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _validation , _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" )
? _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . reset ( localLookup )
: Validation ( this , _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _command , _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" )
? _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . reset ( )
: Command ( _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) , "f" ) ;
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) )
_ _classPrivateFieldSet ( this , _YargsInstance _completion , Completion ( this , _ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) , _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) ) , "f" ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . reset ( ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _completionCommand , null , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _output , '' , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _exitError , null , "f" ) ;
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , false , "f" ) ;
this . parsed = false ;
return this ;
}
[ kRebase ] ( base , dir ) {
return _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . path . relative ( base , dir ) ;
}
[ kRunYargsParserAndExecuteCommands ] ( args , shortCircuit , calledFromCommand , commandIndex = 0 , helpOnly = false ) {
let skipValidation = ! ! calledFromCommand || helpOnly ;
args = args || _ _classPrivateFieldGet ( this , _YargsInstance _processArgs , "f" ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . _ _ = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . y18n . _ _ ;
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configuration = this [ kGetParserConfiguration ] ( ) ;
const populateDoubleDash = ! ! _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configuration [ 'populate--' ] ;
const config = Object . assign ( { } , _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . configuration , {
'populate--' : true ,
} ) ;
const parsed = _ _classPrivateFieldGet ( this , _YargsInstance _shim , "f" ) . Parser . detailed ( args , Object . assign ( { } , _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) , {
configuration : { 'parse-positional-numbers' : false , ... config } ,
} ) ) ;
const argv = Object . assign ( parsed . argv , _ _classPrivateFieldGet ( this , _YargsInstance _parseContext , "f" ) ) ;
let argvPromise = undefined ;
const aliases = parsed . aliases ;
let helpOptSet = false ;
let versionOptSet = false ;
Object . keys ( argv ) . forEach ( key => {
if ( key === _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) && argv [ key ] ) {
helpOptSet = true ;
}
else if ( key === _ _classPrivateFieldGet ( this , _YargsInstance _versionOpt , "f" ) && argv [ key ] ) {
versionOptSet = true ;
}
} ) ;
argv . $0 = this . $0 ;
this . parsed = parsed ;
if ( commandIndex === 0 ) {
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . clearCachedHelpMessage ( ) ;
}
try {
this [ kGuessLocale ] ( ) ;
if ( shortCircuit ) {
return this [ kPostProcess ] ( argv , populateDoubleDash , ! ! calledFromCommand , false ) ;
}
if ( _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ) {
const helpCmds = [ _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ]
. concat ( aliases [ _ _classPrivateFieldGet ( this , _YargsInstance _helpOpt , "f" ) ] || [ ] )
. filter ( k => k . length > 1 ) ;
if ( helpCmds . includes ( '' + argv . _ [ argv . _ . length - 1 ] ) ) {
argv . _ . pop ( ) ;
helpOptSet = true ;
}
}
2023-04-21 16:12:50 +00:00
_ _classPrivateFieldSet ( this , _YargsInstance _isGlobalContext , false , "f" ) ;
2023-04-21 14:57:54 +00:00
const handlerKeys = _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . getCommands ( ) ;
const requestCompletions = _ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . completionKey in argv ;
const skipRecommendation = helpOptSet || requestCompletions || helpOnly ;
if ( argv . _ . length ) {
if ( handlerKeys . length ) {
let firstUnknownCommand ;
for ( let i = commandIndex || 0 , cmd ; argv . _ [ i ] !== undefined ; i ++ ) {
cmd = String ( argv . _ [ i ] ) ;
if ( handlerKeys . includes ( cmd ) && cmd !== _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) ) {
const innerArgv = _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . runCommand ( cmd , this , parsed , i + 1 , helpOnly , helpOptSet || versionOptSet || helpOnly ) ;
return this [ kPostProcess ] ( innerArgv , populateDoubleDash , ! ! calledFromCommand , false ) ;
}
else if ( ! firstUnknownCommand &&
cmd !== _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) ) {
firstUnknownCommand = cmd ;
break ;
}
}
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . hasDefaultCommand ( ) &&
_ _classPrivateFieldGet ( this , _YargsInstance _recommendCommands , "f" ) &&
firstUnknownCommand &&
! skipRecommendation ) {
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . recommendCommands ( firstUnknownCommand , handlerKeys ) ;
}
}
if ( _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) &&
argv . _ . includes ( _ _classPrivateFieldGet ( this , _YargsInstance _completionCommand , "f" ) ) &&
! requestCompletions ) {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) )
setBlocking ( true ) ;
this . showCompletionScript ( ) ;
this . exit ( 0 ) ;
}
}
if ( _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . hasDefaultCommand ( ) && ! skipRecommendation ) {
const innerArgv = _ _classPrivateFieldGet ( this , _YargsInstance _command , "f" ) . runCommand ( null , this , parsed , 0 , helpOnly , helpOptSet || versionOptSet || helpOnly ) ;
return this [ kPostProcess ] ( innerArgv , populateDoubleDash , ! ! calledFromCommand , false ) ;
}
if ( requestCompletions ) {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) )
setBlocking ( true ) ;
args = [ ] . concat ( args ) ;
const completionArgs = args . slice ( args . indexOf ( ` -- ${ _ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . completionKey } ` ) + 1 ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _completion , "f" ) . getCompletion ( completionArgs , ( err , completions ) => {
if ( err )
throw new YError ( err . message ) ;
( completions || [ ] ) . forEach ( completion => {
_ _classPrivateFieldGet ( this , _YargsInstance _logger , "f" ) . log ( completion ) ;
} ) ;
this . exit ( 0 ) ;
} ) ;
return this [ kPostProcess ] ( argv , ! populateDoubleDash , ! ! calledFromCommand , false ) ;
}
if ( ! _ _classPrivateFieldGet ( this , _YargsInstance _hasOutput , "f" ) ) {
if ( helpOptSet ) {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) )
setBlocking ( true ) ;
skipValidation = true ;
this . showHelp ( 'log' ) ;
this . exit ( 0 ) ;
}
else if ( versionOptSet ) {
if ( _ _classPrivateFieldGet ( this , _YargsInstance _exitProcess , "f" ) )
setBlocking ( true ) ;
skipValidation = true ;
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . showVersion ( 'log' ) ;
this . exit ( 0 ) ;
}
}
if ( ! skipValidation && _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . skipValidation . length > 0 ) {
skipValidation = Object . keys ( argv ) . some ( key => _ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . skipValidation . indexOf ( key ) >= 0 && argv [ key ] === true ) ;
}
if ( ! skipValidation ) {
if ( parsed . error )
throw new YError ( parsed . error . message ) ;
if ( ! requestCompletions ) {
const validation = this [ kRunValidation ] ( aliases , { } , parsed . error ) ;
if ( ! calledFromCommand ) {
argvPromise = applyMiddleware ( argv , this , _ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . getMiddleware ( ) , true ) ;
}
argvPromise = this [ kValidateAsync ] ( validation , argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv ) ;
if ( isPromise ( argvPromise ) && ! calledFromCommand ) {
argvPromise = argvPromise . then ( ( ) => {
return applyMiddleware ( argv , this , _ _classPrivateFieldGet ( this , _YargsInstance _globalMiddleware , "f" ) . getMiddleware ( ) , false ) ;
} ) ;
}
}
}
}
catch ( err ) {
if ( err instanceof YError )
_ _classPrivateFieldGet ( this , _YargsInstance _usage , "f" ) . fail ( err . message , err ) ;
else
throw err ;
}
return this [ kPostProcess ] ( argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv , populateDoubleDash , ! ! calledFromCommand , true ) ;
}
[ kRunValidation ] ( aliases , positionalMap , parseErrors , isDefaultCommand ) {
const demandedOptions = { ... this . getDemandedOptions ( ) } ;
return ( argv ) => {
if ( parseErrors )
throw new YError ( parseErrors . message ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . nonOptionCount ( argv ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . requiredArguments ( argv , demandedOptions ) ;
let failedStrictCommands = false ;
if ( _ _classPrivateFieldGet ( this , _YargsInstance _strictCommands , "f" ) ) {
failedStrictCommands = _ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . unknownCommands ( argv ) ;
}
if ( _ _classPrivateFieldGet ( this , _YargsInstance _strict , "f" ) && ! failedStrictCommands ) {
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . unknownArguments ( argv , aliases , positionalMap , ! ! isDefaultCommand ) ;
}
else if ( _ _classPrivateFieldGet ( this , _YargsInstance _strictOptions , "f" ) ) {
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . unknownArguments ( argv , aliases , { } , false , false ) ;
}
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . limitedChoices ( argv ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . implications ( argv ) ;
_ _classPrivateFieldGet ( this , _YargsInstance _validation , "f" ) . conflicting ( argv ) ;
} ;
}
[ kSetHasOutput ] ( ) {
_ _classPrivateFieldSet ( this , _YargsInstance _hasOutput , true , "f" ) ;
}
[ kTrackManuallySetKeys ] ( keys ) {
if ( typeof keys === 'string' ) {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . key [ keys ] = true ;
}
else {
for ( const k of keys ) {
_ _classPrivateFieldGet ( this , _YargsInstance _options , "f" ) . key [ k ] = true ;
}
}
}
}
export function isYargsInstance ( y ) {
return ! ! y && typeof y . getInternalMethods === 'function' ;
}