Skip to content

Commit

Permalink
Use a map instead of an object for storing flag references (internall…
Browse files Browse the repository at this point in the history
…y). This preserves the order of parsed arguments.
  • Loading branch information
coreybutler committed May 4, 2020
1 parent 495a3d4 commit c53544e
Show file tree
Hide file tree
Showing 4 changed files with 662 additions and 763 deletions.
11 changes: 3 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,12 @@ class Parser {
this.addFlag(value)
} else {
let priorFlag = this.getFlag(priorFlagValue)
if (!(priorFlag instanceof Flag)) {
console.log('HERE', priorFlag)
// priorFlag = priorFlag()
// console.log(priorFlag)
if (priorFlag.hasOwnProperty('aliasOf')) {
priorFlag = priorFlag.aliasOf
priorFlag.value = value
}

// console.log(flag, '<<<<', priorFlagValue ,'>>>>', priorFlag.name, priorFlag.recognized, '||'+priorFlag.inputName, ')))> ' + priorFlag.inputName.startsWith('-'))
if (!(priorFlag && (priorFlag.recognized || priorFlagValue.startsWith('-')))) {
// console.log('---Add', value)
this.addFlag(value)
}
}
Expand Down Expand Up @@ -242,7 +239,6 @@ class Parser {

if (flag.aliases.length > 0) {
flag.aliases.forEach(alias => {
// console.log(alias, this.#flags.get(clean).inputName)
this.#flags.set(this.#cleanFlag(alias), { aliasOf: this.#flags.get(clean) })
this.#aliases.add(this.#cleanFlag(alias))
})
Expand Down Expand Up @@ -384,7 +380,6 @@ class Parser {
this.#validFlags = this.valid

if (!this.#validFlags) {
console.log(Array.from(this.#violations).join('\n'))
if (globalThis.hasOwnProperty('process')) {
return globalThis.process.exit(1)
} else {
Expand Down
Loading

0 comments on commit c53544e

Please sign in to comment.