Skip to content

Commit

Permalink
Support functions in default (react-native-community#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou authored Apr 18, 2019
1 parent 98d88d5 commit c28fb93
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const addCommand = (command: CommandT, ctx: ConfigT) => {
opt.command,
opt.description,
opt.parse || defaultOptParser,
opt.default,
typeof opt.default === 'function' ? opt.default(ctx) : opt.default,
),
);
};
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/tools/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const command = t.object({
command: t.string().required(),
description: t.string(),
parse: t.func(),
default: t.alternatives().try([t.bool(), t.number(), t.string()]),
default: t
.alternatives()
.try([t.bool(), t.number(), t.string(), t.func()]),
}),
),
examples: t.array().items(
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-android/src/commands/runAndroid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export default {
command: '--terminal [string]',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: getDefaultUserTerminal(),
default: getDefaultUserTerminal,
},
],
};
2 changes: 1 addition & 1 deletion packages/platform-ios/src/commands/runIOS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export default {
command: '--terminal [string]',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: getDefaultUserTerminal(),
default: getDefaultUserTerminal,
},
],
};
6 changes: 5 additions & 1 deletion types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export type CommandT = {
command: string,
description?: string,
parse?: (val: string) => any,
default?: string | boolean | number,
default?:
| string
| boolean
| number
| ((ctx: ConfigT) => string | boolean | number),
}>,
examples?: Array<{
desc: string,
Expand Down

0 comments on commit c28fb93

Please sign in to comment.