diff --git a/src/commands/api-key/list.ts b/src/commands/api-key/list.ts index 8f802ff7f3..d7b8fa33e6 100644 --- a/src/commands/api-key/list.ts +++ b/src/commands/api-key/list.ts @@ -37,7 +37,7 @@ export default class APIKeyListCmd extends Command { char: 'u', description: 'show API keys for your user', }), - fleet: cf.fleet, + fleet: cf.fleet(), }; public static authenticated = true; diff --git a/src/commands/build/index.ts b/src/commands/build/index.ts index 66a8944fff..da2e0b6aee 100644 --- a/src/commands/build/index.ts +++ b/src/commands/build/index.ts @@ -86,12 +86,15 @@ ${dockerignoreHelp} arch: Flags.string({ description: 'the architecture to build for', char: 'A', + exclusive: ['fleet'], + dependsOn: ['deviceType'], }), deviceType: Flags.string({ description: 'the type of device this build is for', char: 'd', + exclusive: ['fleet'], }), - fleet: cf.fleet, + fleet: cf.fleet({ exclusive: ['deviceType', 'arch'] }), ...composeCliFlags, ...dockerCliFlags, }; @@ -148,17 +151,6 @@ ${dockerignoreHelp} } protected async validateOptions(opts: FlagsDef, sdk: BalenaSDK) { - // Validate option combinations - if ( - (opts.fleet == null && (opts.arch == null || opts.deviceType == null)) || - (opts.fleet != null && (opts.arch != null || opts.deviceType != null)) - ) { - const { ExpectedError } = await import('../../errors'); - throw new ExpectedError( - 'You must specify either a fleet (-f), or the device type (-d) and optionally the architecture (-A)', - ); - } - // Validate project directory const { validateProjectDirectory } = await import('../../utils/compose_ts'); const { dockerfilePath, registrySecrets } = await validateProjectDirectory( diff --git a/src/commands/config/generate.ts b/src/commands/config/generate.ts index 4376b53f24..a2002853d1 100644 --- a/src/commands/config/generate.ts +++ b/src/commands/config/generate.ts @@ -64,7 +64,7 @@ export default class ConfigGenerateCmd extends Command { description: 'a balenaOS version', required: true, }), - fleet: { ...cf.fleet, exclusive: ['device'] }, + fleet: { ...cf.fleet(), exclusive: ['device'] }, dev: cf.dev, secureBoot: cf.secureBoot, device: { diff --git a/src/commands/device/init.ts b/src/commands/device/init.ts index 81b907f4d7..077effffb6 100644 --- a/src/commands/device/init.ts +++ b/src/commands/device/init.ts @@ -73,7 +73,7 @@ export default class DeviceInitCmd extends Command { ]; public static flags = { - fleet: cf.fleet, + fleet: cf.fleet(), yes: cf.yes, advanced: Flags.boolean({ char: 'v', diff --git a/src/commands/device/list.ts b/src/commands/device/list.ts index 7eea1c1ed4..58a7bad758 100644 --- a/src/commands/device/list.ts +++ b/src/commands/device/list.ts @@ -57,7 +57,7 @@ export default class DeviceListCmd extends Command { ]; public static flags = { - fleet: cf.fleet, + fleet: cf.fleet(), json: cf.json, }; diff --git a/src/commands/device/move.ts b/src/commands/device/move.ts index 0300fe7045..17be42d0e0 100644 --- a/src/commands/device/move.ts +++ b/src/commands/device/move.ts @@ -54,7 +54,7 @@ export default class DeviceMoveCmd extends Command { }; public static flags = { - fleet: cf.fleet, + fleet: cf.fleet(), }; public static authenticated = true; diff --git a/src/commands/env/list.ts b/src/commands/env/list.ts index 42c122d564..0c3112c17d 100644 --- a/src/commands/env/list.ts +++ b/src/commands/env/list.ts @@ -97,7 +97,7 @@ export default class EnvListCmd extends Command { ]; public static flags = { - fleet: { ...cf.fleet, exclusive: ['device'] }, + fleet: { ...cf.fleet(), exclusive: ['device'] }, config: Flags.boolean({ default: false, char: 'c', diff --git a/src/commands/env/set.ts b/src/commands/env/set.ts index 6ad8d6a044..1c2a6a34ad 100644 --- a/src/commands/env/set.ts +++ b/src/commands/env/set.ts @@ -95,7 +95,7 @@ export default class EnvSetCmd extends Command { public static strict = false; public static flags = { - fleet: { ...cf.fleet, exclusive: ['device'] }, + fleet: { ...cf.fleet(), exclusive: ['device'] }, device: { ...cf.device, exclusive: ['fleet'] }, quiet: cf.quiet, service: cf.service, diff --git a/src/commands/join/index.ts b/src/commands/join/index.ts index 5427cb5762..c3d7d28675 100644 --- a/src/commands/join/index.ts +++ b/src/commands/join/index.ts @@ -60,7 +60,7 @@ export default class JoinCmd extends Command { }; public static flags = { - fleet: cf.fleet, + fleet: cf.fleet(), pollInterval: Flags.integer({ description: 'the interval in minutes to check for updates', char: 'i', diff --git a/src/commands/os/configure.ts b/src/commands/os/configure.ts index da497c361b..c051b040cf 100644 --- a/src/commands/os/configure.ts +++ b/src/commands/os/configure.ts @@ -97,7 +97,7 @@ export default class OsConfigureCmd extends Command { description: 'ask advanced configuration questions (when in interactive mode)', }), - fleet: { ...cf.fleet, exclusive: ['device'] }, + fleet: { ...cf.fleet(), exclusive: ['device'] }, config: Flags.string({ description: 'path to a pre-generated config.json file to be injected in the OS image', diff --git a/src/commands/preload/index.ts b/src/commands/preload/index.ts index 0cdfc63b72..fe691c393a 100644 --- a/src/commands/preload/index.ts +++ b/src/commands/preload/index.ts @@ -79,7 +79,7 @@ export default class PreloadCmd extends Command { }; public static flags = { - fleet: cf.fleet, + fleet: cf.fleet(), commit: Flags.string({ description: `\ The commit hash of the release to preload. Use "current" to specify the current diff --git a/src/commands/support/index.ts b/src/commands/support/index.ts index 6c100a2472..b5b40dc2ef 100644 --- a/src/commands/support/index.ts +++ b/src/commands/support/index.ts @@ -57,7 +57,7 @@ export default class SupportCmd extends Command { char: 'd', }), fleet: { - ...cf.fleet, + ...cf.fleet(), description: 'comma-separated list (no spaces) of fleet names or slugs (preferred)', }, diff --git a/src/commands/tag/list.ts b/src/commands/tag/list.ts index 40ca940ef4..0cc847b2f8 100644 --- a/src/commands/tag/list.ts +++ b/src/commands/tag/list.ts @@ -43,7 +43,7 @@ export default class TagListCmd extends Command { public static flags = { fleet: { - ...cf.fleet, + ...cf.fleet(), exclusive: ['device', 'release'], }, device: { diff --git a/src/commands/tag/rm.ts b/src/commands/tag/rm.ts index 622b6f35a3..af2e863b6d 100644 --- a/src/commands/tag/rm.ts +++ b/src/commands/tag/rm.ts @@ -46,7 +46,7 @@ export default class TagRmCmd extends Command { public static flags = { fleet: { - ...cf.fleet, + ...cf.fleet(), exclusive: ['device', 'release'], }, device: { diff --git a/src/commands/tag/set.ts b/src/commands/tag/set.ts index adb79a1eff..9793667b91 100644 --- a/src/commands/tag/set.ts +++ b/src/commands/tag/set.ts @@ -60,7 +60,7 @@ export default class TagSetCmd extends Command { public static flags = { fleet: { - ...cf.fleet, + ...cf.fleet(), exclusive: ['device', 'release'], }, device: { diff --git a/src/utils/common-flags.ts b/src/utils/common-flags.ts index ba84db1390..bdfc6a9979 100644 --- a/src/utils/common-flags.ts +++ b/src/utils/common-flags.ts @@ -18,12 +18,15 @@ import { Flags } from '@oclif/core'; import { stripIndent } from './lazy'; import { lowercaseIfSlug } from './normalization'; +import type { FlagProps } from '@oclif/core/lib/interfaces/parser'; -export const fleet = Flags.string({ - char: 'f', - description: 'fleet name or slug (preferred)', - parse: lowercaseIfSlug, -}); +export const fleet = (extraOpts?: Partial) => + Flags.string({ + char: 'f', + description: 'fleet name or slug (preferred)', + parse: lowercaseIfSlug, + ...extraOpts, + }); export const device = Flags.string({ char: 'd',