mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-20 19:49:18 +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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getForm().ask({
|
return getForm().ask<boolean>({
|
||||||
message,
|
message,
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
default: false,
|
default: false,
|
||||||
@ -185,7 +185,8 @@ export function selectOrCreateApplication() {
|
|||||||
.hasAny()
|
.hasAny()
|
||||||
.then(hasAnyApplications => {
|
.then(hasAnyApplications => {
|
||||||
if (!hasAnyApplications) {
|
if (!hasAnyApplications) {
|
||||||
return;
|
// Just to make TS happy
|
||||||
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return balena.models.application.getAll().then(applications => {
|
return balena.models.application.getAll().then(applications => {
|
||||||
@ -286,7 +287,7 @@ export function selectFromList<T>(
|
|||||||
message: string,
|
message: string,
|
||||||
choices: Array<T & { name: string }>,
|
choices: Array<T & { name: string }>,
|
||||||
): Bluebird<T> {
|
): Bluebird<T> {
|
||||||
return getForm().ask({
|
return getForm().ask<T>({
|
||||||
message,
|
message,
|
||||||
type: 'list',
|
type: 'list',
|
||||||
choices: _.map(choices, s => ({
|
choices: _.map(choices, s => ({
|
||||||
|
@ -376,7 +376,7 @@ async function generateApplicationConfig(
|
|||||||
const opts =
|
const opts =
|
||||||
manifest.options && manifest.options.filter(opt => opt.name !== 'network');
|
manifest.options && manifest.options.filter(opt => opt.name !== 'network');
|
||||||
const values = {
|
const values = {
|
||||||
...(await form.run(opts)),
|
...(opts ? await form.run(opts) : {}),
|
||||||
...options,
|
...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.
|
* 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