Fix 'balena app' (rm, restart, info) with numeric app IDs

Resolves: #1815
Change-type: patch
This commit is contained in:
Paulo Castro 2020-05-11 16:40:50 +01:00
parent 9756efb539
commit 8d60cd1f92
5 changed files with 23 additions and 9 deletions

View File

@ -319,7 +319,7 @@ Examples:
#### NAME
application name
application name or numeric ID
### Options
@ -366,7 +366,7 @@ Examples:
#### NAME
application name
application name or numeric ID
### Options
@ -386,7 +386,7 @@ Examples:
#### NAME
application name
application name or numeric ID
### Options

View File

@ -20,6 +20,7 @@ import { stripIndent } from 'common-tags';
import Command from '../../command';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk, getVisuals } from '../../utils/lazy';
import { tryAsInteger } from '../../utils/validation';
interface FlagsDef {
help: void;
@ -40,7 +41,7 @@ export default class AppCmd extends Command {
public static args = [
{
name: 'name',
description: 'application name',
description: 'application name or numeric ID',
required: true,
},
];
@ -58,7 +59,7 @@ export default class AppCmd extends Command {
const { args: params } = this.parse<FlagsDef, ArgsDef>(AppCmd);
const application = await getBalenaSdk().models.application.get(
params.name,
tryAsInteger(params.name),
);
console.log(

View File

@ -20,6 +20,7 @@ import { stripIndent } from 'common-tags';
import Command from '../../command';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk } from '../../utils/lazy';
import { tryAsInteger } from '../../utils/validation';
interface FlagsDef {
help: void;
@ -40,7 +41,7 @@ export default class AppRestartCmd extends Command {
public static args = [
{
name: 'name',
description: 'application name',
description: 'application name or numeric ID',
required: true,
},
];
@ -56,6 +57,6 @@ export default class AppRestartCmd extends Command {
public async run() {
const { args: params } = this.parse<FlagsDef, ArgsDef>(AppRestartCmd);
await getBalenaSdk().models.application.restart(params.name);
await getBalenaSdk().models.application.restart(tryAsInteger(params.name));
}
}

View File

@ -20,6 +20,7 @@ import { stripIndent } from 'common-tags';
import Command from '../../command';
import * as cf from '../../utils/common-flags';
import { getBalenaSdk } from '../../utils/lazy';
import { tryAsInteger } from '../../utils/validation';
interface FlagsDef {
yes: boolean;
@ -46,7 +47,7 @@ export default class AppRmCmd extends Command {
public static args = [
{
name: 'name',
description: 'application name',
description: 'application name or numeric ID',
required: true,
},
];
@ -74,6 +75,6 @@ export default class AppRmCmd extends Command {
);
// Remove
await getBalenaSdk().models.application.remove(params.name);
await getBalenaSdk().models.application.remove(tryAsInteger(params.name));
}
}

View File

@ -88,3 +88,14 @@ export function parseAsInteger(input: string, paramName?: string) {
return Number(input);
}
export function tryAsInteger(
input: string,
paramName?: string,
): number | string {
try {
return parseAsInteger(input, paramName);
} catch {
return input;
}
}