mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-29 15:44:26 +00:00
Merge pull request #2028 from balena-io/join-poll
Add ability to specify poll interval in join command
This commit is contained in:
commit
cd20f1765e
@ -2805,6 +2805,10 @@ the IP or hostname of device
|
||||
|
||||
application name
|
||||
|
||||
#### -i, --pollInterval POLLINTERVAL
|
||||
|
||||
the interval in minutes to check for updates
|
||||
|
||||
## leave [deviceIpOrHostname]
|
||||
|
||||
Remove a local device from its balena application, causing the device to
|
||||
|
@ -40,7 +40,16 @@ export default class ScandevicesCmd extends Command {
|
||||
|
||||
public async run() {
|
||||
const { forms } = await import('balena-sync');
|
||||
const hostnameOrIp = await forms.selectLocalBalenaOsDevice();
|
||||
return console.error(`==> Selected device: ${hostnameOrIp}`);
|
||||
try {
|
||||
const hostnameOrIp = await forms.selectLocalBalenaOsDevice();
|
||||
return console.error(`==> Selected device: ${hostnameOrIp}`);
|
||||
} catch (e) {
|
||||
if (e.message.toLowerCase().includes('could not find any')) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
throw new ExpectedError(e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,11 @@ import { flags } from '@oclif/command';
|
||||
import Command from '../command';
|
||||
import * as cf from '../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../utils/lazy';
|
||||
import { parseAsLocalHostnameOrIp } from '../utils/validation';
|
||||
|
||||
interface FlagsDef {
|
||||
application?: string;
|
||||
pollInterval?: number;
|
||||
help?: void;
|
||||
}
|
||||
|
||||
@ -61,6 +63,7 @@ export default class JoinCmd extends Command {
|
||||
{
|
||||
name: 'deviceIpOrHostname',
|
||||
description: 'the IP or hostname of device',
|
||||
parse: parseAsLocalHostnameOrIp,
|
||||
},
|
||||
];
|
||||
|
||||
@ -72,6 +75,10 @@ export default class JoinCmd extends Command {
|
||||
description: 'the name of the application the device should join',
|
||||
...cf.application,
|
||||
},
|
||||
pollInterval: flags.integer({
|
||||
description: 'the interval in minutes to check for updates',
|
||||
char: 'i',
|
||||
}),
|
||||
help: cf.help,
|
||||
};
|
||||
|
||||
@ -83,15 +90,15 @@ export default class JoinCmd extends Command {
|
||||
JoinCmd,
|
||||
);
|
||||
|
||||
const Logger = await import('../utils/logger');
|
||||
const promote = await import('../utils/promote');
|
||||
const sdk = getBalenaSdk();
|
||||
const logger = Logger.getLogger();
|
||||
const logger = await Command.getLogger();
|
||||
return promote.join(
|
||||
logger,
|
||||
sdk,
|
||||
params.deviceIpOrHostname,
|
||||
options.application,
|
||||
options.pollInterval,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import { flags } from '@oclif/command';
|
||||
import Command from '../command';
|
||||
import * as cf from '../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../utils/lazy';
|
||||
import { parseAsLocalHostnameOrIp } from '../utils/validation';
|
||||
|
||||
interface FlagsDef {
|
||||
help?: void;
|
||||
@ -54,10 +55,10 @@ export default class LeaveCmd extends Command {
|
||||
{
|
||||
name: 'deviceIpOrHostname',
|
||||
description: 'the device IP or hostname',
|
||||
parse: parseAsLocalHostnameOrIp,
|
||||
},
|
||||
];
|
||||
|
||||
// Hardcoded to preserve camelcase
|
||||
public static usage = 'leave [deviceIpOrHostname]';
|
||||
|
||||
public static flags: flags.Input<FlagsDef> = {
|
||||
@ -70,10 +71,9 @@ export default class LeaveCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = this.parse<FlagsDef, ArgsDef>(LeaveCmd);
|
||||
|
||||
const Logger = await import('../utils/logger');
|
||||
const promote = await import('../utils/promote');
|
||||
const sdk = getBalenaSdk();
|
||||
const logger = Logger.getLogger();
|
||||
const logger = await Command.getLogger();
|
||||
return promote.leave(logger, sdk, params.deviceIpOrHostname);
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,11 @@ export async function generateBaseConfig(
|
||||
|
||||
export async function generateApplicationConfig(
|
||||
application: BalenaSdk.Application,
|
||||
options: { version: string; deviceType?: string },
|
||||
options: {
|
||||
version: string;
|
||||
deviceType?: string;
|
||||
appUpdatePollInterval?: number;
|
||||
},
|
||||
) {
|
||||
const config = await generateBaseConfig(application, options);
|
||||
|
||||
|
@ -28,6 +28,7 @@ export async function join(
|
||||
sdk: BalenaSdk.BalenaSDK,
|
||||
deviceHostnameOrIp?: string,
|
||||
appName?: string,
|
||||
appUpdatePollInterval?: number,
|
||||
): Promise<void> {
|
||||
logger.logDebug('Determining device...');
|
||||
const deviceIp = await getOrSelectLocalDevice(deviceHostnameOrIp);
|
||||
@ -55,6 +56,7 @@ export async function join(
|
||||
logger.logDebug('Generating application config...');
|
||||
const config = await generateApplicationConfig(sdk, app, {
|
||||
version: deviceOsVersion,
|
||||
appUpdatePollInterval,
|
||||
});
|
||||
logger.logDebug(`Using config: ${JSON.stringify(config, null, 2)}`);
|
||||
|
||||
@ -387,7 +389,10 @@ async function createApplication(
|
||||
async function generateApplicationConfig(
|
||||
sdk: BalenaSdk.BalenaSDK,
|
||||
app: ApplicationWithDeviceType,
|
||||
options: { version: string },
|
||||
options: {
|
||||
version: string;
|
||||
appUpdatePollInterval?: number;
|
||||
},
|
||||
) {
|
||||
const { generateApplicationConfig: configGen } = await import('./config');
|
||||
|
||||
@ -397,8 +402,13 @@ async function generateApplicationConfig(
|
||||
const opts =
|
||||
manifest.options &&
|
||||
manifest.options.filter((opt) => opt.name !== 'network');
|
||||
|
||||
const override = {
|
||||
appUpdatePollInterval: options.appUpdatePollInterval,
|
||||
};
|
||||
|
||||
const values = {
|
||||
...(opts ? await getCliForm().run(opts) : {}),
|
||||
...(opts ? await getCliForm().run(opts, { override }) : {}),
|
||||
...options,
|
||||
};
|
||||
|
||||
|
@ -57,6 +57,10 @@ export function validateDotLocalUrl(input: string): boolean {
|
||||
return DOTLOCAL_REGEX.test(input);
|
||||
}
|
||||
|
||||
export function validateLocalHostnameOrIp(input: string): boolean {
|
||||
return validateIPAddress(input) || validateDotLocalUrl(input);
|
||||
}
|
||||
|
||||
export function validateLongUuid(input: string): boolean {
|
||||
if (input.length !== 32 && input.length !== 62) {
|
||||
return false;
|
||||
@ -100,3 +104,16 @@ export function tryAsInteger(input: string): number | string {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
export function parseAsLocalHostnameOrIp(input: string, paramName?: string) {
|
||||
if (input && !validateLocalHostnameOrIp(input)) {
|
||||
const message =
|
||||
paramName == null
|
||||
? 'The parameter must be a local hostname or IP address.'
|
||||
: `The parameter '${paramName}' must be a local hostname or IP address.`;
|
||||
|
||||
throw new ExpectedError(message);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user