Skip to content

Commit

Permalink
fix: pass flag to default function
Browse files Browse the repository at this point in the history
@W-11868418@
  • Loading branch information
peternhale committed Apr 19, 2023
1 parent 9f4fd95 commit 7e74882
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ const defaultFlagToCached = async (flag: CompletableOptionFlag<any>, isWritingMa
// if not specified, try the default function
if (typeof flag.default === 'function') {
try {
return await flag.default({options: {}, flags: {}}, isWritingManifest)
return await flag.default({options: flag, flags: {}}, isWritingManifest)
} catch {}
} else {
return flag.default
Expand All @@ -846,7 +846,7 @@ const defaultArgToCached = async (arg: Arg<any>, isWritingManifest = false): Pro
// if not specified, try the default function
if (typeof arg.default === 'function') {
try {
return await arg.default({options: arg, flags: {}}, isWritingManifest)
return await arg.default(isWritingManifest)
} catch {}
} else {
return arg.default
Expand Down
5 changes: 1 addition & 4 deletions src/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']

if (!(k in flags) && flag.default !== undefined) {
this.metaData.flags[k] = {...this.metaData.flags[k], setFromDefault: true}
const defaultValue = (typeof flag.default === 'function' ? await flag.default({
options: flag,
flags, ...this.context,
}) : flag.default)
const defaultValue = (typeof flag.default === 'function' ? await flag.default({options: flag, flags}) : flag.default)
flags[k] = defaultValue
}
}
Expand Down
Loading

0 comments on commit 7e74882

Please sign in to comment.