mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Add initial typings for resin-cli-form
Change-type: patch Signed-off-by: Thodoris Greasidis <thodoris@balena.io>
This commit is contained in:
parent
2b264df41b
commit
051268168a
@ -141,7 +141,7 @@ export function confirm(
|
||||
return true;
|
||||
}
|
||||
|
||||
return getForm().ask({
|
||||
return getForm().ask<boolean>({
|
||||
message,
|
||||
type: 'confirm',
|
||||
default: false,
|
||||
@ -185,7 +185,8 @@ export function selectOrCreateApplication() {
|
||||
.hasAny()
|
||||
.then(hasAnyApplications => {
|
||||
if (!hasAnyApplications) {
|
||||
return;
|
||||
// Just to make TS happy
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return balena.models.application.getAll().then(applications => {
|
||||
@ -286,7 +287,7 @@ export function selectFromList<T>(
|
||||
message: string,
|
||||
choices: Array<T & { name: string }>,
|
||||
): Bluebird<T> {
|
||||
return getForm().ask({
|
||||
return getForm().ask<T>({
|
||||
message,
|
||||
type: 'list',
|
||||
choices: _.map(choices, s => ({
|
||||
|
@ -376,7 +376,7 @@ async function generateApplicationConfig(
|
||||
const opts =
|
||||
manifest.options && manifest.options.filter(opt => opt.name !== 'network');
|
||||
const values = {
|
||||
...(await form.run(opts)),
|
||||
...(opts ? await form.run(opts) : {}),
|
||||
...options,
|
||||
};
|
||||
|
||||
|
39
typings/resin-cli-form/index.d.ts
vendored
39
typings/resin-cli-form/index.d.ts
vendored
@ -15,4 +15,41 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
declare module 'resin-cli-form';
|
||||
declare module 'resin-cli-form' {
|
||||
import Bluebird = require('bluebird');
|
||||
|
||||
type TypeOrPromiseLike<T> = T | PromiseLike<T>;
|
||||
|
||||
type Validate = (
|
||||
input: any,
|
||||
) => TypeOrPromiseLike<boolean | string | undefined>;
|
||||
|
||||
interface AskOptions {
|
||||
message: string;
|
||||
type?: string;
|
||||
name?: string;
|
||||
default?: T;
|
||||
choices?: Array<{
|
||||
name: string;
|
||||
value: T;
|
||||
}>;
|
||||
validate?: Validate;
|
||||
}
|
||||
|
||||
interface RunQuestion {
|
||||
message: string;
|
||||
name: string;
|
||||
type?: string;
|
||||
validate?: Validate;
|
||||
}
|
||||
|
||||
const form: {
|
||||
ask: <T = string>(options: AskOptions) => Bluebird<T>;
|
||||
run: <T = any>(
|
||||
questions: RunQuestion[],
|
||||
extraOptions?: { override: object },
|
||||
) => Bluebird<T>;
|
||||
};
|
||||
|
||||
export = form;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user