From 4b5def0a8a632a9aed827319c1dcbe6ccf8efc32 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Tue, 7 Nov 2023 05:22:09 +0530 Subject: [PATCH 01/10] Docs: Automatically generate Capitano configuration Change-type: patch Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/capitanodoc/capitanodoc.ts | 287 +++++++------------------- 1 file changed, 78 insertions(+), 209 deletions(-) diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 4a594517..2b263de8 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -17,6 +17,7 @@ import * as path from 'path'; import { MarkdownFileParser } from './utils'; +import { globSync } from 'glob'; /** * This is the skeleton of CLI documentation/reference web page at: @@ -27,224 +28,92 @@ import { MarkdownFileParser } from './utils'; * * IMPORTANT * - * Only build files listed here will be documented by Capitano - * Make sure to add your files in alphabetical order + * All commands need to be stored under a folder in lib/commands to maintain uniformity + * Generating docs will error out if directive not followed + * To add a custom heading for command docs, add the heading next to the folder name + * in the `commandHeadings` dictionary. + * + * This dictionary is the source of truth that creates the docs config which is used + * to generate the CLI documentation. By default, the folder name will be used. * * Resources with plural names needs to have 2 sections if they have commands like: * "fleet, fleets" or "device, devices" or "tag, tags" * */ -const capitanoDoc = { - title: 'balena CLI Documentation', - introduction: '', - categories: [ - { - title: 'API Key', - files: ['build/commands/api-keys/index.js'], - }, - { - title: 'API Keys', - files: [ - 'build/commands/api-key/generate.js', - 'build/commands/api-key/revoke.js', - ], - }, - { - title: 'App', - files: ['build/commands/app/create.js'], - }, - { - title: 'Authentication', - files: [ - 'build/commands/login.js', - 'build/commands/logout.js', - 'build/commands/whoami.js', - ], - }, - { - title: 'Block', - files: ['build/commands/app/create.js'], - }, - { - title: 'Config', - files: [ - 'build/commands/config/generate.js', - 'build/commands/config/inject.js', - 'build/commands/config/read.js', - 'build/commands/config/reconfigure.js', - 'build/commands/config/write.js', - ], - }, - { - title: 'Deploy', - files: ['build/commands/build.js', 'build/commands/deploy.js'], - }, - { - title: 'Device', - files: [ - 'build/commands/device/deactivate.js', - 'build/commands/device/identify.js', - 'build/commands/device/index.js', - 'build/commands/device/init.js', - 'build/commands/device/local-mode.js', - 'build/commands/device/move.js', - 'build/commands/device/os-update.js', - 'build/commands/device/pin.js', - 'build/commands/device/public-url.js', - 'build/commands/device/purge.js', - 'build/commands/device/reboot.js', - 'build/commands/device/register.js', - 'build/commands/device/rename.js', - 'build/commands/device/restart.js', - 'build/commands/device/rm.js', - 'build/commands/device/shutdown.js', - 'build/commands/device/track-fleet.js', - 'build/commands/device/start-service.js', - 'build/commands/device/stop-service.js', - ], - }, - { - title: 'Devices', - files: [ - 'build/commands/devices/index.js', - 'build/commands/devices/supported.js', - ], - }, - { - title: 'Environment Variable', - files: [ - 'build/commands/env/add.js', - 'build/commands/env/rename.js', - 'build/commands/env/rm.js', - ], - }, - { - title: 'Environment Variables', - files: ['build/commands/envs.js'], - }, - { - title: 'Fleet', - files: [ - 'build/commands/fleet/create.js', - 'build/commands/fleet/index.js', - 'build/commands/fleet/pin.js', - 'build/commands/fleet/purge.js', - 'build/commands/fleet/rename.js', - 'build/commands/fleet/restart.js', - 'build/commands/fleet/rm.js', - 'build/commands/fleet/track-latest.js', - ], - }, - { - title: 'Fleets', - files: ['build/commands/fleets.js'], - }, - { - title: 'Help and Version', - files: ['help', 'build/commands/version.js'], - }, - { - title: 'Local', - files: [ - 'build/commands/local/configure.js', - 'build/commands/local/flash.js', - ], - }, - { - title: 'Logs', - files: ['build/commands/logs.js'], - }, - { - title: 'Network', - files: [ - 'build/commands/scan.js', - 'build/commands/ssh.js', - 'build/commands/tunnel.js', - ], - }, - { - title: 'Notes', - files: ['build/commands/note.js'], - }, - { - title: 'Organizations', - files: ['build/commands/orgs.js'], - }, - { - title: 'OS', - files: [ - 'build/commands/os/build-config.js', - 'build/commands/os/configure.js', - 'build/commands/os/download.js', - 'build/commands/os/initialize.js', - 'build/commands/os/versions.js', - ], - }, - { - title: 'Preload', - files: ['build/commands/preload.js'], - }, - { - title: 'Push', - files: ['build/commands/push.js'], - }, - { - title: 'Platform', - files: ['build/commands/join.js', 'build/commands/leave.js'], - }, - { - title: 'Release', - files: [ - 'build/commands/release/finalize.js', - 'build/commands/release/index.js', - 'build/commands/release/invalidate.js', - 'build/commands/release/validate.js', - ], - }, - { - title: 'Releases', - files: ['build/commands/releases.js'], - }, - { - title: 'Settings', - files: ['build/commands/settings.js'], - }, - { - title: 'Support', - files: ['build/commands/support.js'], - }, - { - title: 'SSH Key', - files: [ - 'build/commands/key/add.js', - 'build/commands/key/index.js', - 'build/commands/key/rm.js', - ], - }, - { - title: 'SSH Keys', - files: ['build/commands/keys.js'], - }, - { - title: 'Tags', - files: ['build/commands/tag/rm.js', 'build/commands/tag/set.js'], - }, - { - title: 'Tags', - files: ['build/commands/tags.js'], - }, - { - title: 'Utilities', - files: ['build/commands/util/available-drives.js'], - }, - ], +interface Category { + title: string; + files: string[]; +} + +interface Documentation { + title: string; + introduction: string; + categories: Category[]; +} + +// Mapping folders names to custom headings in the docs +const commandHeadings: { [key: string]: string } = { + 'api-key': 'API Key', + 'api-keys': 'API Keys', + auth: 'Authentication', + env: 'Environment Variable', + envs: 'Environment Variables', + help: 'Help and Version', + key: 'SSH Key', + keys: 'SSH Keys', + orgs: 'Organizations', + os: 'OS', + util: 'Utilities', }; +// Fetch all available commands +const allCommandsPaths = globSync('build/commands/**/*.js', { + ignore: 'build/commands/internal/**', +}); + +// Docs config template +let capitanoDoc: Documentation = { + title: 'balena CLI Documentation', + introduction: '', + categories: [], +}; + +// Helper function to capitalize each word of directory name +function formatTitle(dir: string): string { + return dir.replace(/(^\w|\s\w)/g, (word) => word.toUpperCase()); +} + +// Create a map to track the categories for faster lookup +const categoriesMap: { [key: string]: Category } = {}; + +for (const commandPath of allCommandsPaths) { + const commandDir = path.basename(path.dirname(commandPath)); + const heading = commandHeadings[commandDir] || formatTitle(commandDir); + + if (!categoriesMap[heading]) { + categoriesMap[heading] = { title: heading, files: [] }; + capitanoDoc.categories.push(categoriesMap[heading]); + } + + categoriesMap[heading].files.push(commandPath); +} + +// Sort Category titles alhpabetically +capitanoDoc.categories = capitanoDoc.categories.sort((a, b) => +a.title.localeCompare(b.title), +); + +// Sort Category file paths alhpabetically +capitanoDoc.categories.forEach((category) => { + category.files.sort((a, b) => a.localeCompare(b)); +}); + +// TODO: Generate an error if commands are not in their folder + /** - * Modify and return the `capitanoDoc` object above in order to render the - * CLI documentation/reference web page at: - * https://www.balena.io/docs/reference/cli/ + * Modify and return the `capitanoDoc` object above in order to generate the + * CLI documentation at docs/balena-cli.md * * This function parses the README.md file to extract relevant sections * for the documentation web page. From dc40b0d9694ffd1c81d178689c1ec5b3fdabf33d Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 8 Nov 2023 01:30:28 +0530 Subject: [PATCH 02/10] Docs: Move CLI commands files to command directories Signed-off-by: Vipul Gupta (@vipulgupta2048) --- lib/commands/{ => auth}/login.ts | 0 lib/commands/{ => auth}/logout.ts | 0 lib/commands/{ => auth}/whoami.ts | 0 lib/commands/{ => deploy}/build.ts | 0 lib/commands/{ => deploy}/deploy.ts | 0 lib/commands/{ => envs}/envs.ts | 0 lib/commands/{ => fleets}/fleets.ts | 0 lib/commands/{ => help}/version.ts | 0 lib/commands/{ => keys}/keys.ts | 0 lib/commands/{ => logs}/logs.ts | 0 lib/commands/{ => network}/scan.ts | 0 lib/commands/{ => network}/ssh.ts | 0 lib/commands/{ => network}/tunnel.ts | 0 lib/commands/{ => notes}/note.ts | 0 lib/commands/{ => orgs}/orgs.ts | 0 lib/commands/{ => platform}/join.ts | 0 lib/commands/{ => platform}/leave.ts | 0 lib/commands/{ => preload}/preload.ts | 0 lib/commands/{ => push}/push.ts | 0 lib/commands/{ => releases}/releases.ts | 0 lib/commands/{ => settings}/settings.ts | 0 lib/commands/{ => support}/support.ts | 0 lib/commands/{ => tags}/tags.ts | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename lib/commands/{ => auth}/login.ts (100%) rename lib/commands/{ => auth}/logout.ts (100%) rename lib/commands/{ => auth}/whoami.ts (100%) rename lib/commands/{ => deploy}/build.ts (100%) rename lib/commands/{ => deploy}/deploy.ts (100%) rename lib/commands/{ => envs}/envs.ts (100%) rename lib/commands/{ => fleets}/fleets.ts (100%) rename lib/commands/{ => help}/version.ts (100%) rename lib/commands/{ => keys}/keys.ts (100%) rename lib/commands/{ => logs}/logs.ts (100%) rename lib/commands/{ => network}/scan.ts (100%) rename lib/commands/{ => network}/ssh.ts (100%) rename lib/commands/{ => network}/tunnel.ts (100%) rename lib/commands/{ => notes}/note.ts (100%) rename lib/commands/{ => orgs}/orgs.ts (100%) rename lib/commands/{ => platform}/join.ts (100%) rename lib/commands/{ => platform}/leave.ts (100%) rename lib/commands/{ => preload}/preload.ts (100%) rename lib/commands/{ => push}/push.ts (100%) rename lib/commands/{ => releases}/releases.ts (100%) rename lib/commands/{ => settings}/settings.ts (100%) rename lib/commands/{ => support}/support.ts (100%) rename lib/commands/{ => tags}/tags.ts (100%) diff --git a/lib/commands/login.ts b/lib/commands/auth/login.ts similarity index 100% rename from lib/commands/login.ts rename to lib/commands/auth/login.ts diff --git a/lib/commands/logout.ts b/lib/commands/auth/logout.ts similarity index 100% rename from lib/commands/logout.ts rename to lib/commands/auth/logout.ts diff --git a/lib/commands/whoami.ts b/lib/commands/auth/whoami.ts similarity index 100% rename from lib/commands/whoami.ts rename to lib/commands/auth/whoami.ts diff --git a/lib/commands/build.ts b/lib/commands/deploy/build.ts similarity index 100% rename from lib/commands/build.ts rename to lib/commands/deploy/build.ts diff --git a/lib/commands/deploy.ts b/lib/commands/deploy/deploy.ts similarity index 100% rename from lib/commands/deploy.ts rename to lib/commands/deploy/deploy.ts diff --git a/lib/commands/envs.ts b/lib/commands/envs/envs.ts similarity index 100% rename from lib/commands/envs.ts rename to lib/commands/envs/envs.ts diff --git a/lib/commands/fleets.ts b/lib/commands/fleets/fleets.ts similarity index 100% rename from lib/commands/fleets.ts rename to lib/commands/fleets/fleets.ts diff --git a/lib/commands/version.ts b/lib/commands/help/version.ts similarity index 100% rename from lib/commands/version.ts rename to lib/commands/help/version.ts diff --git a/lib/commands/keys.ts b/lib/commands/keys/keys.ts similarity index 100% rename from lib/commands/keys.ts rename to lib/commands/keys/keys.ts diff --git a/lib/commands/logs.ts b/lib/commands/logs/logs.ts similarity index 100% rename from lib/commands/logs.ts rename to lib/commands/logs/logs.ts diff --git a/lib/commands/scan.ts b/lib/commands/network/scan.ts similarity index 100% rename from lib/commands/scan.ts rename to lib/commands/network/scan.ts diff --git a/lib/commands/ssh.ts b/lib/commands/network/ssh.ts similarity index 100% rename from lib/commands/ssh.ts rename to lib/commands/network/ssh.ts diff --git a/lib/commands/tunnel.ts b/lib/commands/network/tunnel.ts similarity index 100% rename from lib/commands/tunnel.ts rename to lib/commands/network/tunnel.ts diff --git a/lib/commands/note.ts b/lib/commands/notes/note.ts similarity index 100% rename from lib/commands/note.ts rename to lib/commands/notes/note.ts diff --git a/lib/commands/orgs.ts b/lib/commands/orgs/orgs.ts similarity index 100% rename from lib/commands/orgs.ts rename to lib/commands/orgs/orgs.ts diff --git a/lib/commands/join.ts b/lib/commands/platform/join.ts similarity index 100% rename from lib/commands/join.ts rename to lib/commands/platform/join.ts diff --git a/lib/commands/leave.ts b/lib/commands/platform/leave.ts similarity index 100% rename from lib/commands/leave.ts rename to lib/commands/platform/leave.ts diff --git a/lib/commands/preload.ts b/lib/commands/preload/preload.ts similarity index 100% rename from lib/commands/preload.ts rename to lib/commands/preload/preload.ts diff --git a/lib/commands/push.ts b/lib/commands/push/push.ts similarity index 100% rename from lib/commands/push.ts rename to lib/commands/push/push.ts diff --git a/lib/commands/releases.ts b/lib/commands/releases/releases.ts similarity index 100% rename from lib/commands/releases.ts rename to lib/commands/releases/releases.ts diff --git a/lib/commands/settings.ts b/lib/commands/settings/settings.ts similarity index 100% rename from lib/commands/settings.ts rename to lib/commands/settings/settings.ts diff --git a/lib/commands/support.ts b/lib/commands/support/support.ts similarity index 100% rename from lib/commands/support.ts rename to lib/commands/support/support.ts diff --git a/lib/commands/tags.ts b/lib/commands/tags/tags.ts similarity index 100% rename from lib/commands/tags.ts rename to lib/commands/tags/tags.ts From 0711eefb7cfbced86ebc0d0af7d7cd5dfa976ccc Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 8 Nov 2023 04:02:25 +0530 Subject: [PATCH 03/10] Update all imports to match new command directory structure Signed-off-by: Vipul Gupta (@vipulgupta2048) --- lib/commands/auth/login.ts | 16 +++++----- lib/commands/auth/logout.ts | 4 +-- lib/commands/auth/whoami.ts | 4 +-- lib/commands/deploy/build.ts | 30 ++++++++--------- lib/commands/deploy/{deploy.ts => index.ts} | 32 +++++++++---------- lib/commands/envs/{envs.ts => index.ts} | 20 +++++++----- lib/commands/fleets/{fleets.ts => index.ts} | 6 ++-- lib/commands/help/version.ts | 6 ++-- lib/commands/keys/{keys.ts => index.ts} | 6 ++-- lib/commands/logs/{logs.ts => index.ts} | 18 +++++------ lib/commands/network/scan.ts | 12 ++++--- lib/commands/network/ssh.ts | 25 +++++++++------ lib/commands/network/tunnel.ts | 16 ++++++---- lib/commands/notes/{note.ts => index.ts} | 8 ++--- lib/commands/orgs/{orgs.ts => index.ts} | 8 ++--- lib/commands/platform/join.ts | 12 +++---- lib/commands/platform/leave.ts | 10 +++--- lib/commands/preload/{preload.ts => index.ts} | 24 +++++++------- lib/commands/push/{push.ts => index.ts} | 28 ++++++++-------- .../releases/{releases.ts => index.ts} | 12 +++---- .../settings/{settings.ts => index.ts} | 6 ++-- lib/commands/support/support.ts | 12 +++---- lib/commands/tags/{tags.ts => index.ts} | 14 ++++---- 23 files changed, 173 insertions(+), 156 deletions(-) rename lib/commands/deploy/{deploy.ts => index.ts} (93%) rename lib/commands/envs/{envs.ts => index.ts} (95%) rename lib/commands/fleets/{fleets.ts => index.ts} (94%) rename lib/commands/keys/{keys.ts => index.ts} (89%) rename lib/commands/logs/{logs.ts => index.ts} (91%) rename lib/commands/notes/{note.ts => index.ts} (91%) rename lib/commands/orgs/{orgs.ts => index.ts} (84%) rename lib/commands/preload/{preload.ts => index.ts} (96%) rename lib/commands/push/{push.ts => index.ts} (94%) rename lib/commands/releases/{releases.ts => index.ts} (86%) rename lib/commands/settings/{settings.ts => index.ts} (88%) rename lib/commands/tags/{tags.ts => index.ts} (88%) diff --git a/lib/commands/auth/login.ts b/lib/commands/auth/login.ts index e8c2211c..70d6c1c6 100644 --- a/lib/commands/auth/login.ts +++ b/lib/commands/auth/login.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent, getCliForm } from '../utils/lazy'; -import { ExpectedError } from '../errors'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; +import { ExpectedError } from '../../errors'; import type { WhoamiResult } from 'balena-sdk'; interface FlagsDef { @@ -123,7 +123,7 @@ export default class LoginCmd extends Command { const { flags: options, args: params } = await this.parse(LoginCmd); const balena = getBalenaSdk(); - const messages = await import('../utils/messages'); + const messages = await import('../../utils/messages'); const balenaUrl = await balena.settings.get('balenaUrl'); // Consolidate user/email options @@ -202,16 +202,16 @@ ${messages.reachingOut}`); } // Credentials else if (loginOptions.credentials) { - const patterns = await import('../utils/patterns'); + const patterns = await import('../../utils/patterns'); return patterns.authenticate(loginOptions); } // Web else if (loginOptions.web) { - const auth = await import('../auth'); + const auth = await import('../../auth'); await auth.login({ port: loginOptions.port }); return; } else { - const patterns = await import('../utils/patterns'); + const patterns = await import('../../utils/patterns'); // User had not selected login preference, prompt interactively const loginType = await patterns.askLoginType(); if (loginType === 'register') { diff --git a/lib/commands/auth/logout.ts b/lib/commands/auth/logout.ts index 89d8c727..5ea45963 100644 --- a/lib/commands/auth/logout.ts +++ b/lib/commands/auth/logout.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import Command from '../command'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; export default class LogoutCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/auth/whoami.ts b/lib/commands/auth/whoami.ts index 5d96cc7a..adc81acd 100644 --- a/lib/commands/auth/whoami.ts +++ b/lib/commands/auth/whoami.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import Command from '../command'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; export default class WhoamiCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/deploy/build.ts b/lib/commands/deploy/build.ts index 72efca76..44718584 100644 --- a/lib/commands/deploy/build.ts +++ b/lib/commands/deploy/build.ts @@ -16,20 +16,20 @@ */ import { Args, Flags } from '@oclif/core'; -import Command from '../command'; -import { getBalenaSdk } from '../utils/lazy'; -import * as cf from '../utils/common-flags'; -import * as compose from '../utils/compose'; +import Command from '../../command'; +import { getBalenaSdk } from '../../utils/lazy'; +import * as cf from '../../utils/common-flags'; +import * as compose from '../../utils/compose'; import type { ApplicationType, BalenaSDK } from 'balena-sdk'; import { buildArgDeprecation, dockerignoreHelp, registrySecretsHelp, -} from '../utils/messages'; -import type { ComposeCliFlags, ComposeOpts } from '../utils/compose-types'; -import { buildProject, composeCliFlags } from '../utils/compose_ts'; -import type { BuildOpts, DockerCliFlags } from '../utils/docker'; -import { dockerCliFlags } from '../utils/docker'; +} from '../../utils/messages'; +import type { ComposeCliFlags, ComposeOpts } from '../../utils/compose-types'; +import { buildProject, composeCliFlags } from '../../utils/compose_ts'; +import type { BuildOpts, DockerCliFlags } from '../../utils/docker'; +import { dockerCliFlags } from '../../utils/docker'; // TODO: For this special one we can't use Interfaces.InferredFlags/InferredArgs // because of the 'registry-secrets' type which is defined in the actual code @@ -148,14 +148,14 @@ ${dockerignoreHelp} (opts.fleet == null && (opts.arch == null || opts.deviceType == null)) || (opts.fleet != null && (opts.arch != null || opts.deviceType != null)) ) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../../errors'); throw new ExpectedError( 'You must specify either a fleet (-f), or the device type (-d) and architecture (-A)', ); } // Validate project directory - const { validateProjectDirectory } = await import('../utils/compose_ts'); + const { validateProjectDirectory } = await import('../../utils/compose_ts'); const { dockerfilePath, registrySecrets } = await validateProjectDirectory( sdk, { @@ -172,7 +172,7 @@ ${dockerignoreHelp} protected async getAppAndResolveArch(opts: FlagsDef) { if (opts.fleet) { - const { getAppWithArch } = await import('../utils/helpers'); + const { getAppWithArch } = await import('../../utils/helpers'); const app = await getAppWithArch(opts.fleet); opts.arch = app.arch; opts.deviceType = app.is_for__device_type[0].slug; @@ -181,7 +181,7 @@ ${dockerignoreHelp} } protected async prepareBuild(options: FlagsDef) { - const { getDocker, generateBuildOpts } = await import('../utils/docker'); + const { getDocker, generateBuildOpts } = await import('../../utils/docker'); const [docker, buildOpts, composeOpts] = await Promise.all([ getDocker(options), generateBuildOpts(options), @@ -209,7 +209,7 @@ ${dockerignoreHelp} */ protected async buildProject( docker: import('dockerode'), - logger: import('../utils/logger'), + logger: import('../../utils/logger'), composeOpts: ComposeOpts, opts: { app?: { @@ -221,7 +221,7 @@ ${dockerignoreHelp} buildOpts: BuildOpts; }, ) { - const { loadProject } = await import('../utils/compose_ts'); + const { loadProject } = await import('../../utils/compose_ts'); const project = await loadProject( logger, diff --git a/lib/commands/deploy/deploy.ts b/lib/commands/deploy/index.ts similarity index 93% rename from lib/commands/deploy/deploy.ts rename to lib/commands/deploy/index.ts index abc84683..c4be73c0 100644 --- a/lib/commands/deploy/deploy.ts +++ b/lib/commands/deploy/index.ts @@ -18,31 +18,31 @@ import { Args, Flags } from '@oclif/core'; import type { ImageDescriptor } from '@balena/compose/dist/parse'; -import Command from '../command'; -import { ExpectedError } from '../errors'; -import { getBalenaSdk, getChalk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy'; import { dockerignoreHelp, registrySecretsHelp, buildArgDeprecation, -} from '../utils/messages'; -import * as ca from '../utils/common-args'; -import * as compose from '../utils/compose'; +} from '../../utils/messages'; +import * as ca from '../../utils/common-args'; +import * as compose from '../../utils/compose'; import type { BuiltImage, ComposeCliFlags, ComposeOpts, Release as ComposeReleaseInfo, -} from '../utils/compose-types'; -import type { BuildOpts, DockerCliFlags } from '../utils/docker'; +} from '../../utils/compose-types'; +import type { BuildOpts, DockerCliFlags } from '../../utils/docker'; import { applyReleaseTagKeysAndValues, buildProject, composeCliFlags, isBuildConfig, parseReleaseTagKeysAndValues, -} from '../utils/compose_ts'; -import { dockerCliFlags } from '../utils/docker'; +} from '../../utils/compose_ts'; +import { dockerCliFlags } from '../../utils/docker'; import type { ApplicationType, DeviceType, Release } from 'balena-sdk'; interface ApplicationWithArch { @@ -175,7 +175,7 @@ ${dockerignoreHelp} const sdk = getBalenaSdk(); const { getRegistrySecrets, validateProjectDirectory } = await import( - '../utils/compose_ts' + '../../utils/compose_ts' ); const { releaseTagKeys, releaseTagValues } = parseReleaseTagKeysAndValues( @@ -199,10 +199,10 @@ ${dockerignoreHelp} (options as FlagsDef)['registry-secrets'] = registrySecrets; } - const helpers = await import('../utils/helpers'); + const helpers = await import('../../utils/helpers'); const app = await helpers.getAppWithArch(fleet); - const dockerUtils = await import('../utils/docker'); + const dockerUtils = await import('../../utils/docker'); const [docker, buildOpts, composeOpts] = await Promise.all([ dockerUtils.getDocker(options), dockerUtils.generateBuildOpts(options as FlagsDef), @@ -232,7 +232,7 @@ ${dockerignoreHelp} async deployProject( docker: import('dockerode'), - logger: import('../utils/logger'), + logger: import('../../utils/logger'), composeOpts: ComposeOpts, opts: { app: ApplicationWithArch; // the application instance to deploy to @@ -250,7 +250,7 @@ ${dockerignoreHelp} const doodles = await import('resin-doodles'); const sdk = getBalenaSdk(); const { deployProject: $deployProject, loadProject } = await import( - '../utils/compose_ts' + '../../utils/compose_ts' ); const appType = opts.app.application_type[0]; @@ -332,7 +332,7 @@ ${dockerignoreHelp} let release: Release | ComposeReleaseInfo['release']; if (appType.slug === 'legacy-v1' || appType.slug === 'legacy-v2') { - const { deployLegacy } = require('../utils/deploy-legacy'); + const { deployLegacy } = require('../../utils/deploy-legacy'); const msg = getChalk().yellow( 'Target fleet requires legacy deploy method.', diff --git a/lib/commands/envs/envs.ts b/lib/commands/envs/index.ts similarity index 95% rename from lib/commands/envs/envs.ts rename to lib/commands/envs/index.ts index 2a2aeefe..9434b7f9 100644 --- a/lib/commands/envs/envs.ts +++ b/lib/commands/envs/index.ts @@ -18,11 +18,11 @@ import { Flags } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; import type * as SDK from 'balena-sdk'; import * as _ from 'lodash'; -import Command from '../command'; -import { ExpectedError } from '../errors'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; -import { applicationIdInfo } from '../utils/messages'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import { applicationIdInfo } from '../../utils/messages'; type FlagsDef = Interfaces.InferredFlags; @@ -124,12 +124,16 @@ export default class EnvsCmd extends Command { const balena = getBalenaSdk(); let fleetSlug: string | undefined = options.fleet - ? await (await import('../utils/sdk')).getFleetSlug(balena, options.fleet) + ? await ( + await import('../../utils/sdk') + ).getFleetSlug(balena, options.fleet) : undefined; let fullUUID: string | undefined; // as oppposed to the short, 7-char UUID if (options.device) { - const { getDeviceAndMaybeAppFromUUID } = await import('../utils/cloud'); + const { getDeviceAndMaybeAppFromUUID } = await import( + '../../utils/cloud' + ); const [device, app] = await getDeviceAndMaybeAppFromUUID( balena, options.device, @@ -182,7 +186,7 @@ export default class EnvsCmd extends Command { } if (options.json) { - const { pickAndRename } = await import('../utils/helpers'); + const { pickAndRename } = await import('../../utils/helpers'); const mapped = varArray.map((o) => pickAndRename(o, fields)); this.log(JSON.stringify(mapped, null, 4)); } else { diff --git a/lib/commands/fleets/fleets.ts b/lib/commands/fleets/index.ts similarity index 94% rename from lib/commands/fleets/fleets.ts rename to lib/commands/fleets/index.ts index a4b0a194..fe649c18 100644 --- a/lib/commands/fleets/fleets.ts +++ b/lib/commands/fleets/index.ts @@ -17,9 +17,9 @@ import type * as BalenaSdk from 'balena-sdk'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; interface ExtendedApplication extends ApplicationWithDeviceTypeSlug { device_count: number; diff --git a/lib/commands/help/version.ts b/lib/commands/help/version.ts index 970d362d..9c59a8cc 100644 --- a/lib/commands/help/version.ts +++ b/lib/commands/help/version.ts @@ -16,8 +16,8 @@ */ import { Flags } from '@oclif/core'; -import Command from '../command'; -import { stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import { stripIndent } from '../../utils/lazy'; export interface JsonVersions { 'balena-cli': string; @@ -72,7 +72,7 @@ export default class VersionCmd extends Command { public async run() { const { flags: options } = await this.parse(VersionCmd); const versions: JsonVersions = { - 'balena-cli': (await import('../../package.json')).version, + 'balena-cli': (await import('../../../package.json')).version, 'Node.js': process.version && process.version.startsWith('v') ? process.version.slice(1) diff --git a/lib/commands/keys/keys.ts b/lib/commands/keys/index.ts similarity index 89% rename from lib/commands/keys/keys.ts rename to lib/commands/keys/index.ts index fa8db893..ca81f366 100644 --- a/lib/commands/keys/keys.ts +++ b/lib/commands/keys/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; export default class KeysCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/logs/logs.ts b/lib/commands/logs/index.ts similarity index 91% rename from lib/commands/logs/logs.ts rename to lib/commands/logs/index.ts index ef0f1204..4745211a 100644 --- a/lib/commands/logs/logs.ts +++ b/lib/commands/logs/index.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { LogMessage } from 'balena-sdk'; const MAX_RETRY = 1000; @@ -96,14 +96,14 @@ export default class LogsCmd extends Command { const { args: params, flags: options } = await this.parse(LogsCmd); const balena = getBalenaSdk(); - const { serviceIdToName } = await import('../utils/cloud'); + const { serviceIdToName } = await import('../../utils/cloud'); const { connectAndDisplayDeviceLogs, displayLogObject } = await import( - '../utils/device/logs' + '../../utils/device/logs' ); const { validateIPAddress, validateDotLocalUrl } = await import( - '../utils/validation' + '../../utils/validation' ); - const Logger = await import('../utils/logger'); + const Logger = await import('../../utils/logger'); const logger = Logger.getLogger(); @@ -132,13 +132,13 @@ export default class LogsCmd extends Command { validateDotLocalUrl(params.device) ) { // Logs from local device - const { DeviceAPI } = await import('../utils/device/api'); + const { DeviceAPI } = await import('../../utils/device/api'); const deviceApi = new DeviceAPI(logger, params.device); logger.logDebug('Checking we can access device'); try { await deviceApi.ping(); } catch (e) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../../errors'); throw new ExpectedError( `Cannot access device at address ${params.device}. Device may not be in local mode.`, ); diff --git a/lib/commands/network/scan.ts b/lib/commands/network/scan.ts index e18f8781..fd6fdcc2 100644 --- a/lib/commands/network/scan.ts +++ b/lib/commands/network/scan.ts @@ -16,9 +16,9 @@ */ import { Flags } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getCliUx, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getCliUx, stripIndent } from '../../utils/lazy'; export default class ScanCmd extends Command { public static description = stripIndent` @@ -64,9 +64,11 @@ export default class ScanCmd extends Command { public async run() { const _ = await import('lodash'); - const { discoverLocalBalenaOsDevices } = await import('../utils/discover'); + const { discoverLocalBalenaOsDevices } = await import( + '../../utils/discover' + ); const prettyjson = await import('prettyjson'); - const dockerUtils = await import('../utils/docker'); + const dockerUtils = await import('../../utils/docker'); const dockerPort = 2375; const dockerTimeout = 2000; diff --git a/lib/commands/network/ssh.ts b/lib/commands/network/ssh.ts index d2a78a6e..477736ff 100644 --- a/lib/commands/network/ssh.ts +++ b/lib/commands/network/ssh.ts @@ -16,10 +16,13 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; -import { parseAsInteger, validateLocalHostnameOrIp } from '../utils/validation'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { + parseAsInteger, + validateLocalHostnameOrIp, +} from '../../utils/validation'; export default class SshCmd extends Command { public static description = stripIndent` @@ -108,7 +111,7 @@ export default class SshCmd extends Command { // Local connection if (validateLocalHostnameOrIp(params.fleetOrDevice)) { - const { performLocalDeviceSSH } = await import('../utils/device/ssh'); + const { performLocalDeviceSSH } = await import('../../utils/device/ssh'); return await performLocalDeviceSSH({ hostname: params.fleetOrDevice, port: options.port || 'local', @@ -119,8 +122,8 @@ export default class SshCmd extends Command { } // Remote connection - const { getProxyConfig } = await import('../utils/helpers'); - const { getOnlineTargetDeviceUuid } = await import('../utils/patterns'); + const { getProxyConfig } = await import('../../utils/helpers'); + const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns'); const sdk = getBalenaSdk(); const proxyConfig = getProxyConfig(); @@ -134,7 +137,7 @@ export default class SshCmd extends Command { params.fleetOrDevice, ); - const { which } = await import('../utils/which'); + const { which } = await import('../../utils/which'); const [whichProxytunnel, { username }, proxyUrl] = await Promise.all([ useProxy ? which('proxytunnel', false) : undefined, @@ -185,7 +188,9 @@ export default class SshCmd extends Command { // that we know exists and is accessible let containerId: string | undefined; if (params.service != null) { - const { getContainerIdForService } = await import('../utils/device/ssh'); + const { getContainerIdForService } = await import( + '../../utils/device/ssh' + ); containerId = await getContainerIdForService({ deviceUuid, hostname: `ssh.${proxyUrl}`, @@ -202,7 +207,7 @@ export default class SshCmd extends Command { } else { accessCommand = `host ${deviceUuid}`; } - const { runRemoteCommand } = await import('../utils/ssh'); + const { runRemoteCommand } = await import('../../utils/ssh'); await runRemoteCommand({ cmd: accessCommand, hostname: `ssh.${proxyUrl}`, diff --git a/lib/commands/network/tunnel.ts b/lib/commands/network/tunnel.ts index 56fb9766..91be2fe6 100644 --- a/lib/commands/network/tunnel.ts +++ b/lib/commands/network/tunnel.ts @@ -16,15 +16,15 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; +import Command from '../../command'; import { NoPortsDefinedError, InvalidPortMappingError, ExpectedError, -} from '../errors'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; -import { lowercaseIfSlug } from '../utils/normalization'; +} from '../../errors'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { lowercaseIfSlug } from '../../utils/normalization'; import type { Server, Socket } from 'net'; @@ -122,7 +122,7 @@ export default class TunnelCmd extends Command { } // Ascertain device uuid - const { getOnlineTargetDeviceUuid } = await import('../utils/patterns'); + const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns'); const uuid = await getOnlineTargetDeviceUuid(sdk, params.deviceOrFleet); logger.logInfo(`Opening a tunnel to ${uuid}...`); @@ -133,7 +133,9 @@ export default class TunnelCmd extends Command { }) .map(async ({ localPort, localAddress, remotePort }) => { try { - const { tunnelConnectionToDevice } = await import('../utils/tunnel'); + const { tunnelConnectionToDevice } = await import( + '../../utils/tunnel' + ); const handler = await tunnelConnectionToDevice(uuid, remotePort, sdk); const { createServer } = await import('net'); diff --git a/lib/commands/notes/note.ts b/lib/commands/notes/index.ts similarity index 91% rename from lib/commands/notes/note.ts rename to lib/commands/notes/index.ts index 8afd2036..fb3e38fc 100644 --- a/lib/commands/notes/note.ts +++ b/lib/commands/notes/index.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; -import { ExpectedError } from '../errors'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; export default class NoteCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/orgs/orgs.ts b/lib/commands/orgs/index.ts similarity index 84% rename from lib/commands/orgs/orgs.ts rename to lib/commands/orgs/index.ts index b05ffa40..f50604f8 100644 --- a/lib/commands/orgs/orgs.ts +++ b/lib/commands/orgs/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; export default class OrgsCmd extends Command { public static description = stripIndent` @@ -38,7 +38,7 @@ export default class OrgsCmd extends Command { public async run() { await this.parse(OrgsCmd); - const { getOwnOrganizations } = await import('../utils/sdk'); + const { getOwnOrganizations } = await import('../../utils/sdk'); // Get organizations const organizations = await getOwnOrganizations(getBalenaSdk(), { diff --git a/lib/commands/platform/join.ts b/lib/commands/platform/join.ts index a483bed8..152381b3 100644 --- a/lib/commands/platform/join.ts +++ b/lib/commands/platform/join.ts @@ -16,11 +16,11 @@ */ import { Args, Flags } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; -import { applicationIdInfo } from '../utils/messages'; -import { parseAsLocalHostnameOrIp } from '../utils/validation'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { applicationIdInfo } from '../../utils/messages'; +import { parseAsLocalHostnameOrIp } from '../../utils/validation'; export default class JoinCmd extends Command { public static description = stripIndent` @@ -78,7 +78,7 @@ export default class JoinCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(JoinCmd); - const promote = await import('../utils/promote'); + const promote = await import('../../utils/promote'); const sdk = getBalenaSdk(); const logger = await Command.getLogger(); return promote.join( diff --git a/lib/commands/platform/leave.ts b/lib/commands/platform/leave.ts index 46a08c2a..2365d007 100644 --- a/lib/commands/platform/leave.ts +++ b/lib/commands/platform/leave.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { stripIndent } from '../utils/lazy'; -import { parseAsLocalHostnameOrIp } from '../utils/validation'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { stripIndent } from '../../utils/lazy'; +import { parseAsLocalHostnameOrIp } from '../../utils/validation'; export default class LeaveCmd extends Command { public static description = stripIndent` @@ -62,7 +62,7 @@ export default class LeaveCmd extends Command { public async run() { const { args: params } = await this.parse(LeaveCmd); - const promote = await import('../utils/promote'); + const promote = await import('../../utils/promote'); const logger = await Command.getLogger(); return promote.leave(logger, params.deviceIpOrHostname); } diff --git a/lib/commands/preload/preload.ts b/lib/commands/preload/index.ts similarity index 96% rename from lib/commands/preload/preload.ts rename to lib/commands/preload/index.ts index 572cc0e1..3ecee597 100644 --- a/lib/commands/preload/preload.ts +++ b/lib/commands/preload/index.ts @@ -15,18 +15,18 @@ * limitations under the License. */ -import Command from '../command'; -import { ExpectedError } from '../errors'; -import * as cf from '../utils/common-flags'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliForm, getVisuals, stripIndent, -} from '../utils/lazy'; -import { applicationIdInfo } from '../utils/messages'; -import { dockerConnectionCliFlags } from '../utils/docker'; -import { parseAsInteger } from '../utils/validation'; +} from '../../utils/lazy'; +import { applicationIdInfo } from '../../utils/messages'; +import { dockerConnectionCliFlags } from '../../utils/docker'; +import { parseAsInteger } from '../../utils/validation'; import { Flags, Args } from '@oclif/core'; import * as _ from 'lodash'; @@ -148,7 +148,7 @@ Can be repeated to add multiple certificates.\ const balenaPreload = await import('balena-preload'); const visuals = getVisuals(); const nodeCleanup = await import('node-cleanup'); - const { instanceOf } = await import('../errors'); + const { instanceOf } = await import('../../errors'); // Check image file exists try { @@ -171,7 +171,9 @@ Can be repeated to add multiple certificates.\ // balena-preload currently does not work with numerical app IDs // Load app here, and use app slug from hereon const fleetSlug: string | undefined = options.fleet - ? await (await import('../utils/sdk')).getFleetSlug(balena, options.fleet) + ? await ( + await import('../../utils/sdk') + ).getFleetSlug(balena, options.fleet) : undefined; const progressBars: { @@ -227,7 +229,7 @@ Can be repeated to add multiple certificates.\ } // Get a configured dockerode instance - const dockerUtils = await import('../utils/docker'); + const dockerUtils = await import('../../utils/docker'); const docker = await dockerUtils.getDocker(options); const preloader = new balenaPreload.Preloader( undefined, @@ -479,7 +481,7 @@ Would you like to disable automatic updates for this fleet now?\ } async getAppWithReleases(balenaSdk: BalenaSDK, slug: string) { - const { getApplication } = await import('../utils/sdk'); + const { getApplication } = await import('../../utils/sdk'); return await getApplication(balenaSdk, slug, { $expand: this.applicationExpandOptions, diff --git a/lib/commands/push/push.ts b/lib/commands/push/index.ts similarity index 94% rename from lib/commands/push/push.ts rename to lib/commands/push/index.ts index e5623dcb..a00c0fb4 100644 --- a/lib/commands/push/push.ts +++ b/lib/commands/push/index.ts @@ -17,18 +17,18 @@ import { Flags, Args } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; -import { dockerignoreHelp, registrySecretsHelp } from '../utils/messages'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { dockerignoreHelp, registrySecretsHelp } from '../../utils/messages'; import type { BalenaSDK } from 'balena-sdk'; -import { ExpectedError, instanceOf } from '../errors'; +import { ExpectedError, instanceOf } from '../../errors'; import { RegistrySecrets } from '@balena/compose/dist/multibuild'; -import { lowercaseIfSlug } from '../utils/normalization'; +import { lowercaseIfSlug } from '../../utils/normalization'; import { applyReleaseTagKeysAndValues, parseReleaseTagKeysAndValues, -} from '../utils/compose_ts'; +} from '../../utils/compose_ts'; enum BuildTarget { Cloud, @@ -233,7 +233,7 @@ export default class PushCmd extends Command { logger.logDebug(`Using build source directory: ${options.source} `); const sdk = getBalenaSdk(); - const { validateProjectDirectory } = await import('../utils/compose_ts'); + const { validateProjectDirectory } = await import('../../utils/compose_ts'); const { dockerfilePath, registrySecrets } = await validateProjectDirectory( sdk, { @@ -276,8 +276,8 @@ export default class PushCmd extends Command { dockerfilePath: string, registrySecrets: RegistrySecrets, ) { - const remote = await import('../utils/remote-build'); - const { getApplication } = await import('../utils/sdk'); + const remote = await import('../../utils/remote-build'); + const { getApplication } = await import('../../utils/sdk'); // Check for invalid options const localOnlyOptions: Array = [ @@ -356,7 +356,7 @@ export default class PushCmd extends Command { 'is only valid when pushing to a fleet', ); - const deviceDeploy = await import('../utils/device/deploy'); + const deviceDeploy = await import('../../utils/device/deploy'); try { await deviceDeploy.deployToDevice({ @@ -376,7 +376,7 @@ export default class PushCmd extends Command { convertEol: !options['noconvert-eol'], }); } catch (e) { - const { BuildError } = await import('../utils/device/errors'); + const { BuildError } = await import('../../utils/device/errors'); if (instanceOf(e, BuildError)) { throw new ExpectedError(e.toString()); } else { @@ -386,7 +386,9 @@ export default class PushCmd extends Command { } protected async getBuildTarget(appOrDevice: string): Promise { - const { validateLocalHostnameOrIp } = await import('../utils/validation'); + const { validateLocalHostnameOrIp } = await import( + '../../utils/validation' + ); return validateLocalHostnameOrIp(appOrDevice) ? BuildTarget.Device diff --git a/lib/commands/releases/releases.ts b/lib/commands/releases/index.ts similarity index 86% rename from lib/commands/releases/releases.ts rename to lib/commands/releases/index.ts index 7be38b26..5efc7ce0 100644 --- a/lib/commands/releases/releases.ts +++ b/lib/commands/releases/index.ts @@ -16,12 +16,12 @@ */ import { Args } from '@oclif/core'; -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; -import { applicationNameNote } from '../utils/messages'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import { applicationNameNote } from '../../utils/messages'; import type * as BalenaSdk from 'balena-sdk'; -import { jsonInfo } from '../utils/messages'; +import { jsonInfo } from '../../utils/messages'; export default class ReleasesCmd extends Command { public static description = stripIndent` @@ -67,7 +67,7 @@ export default class ReleasesCmd extends Command { ]; const balena = getBalenaSdk(); - const { getFleetSlug } = await import('../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk'); const releases = await balena.models.release.getAllByApplication( await getFleetSlug(balena, params.fleet), diff --git a/lib/commands/settings/settings.ts b/lib/commands/settings/index.ts similarity index 88% rename from lib/commands/settings/settings.ts rename to lib/commands/settings/index.ts index 47447728..f54c4db0 100644 --- a/lib/commands/settings/settings.ts +++ b/lib/commands/settings/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../command'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../utils/lazy'; +import Command from '../../command'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy'; export default class SettingsCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/support/support.ts b/lib/commands/support/support.ts index 349ababe..84af6f4c 100644 --- a/lib/commands/support/support.ts +++ b/lib/commands/support/support.ts @@ -16,11 +16,11 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../command'; -import { ExpectedError } from '../errors'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../utils/lazy'; -import { applicationIdInfo } from '../utils/messages'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; +import { applicationIdInfo } from '../../utils/messages'; export default class SupportCmd extends Command { public static description = stripIndent` @@ -116,7 +116,7 @@ export default class SupportCmd extends Command { ux.action.stop(); } - const { getFleetSlug } = await import('../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk'); // Process applications for (const appName of appNames) { diff --git a/lib/commands/tags/tags.ts b/lib/commands/tags/index.ts similarity index 88% rename from lib/commands/tags/tags.ts rename to lib/commands/tags/index.ts index 62434fe1..9653c396 100644 --- a/lib/commands/tags/tags.ts +++ b/lib/commands/tags/index.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import Command from '../command'; -import { ExpectedError } from '../errors'; -import * as cf from '../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../utils/lazy'; -import { applicationIdInfo } from '../utils/messages'; +import Command from '../../command'; +import { ExpectedError } from '../../errors'; +import * as cf from '../../utils/common-flags'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import { applicationIdInfo } from '../../utils/messages'; export default class TagsCmd extends Command { public static description = stripIndent` @@ -71,7 +71,7 @@ export default class TagsCmd extends Command { let tags; if (options.fleet) { - const { getFleetSlug } = await import('../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk'); tags = await balena.models.application.tags.getAllByApplication( await getFleetSlug(balena, options.fleet), ); @@ -81,7 +81,7 @@ export default class TagsCmd extends Command { } if (options.release) { const { disambiguateReleaseParam } = await import( - '../utils/normalization' + '../../utils/normalization' ); const releaseParam = await disambiguateReleaseParam( balena, From 99094dbfdaeae73851039d380edfd8bc7724d1b9 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 8 Nov 2023 04:03:48 +0530 Subject: [PATCH 04/10] Throw error if command directory rules not followed Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/build-bin.ts | 2 +- automation/capitanodoc/capitanodoc.ts | 26 +- completion/_balena | 26 +- completion/balena-completion.bash | 26 +- docs/balena-cli.md | 578 ++++++++++++++++---------- 5 files changed, 431 insertions(+), 227 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index 75f067e1..7c83bf1f 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import type { JsonVersions } from '../lib/commands/version'; +import type { JsonVersions } from '../lib/commands/help/version'; import { run as oclifRun } from '@oclif/core'; import * as archiver from 'archiver'; diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 2b263de8..b5cb5571 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -17,7 +17,7 @@ import * as path from 'path'; import { MarkdownFileParser } from './utils'; -import { globSync } from 'glob'; +import { GlobSync } from 'glob'; /** * This is the skeleton of CLI documentation/reference web page at: @@ -68,12 +68,26 @@ const commandHeadings: { [key: string]: string } = { }; // Fetch all available commands -const allCommandsPaths = globSync('build/commands/**/*.js', { +const allCommandsPaths = new GlobSync('build/commands/**/*.js', { ignore: 'build/commands/internal/**', -}); +}).found; + +// Throw error if any commands found outside of command directories +// +const illegalCommandPaths = allCommandsPaths.filter((commandPath: string) => + /^build\/commands\/[^/]+\.js$/.test(commandPath), +); + +if (illegalCommandPaths.length !== 0) { + throw new Error( + `Found the following commands without a command directory: ${illegalCommandPaths}\n + To resolve this error, move the respective commands to their resource directories or create new ones.\n + Refer to the automation/capitanodoc/capitanodoc.ts file for more information.`, + ); +} // Docs config template -let capitanoDoc: Documentation = { +const capitanoDoc: Documentation = { title: 'balena CLI Documentation', introduction: '', categories: [], @@ -101,7 +115,7 @@ for (const commandPath of allCommandsPaths) { // Sort Category titles alhpabetically capitanoDoc.categories = capitanoDoc.categories.sort((a, b) => -a.title.localeCompare(b.title), + a.title.localeCompare(b.title), ); // Sort Category file paths alhpabetically @@ -109,7 +123,7 @@ capitanoDoc.categories.forEach((category) => { category.files.sort((a, b) => a.localeCompare(b)); }); -// TODO: Generate an error if commands are not in their folder +console.log(capitanoDoc.categories); /** * Modify and return the `capitanoDoc` object above in order to generate the diff --git a/completion/_balena b/completion/_balena index 25336988..d93c59c3 100644 --- a/completion/_balena +++ b/completion/_balena @@ -8,21 +8,27 @@ _balena() { local context state line curcontext="$curcontext" # Valid top-level completions - main_commands=( build deploy envs fleets join keys leave login logout logs note orgs preload push releases scan settings ssh support tags tunnel version whoami api-key api-keys app block config device device devices env fleet fleet internal key key local os release release tag util ) + main_commands=( api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets help internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util ) # Sub-completions api_key_cmds=( generate revoke ) app_cmds=( create ) + auth_cmds=( login logout whoami ) block_cmds=( create ) config_cmds=( generate inject read reconfigure write ) + deploy_cmds=( build ) device_cmds=( deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet ) devices_cmds=( supported ) env_cmds=( add rename rm ) fleet_cmds=( create pin purge rename restart rm track-latest ) + help_cmds=( version ) internal_cmds=( osinit ) key_cmds=( add rm ) local_cmds=( configure flash ) + network_cmds=( scan ssh tunnel ) os_cmds=( build-config configure download initialize versions ) + platform_cmds=( join leave ) release_cmds=( finalize invalidate validate ) + support_cmds=( support ) tag_cmds=( rm set ) @@ -48,12 +54,18 @@ _balena_sec_cmds() { "app") _describe -t app_cmds 'app_cmd' app_cmds "$@" && ret=0 ;; + "auth") + _describe -t auth_cmds 'auth_cmd' auth_cmds "$@" && ret=0 + ;; "block") _describe -t block_cmds 'block_cmd' block_cmds "$@" && ret=0 ;; "config") _describe -t config_cmds 'config_cmd' config_cmds "$@" && ret=0 ;; + "deploy") + _describe -t deploy_cmds 'deploy_cmd' deploy_cmds "$@" && ret=0 + ;; "device") _describe -t device_cmds 'device_cmd' device_cmds "$@" && ret=0 ;; @@ -66,6 +78,9 @@ _balena_sec_cmds() { "fleet") _describe -t fleet_cmds 'fleet_cmd' fleet_cmds "$@" && ret=0 ;; + "help") + _describe -t help_cmds 'help_cmd' help_cmds "$@" && ret=0 + ;; "internal") _describe -t internal_cmds 'internal_cmd' internal_cmds "$@" && ret=0 ;; @@ -75,12 +90,21 @@ _balena_sec_cmds() { "local") _describe -t local_cmds 'local_cmd' local_cmds "$@" && ret=0 ;; + "network") + _describe -t network_cmds 'network_cmd' network_cmds "$@" && ret=0 + ;; "os") _describe -t os_cmds 'os_cmd' os_cmds "$@" && ret=0 ;; + "platform") + _describe -t platform_cmds 'platform_cmd' platform_cmds "$@" && ret=0 + ;; "release") _describe -t release_cmds 'release_cmd' release_cmds "$@" && ret=0 ;; + "support") + _describe -t support_cmds 'support_cmd' support_cmds "$@" && ret=0 + ;; "tag") _describe -t tag_cmds 'tag_cmd' tag_cmds "$@" && ret=0 ;; diff --git a/completion/balena-completion.bash b/completion/balena-completion.bash index 566b28aa..b2802dcf 100644 --- a/completion/balena-completion.bash +++ b/completion/balena-completion.bash @@ -7,21 +7,27 @@ _balena_complete() local cur prev # Valid top-level completions - main_commands="build deploy envs fleets join keys leave login logout logs note orgs preload push releases scan settings ssh support tags tunnel version whoami api-key api-keys app block config device device devices env fleet fleet internal key key local os release release tag util" + main_commands="api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets help internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util" # Sub-completions api_key_cmds="generate revoke" app_cmds="create" + auth_cmds="login logout whoami" block_cmds="create" config_cmds="generate inject read reconfigure write" + deploy_cmds="build" device_cmds="deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet" devices_cmds="supported" env_cmds="add rename rm" fleet_cmds="create pin purge rename restart rm track-latest" + help_cmds="version" internal_cmds="osinit" key_cmds="add rm" local_cmds="configure flash" + network_cmds="scan ssh tunnel" os_cmds="build-config configure download initialize versions" + platform_cmds="join leave" release_cmds="finalize invalidate validate" + support_cmds="support" tag_cmds="rm set" @@ -42,12 +48,18 @@ _balena_complete() app) COMPREPLY=( $(compgen -W "$app_cmds" -- $cur) ) ;; + auth) + COMPREPLY=( $(compgen -W "$auth_cmds" -- $cur) ) + ;; block) COMPREPLY=( $(compgen -W "$block_cmds" -- $cur) ) ;; config) COMPREPLY=( $(compgen -W "$config_cmds" -- $cur) ) ;; + deploy) + COMPREPLY=( $(compgen -W "$deploy_cmds" -- $cur) ) + ;; device) COMPREPLY=( $(compgen -W "$device_cmds" -- $cur) ) ;; @@ -60,6 +72,9 @@ _balena_complete() fleet) COMPREPLY=( $(compgen -W "$fleet_cmds" -- $cur) ) ;; + help) + COMPREPLY=( $(compgen -W "$help_cmds" -- $cur) ) + ;; internal) COMPREPLY=( $(compgen -W "$internal_cmds" -- $cur) ) ;; @@ -69,12 +84,21 @@ _balena_complete() local) COMPREPLY=( $(compgen -W "$local_cmds" -- $cur) ) ;; + network) + COMPREPLY=( $(compgen -W "$network_cmds" -- $cur) ) + ;; os) COMPREPLY=( $(compgen -W "$os_cmds" -- $cur) ) ;; + platform) + COMPREPLY=( $(compgen -W "$platform_cmds" -- $cur) ) + ;; release) COMPREPLY=( $(compgen -W "$release_cmds" -- $cur) ) ;; + support) + COMPREPLY=( $(compgen -W "$support_cmds" -- $cur) ) + ;; tag) COMPREPLY=( $(compgen -W "$tag_cmds" -- $cur) ) ;; diff --git a/docs/balena-cli.md b/docs/balena-cli.md index adebd409..3502e1ff 100644 --- a/docs/balena-cli.md +++ b/docs/balena-cli.md @@ -1,3 +1,168 @@ +[ + { + title: 'API Key', + files: [ + 'build/commands/api-key/generate.js', + 'build/commands/api-key/revoke.js' + ] + }, + { title: 'API Keys', files: [ 'build/commands/api-keys/index.js' ] }, + { title: 'App', files: [ 'build/commands/app/create.js' ] }, + { + title: 'Authentication', + files: [ + 'build/commands/auth/login.js', + 'build/commands/auth/logout.js', + 'build/commands/auth/whoami.js' + ] + }, + { title: 'Block', files: [ 'build/commands/block/create.js' ] }, + { + title: 'Config', + files: [ + 'build/commands/config/generate.js', + 'build/commands/config/inject.js', + 'build/commands/config/read.js', + 'build/commands/config/reconfigure.js', + 'build/commands/config/write.js' + ] + }, + { + title: 'Deploy', + files: [ + 'build/commands/deploy/build.js', + 'build/commands/deploy/index.js' + ] + }, + { + title: 'Device', + files: [ + 'build/commands/device/deactivate.js', + 'build/commands/device/identify.js', + 'build/commands/device/index.js', + 'build/commands/device/init.js', + 'build/commands/device/local-mode.js', + 'build/commands/device/move.js', + 'build/commands/device/os-update.js', + 'build/commands/device/pin.js', + 'build/commands/device/public-url.js', + 'build/commands/device/purge.js', + 'build/commands/device/reboot.js', + 'build/commands/device/register.js', + 'build/commands/device/rename.js', + 'build/commands/device/restart.js', + 'build/commands/device/rm.js', + 'build/commands/device/shutdown.js', + 'build/commands/device/start-service.js', + 'build/commands/device/stop-service.js', + 'build/commands/device/track-fleet.js' + ] + }, + { + title: 'Devices', + files: [ + 'build/commands/devices/index.js', + 'build/commands/devices/supported.js' + ] + }, + { + title: 'Environment Variable', + files: [ + 'build/commands/env/add.js', + 'build/commands/env/rename.js', + 'build/commands/env/rm.js' + ] + }, + { + title: 'Environment Variables', + files: [ 'build/commands/envs/index.js' ] + }, + { + title: 'Fleet', + files: [ + 'build/commands/fleet/create.js', + 'build/commands/fleet/index.js', + 'build/commands/fleet/pin.js', + 'build/commands/fleet/purge.js', + 'build/commands/fleet/rename.js', + 'build/commands/fleet/restart.js', + 'build/commands/fleet/rm.js', + 'build/commands/fleet/track-latest.js' + ] + }, + { title: 'Fleets', files: [ 'build/commands/fleets/index.js' ] }, + { + title: 'Help and Version', + files: [ 'build/commands/help/version.js' ] + }, + { + title: 'Local', + files: [ + 'build/commands/local/configure.js', + 'build/commands/local/flash.js' + ] + }, + { title: 'Logs', files: [ 'build/commands/logs/index.js' ] }, + { + title: 'Network', + files: [ + 'build/commands/network/scan.js', + 'build/commands/network/ssh.js', + 'build/commands/network/tunnel.js' + ] + }, + { title: 'Notes', files: [ 'build/commands/notes/index.js' ] }, + { title: 'Organizations', files: [ 'build/commands/orgs/index.js' ] }, + { + title: 'OS', + files: [ + 'build/commands/os/build-config.js', + 'build/commands/os/configure.js', + 'build/commands/os/download.js', + 'build/commands/os/initialize.js', + 'build/commands/os/versions.js' + ] + }, + { + title: 'Platform', + files: [ + 'build/commands/platform/join.js', + 'build/commands/platform/leave.js' + ] + }, + { title: 'Preload', files: [ 'build/commands/preload/index.js' ] }, + { title: 'Push', files: [ 'build/commands/push/index.js' ] }, + { + title: 'Release', + files: [ + 'build/commands/release/finalize.js', + 'build/commands/release/index.js', + 'build/commands/release/invalidate.js', + 'build/commands/release/validate.js' + ] + }, + { title: 'Releases', files: [ 'build/commands/releases/index.js' ] }, + { title: 'Settings', files: [ 'build/commands/settings/index.js' ] }, + { + title: 'SSH Key', + files: [ + 'build/commands/key/add.js', + 'build/commands/key/index.js', + 'build/commands/key/rm.js' + ] + }, + { title: 'SSH Keys', files: [ 'build/commands/keys/index.js' ] }, + { title: 'Support', files: [ 'build/commands/support/support.js' ] }, + { + title: 'Tag', + files: [ 'build/commands/tag/rm.js', 'build/commands/tag/set.js' ] + }, + { title: 'Tags', files: [ 'build/commands/tags/index.js' ] }, + { + title: 'Utilities', + files: [ 'build/commands/util/available-drives.js' ] + } +] # balena CLI Documentation The balena CLI is a Command Line Interface for [balenaCloud](https://www.balena.io/cloud/) or @@ -162,12 +327,12 @@ are encouraged to regularly update the balena CLI to the latest version. - API Key - - [api-keys](#api-keys) + - [api-key generate <name>](#api-key-generate-name) + - [api-key revoke <ids>](#api-key-revoke-ids) - API Keys - - [api-key generate <name>](#api-key-generate-name) - - [api-key revoke <ids>](#api-key-revoke-ids) + - [api-keys](#api-keys) - App @@ -181,7 +346,7 @@ are encouraged to regularly update the balena CLI to the latest version. - Block - - [app create <name>](#app-create-name) + - [block create <name>](#block-create-name) - Config @@ -214,9 +379,9 @@ are encouraged to regularly update the balena CLI to the latest version. - [device restart <uuid>](#device-restart-uuid) - [device rm <uuid(s)>](#device-rm-uuid-s) - [device shutdown <uuid>](#device-shutdown-uuid) - - [device track-fleet <uuid>](#device-track-fleet-uuid) - [device start-service <uuid>](#device-start-service-uuid) - [device stop-service <uuid>](#device-stop-service-uuid) + - [device track-fleet <uuid>](#device-track-fleet-uuid) - Devices @@ -250,7 +415,6 @@ are encouraged to regularly update the balena CLI to the latest version. - Help and Version - - [help [command]](#help-command) - [version](#version) - Local @@ -284,6 +448,11 @@ are encouraged to regularly update the balena CLI to the latest version. - [os configure <image>](#os-configure-image) - [os initialize <image>](#os-initialize-image) +- Platform + + - [join [deviceiporhostname]](#join-deviceiporhostname) + - [leave [deviceiporhostname]](#leave-deviceiporhostname) + - Preload - [preload <image>](#preload-image) @@ -292,11 +461,6 @@ are encouraged to regularly update the balena CLI to the latest version. - [push <fleetordevice>](#push-fleetordevice) -- Platform - - - [join [deviceiporhostname]](#join-deviceiporhostname) - - [leave [deviceiporhostname]](#leave-deviceiporhostname) - - Release - [release finalize <commitorid>](#release-finalize-commitorid) @@ -312,10 +476,6 @@ are encouraged to regularly update the balena CLI to the latest version. - [settings](#settings) -- Support - - - [support <action>](#support-action) - - SSH Key - [key add <name> [path]](#key-add-name-path) @@ -326,7 +486,11 @@ are encouraged to regularly update the balena CLI to the latest version. - [keys](#keys) -- Tags +- Support + + - [support <action>](#support-action) + +- Tag - [tag rm <tagkey>](#tag-rm-tagkey) - [tag set <tagkey> [value]](#tag-set-tagkey-value) @@ -341,28 +505,6 @@ are encouraged to regularly update the balena CLI to the latest version. # API Key -## api-keys - -Print a list of balenaCloud API keys. - -Print a list of balenaCloud API keys for the current user or for a specific fleet with the `--fleet` option. - -Examples: - - $ balena api-keys - -### Options - -#### -u, --user - -show API keys for your user - -#### -f, --fleet FLEET - -fleet name or slug (preferred) - -# API Keys - ## api-key generate <name> Generate a new balenaCloud API key for the current user, with the given @@ -403,6 +545,28 @@ the API key ids ### Options +# API Keys + +## api-keys + +Print a list of balenaCloud API keys. + +Print a list of balenaCloud API keys for the current user or for a specific fleet with the `--fleet` option. + +Examples: + + $ balena api-keys + +### Options + +#### -u, --user + +show API keys for your user + +#### -f, --fleet FLEET + +fleet name or slug (preferred) + # App ## app create <name> @@ -527,16 +691,16 @@ Examples: # Block -## app create <name> +## block create <name> -Create a new balena app. +Create a new balena block. -You can specify the organization the app should belong to using +You can specify the organization the block should belong to using the `--organization` option. The organization's handle, not its name, should be provided. Organization handles can be listed with the `balena orgs` command. -The app's default device type is specified with the `--type` option. +The block's default device type is specified with the `--type` option. The `balena devices supported` command can be used to list the available device types. @@ -548,25 +712,25 @@ type and organization. Examples: - $ balena app create MyApp - $ balena app create MyApp --organization mmyorg - $ balena app create MyApp -o myorg --type raspberry-pi + $ balena block create MyBlock + $ balena block create MyBlock --organization mmyorg + $ balena block create MyBlock -o myorg --type raspberry-pi ### Arguments #### NAME -app name +block name ### Options #### -o, --organization ORGANIZATION -handle of the organization the app should belong to +handle of the organization the block should belong to #### -t, --type TYPE -app device type (Check available types with `balena devices supported`) +block device type (Check available types with `balena devices supported`) # Config @@ -1706,22 +1870,6 @@ the uuid of the device to shutdown force action if the update lock is set -## device track-fleet <uuid> - -Make a device track the fleet's pinned release. - -Examples: - - $ balena device track-fleet 7cf02a6 - -### Arguments - -#### UUID - -the uuid of the device to make track the fleet's release - -### Options - ## device start-service <uuid> Start containers on a device. @@ -1770,6 +1918,22 @@ comma-separated list (no blank spaces) of service names ### Options +## device track-fleet <uuid> + +Make a device track the fleet's pinned release. + +Examples: + + $ balena device track-fleet 7cf02a6 + +### Arguments + +#### UUID + +the uuid of the device to make track the fleet's release + +### Options + # Devices ## devices @@ -2403,28 +2567,6 @@ field to sort by (prepend '-' for descending order) # Help and Version -## help [command] - -List balena commands, or get detailed help for a specific command. - -Examples: - - $ balena help - $ balena help login - $ balena help os download - -### Arguments - -#### COMMAND - -command to show help for - -### Options - -#### --v, --verbose - -show additional commands - ## version Display version information for the balena CLI and/or Node.js. Note that the @@ -3033,6 +3175,87 @@ Check `balena util available-drives` for available options. answer "yes" to all questions (non interactive use) +# Platform + +## join [deviceIpOrHostname] + +Move a local device to a fleet on another balena server, causing +the device to "join" the new server. The device must be running balenaOS. + +For example, you could provision a device against an openBalena installation +where you perform end-to-end tests and then move it to balenaCloud when it's +ready for production. + +To move a device between fleets on the same server, use the +`balena device move` command instead of `balena join`. + +If you don't specify a device hostname or IP, this command will automatically +scan the local network for balenaOS devices and prompt you to select one +from an interactive picker. This may require administrator/root privileges. +Likewise, if the fleet option is not provided then a picker will be shown. + +Fleets may be specified by fleet name or slug. Fleet slugs are +the recommended option, as they are unique and unambiguous. Slugs can be +listed with the `balena fleets` command. Note that slugs may change if the +fleet is renamed. Fleet names are not unique and may result in "Fleet is +ambiguous" errors at any time (even if it "used to work in the past"), for +example if the name clashes with a newly created public fleet, or with fleets +from other balena accounts that you may be invited to join under any role. +For this reason, fleet names are especially discouraged in scripts (e.g. CI +environments). + +Examples: + + $ balena join + $ balena join balena.local + $ balena join balena.local --fleet MyFleet + $ balena join balena.local -f myorg/myfleet + $ balena join 192.168.1.25 + $ balena join 192.168.1.25 --fleet MyFleet + +### Arguments + +#### DEVICEIPORHOSTNAME + +the IP or hostname of device + +### Options + +#### -f, --fleet FLEET + +fleet name or slug (preferred) + +#### -i, --pollInterval POLLINTERVAL + +the interval in minutes to check for updates + +## leave [deviceIpOrHostname] + +Remove a local device from its balena fleet, causing the device to +"leave" the server it is provisioned on. This effectively makes the device +"unmanaged". The device must be running balenaOS. + +The device entry on the server is preserved after running this command, +so the device can subsequently re-join the server if needed. + +If you don't specify a device hostname or IP, this command will automatically +scan the local network for balenaOS devices and prompt you to select one +from an interactive picker. This may require administrator/root privileges. + +Examples: + + $ balena leave + $ balena leave balena.local + $ balena leave 192.168.1.25 + +### Arguments + +#### DEVICEIPORHOSTNAME + +the device IP or hostname + +### Options + # Preload ## preload <image> @@ -3368,87 +3591,6 @@ as final by default unless this option is given. The notes for this release -# Platform - -## join [deviceIpOrHostname] - -Move a local device to a fleet on another balena server, causing -the device to "join" the new server. The device must be running balenaOS. - -For example, you could provision a device against an openBalena installation -where you perform end-to-end tests and then move it to balenaCloud when it's -ready for production. - -To move a device between fleets on the same server, use the -`balena device move` command instead of `balena join`. - -If you don't specify a device hostname or IP, this command will automatically -scan the local network for balenaOS devices and prompt you to select one -from an interactive picker. This may require administrator/root privileges. -Likewise, if the fleet option is not provided then a picker will be shown. - -Fleets may be specified by fleet name or slug. Fleet slugs are -the recommended option, as they are unique and unambiguous. Slugs can be -listed with the `balena fleets` command. Note that slugs may change if the -fleet is renamed. Fleet names are not unique and may result in "Fleet is -ambiguous" errors at any time (even if it "used to work in the past"), for -example if the name clashes with a newly created public fleet, or with fleets -from other balena accounts that you may be invited to join under any role. -For this reason, fleet names are especially discouraged in scripts (e.g. CI -environments). - -Examples: - - $ balena join - $ balena join balena.local - $ balena join balena.local --fleet MyFleet - $ balena join balena.local -f myorg/myfleet - $ balena join 192.168.1.25 - $ balena join 192.168.1.25 --fleet MyFleet - -### Arguments - -#### DEVICEIPORHOSTNAME - -the IP or hostname of device - -### Options - -#### -f, --fleet FLEET - -fleet name or slug (preferred) - -#### -i, --pollInterval POLLINTERVAL - -the interval in minutes to check for updates - -## leave [deviceIpOrHostname] - -Remove a local device from its balena fleet, causing the device to -"leave" the server it is provisioned on. This effectively makes the device -"unmanaged". The device must be running balenaOS. - -The device entry on the server is preserved after running this command, -so the device can subsequently re-join the server if needed. - -If you don't specify a device hostname or IP, this command will automatically -scan the local network for balenaOS devices and prompt you to select one -from an interactive picker. This may require administrator/root privileges. - -Examples: - - $ balena leave - $ balena leave balena.local - $ balena leave 192.168.1.25 - -### Arguments - -#### DEVICEIPORHOSTNAME - -the device IP or hostname - -### Options - # Release ## release finalize <commitOrId> @@ -3598,56 +3740,6 @@ Examples: ### Options -# Support - -## support <action> - -Grant or revoke balena support agent access to devices or fleets -on balenaCloud. (This command does not apply to openBalena.) -Access will be automatically revoked once the specified duration has elapsed. - -Duration defaults to 24h, but can be specified using --duration flag in days -or hours, e.g. '12h', '2d'. - -Both --device and --fleet flags accept multiple values, specified as -a comma-separated list (with no spaces). - -Fleets may be specified by fleet name or slug. Fleet slugs are -the recommended option, as they are unique and unambiguous. Slugs can be -listed with the `balena fleets` command. Note that slugs may change if the -fleet is renamed. Fleet names are not unique and may result in "Fleet is -ambiguous" errors at any time (even if it "used to work in the past"), for -example if the name clashes with a newly created public fleet, or with fleets -from other balena accounts that you may be invited to join under any role. -For this reason, fleet names are especially discouraged in scripts (e.g. CI -environments). - -Examples: - - balena support enable --device ab346f,cd457a --duration 3d - balena support enable --fleet myFleet --duration 12h - balena support disable -f myorg/myfleet - -### Arguments - -#### ACTION - -enable|disable support access - -### Options - -#### -d, --device DEVICE - -comma-separated list (no spaces) of device UUIDs - -#### -f, --fleet FLEET - -comma-separated list (no spaces) of fleet names or slugs (preferred) - -#### -t, --duration DURATION - -length of time to enable support for, in (h)ours or (d)ays, e.g. 12h, 2d - # SSH Key ## key add <name> [path] @@ -3740,7 +3832,57 @@ Examples: ### Options -# Tags +# Support + +## support <action> + +Grant or revoke balena support agent access to devices or fleets +on balenaCloud. (This command does not apply to openBalena.) +Access will be automatically revoked once the specified duration has elapsed. + +Duration defaults to 24h, but can be specified using --duration flag in days +or hours, e.g. '12h', '2d'. + +Both --device and --fleet flags accept multiple values, specified as +a comma-separated list (with no spaces). + +Fleets may be specified by fleet name or slug. Fleet slugs are +the recommended option, as they are unique and unambiguous. Slugs can be +listed with the `balena fleets` command. Note that slugs may change if the +fleet is renamed. Fleet names are not unique and may result in "Fleet is +ambiguous" errors at any time (even if it "used to work in the past"), for +example if the name clashes with a newly created public fleet, or with fleets +from other balena accounts that you may be invited to join under any role. +For this reason, fleet names are especially discouraged in scripts (e.g. CI +environments). + +Examples: + + balena support enable --device ab346f,cd457a --duration 3d + balena support enable --fleet myFleet --duration 12h + balena support disable -f myorg/myfleet + +### Arguments + +#### ACTION + +enable|disable support access + +### Options + +#### -d, --device DEVICE + +comma-separated list (no spaces) of device UUIDs + +#### -f, --fleet FLEET + +comma-separated list (no spaces) of fleet names or slugs (preferred) + +#### -t, --duration DURATION + +length of time to enable support for, in (h)ours or (d)ays, e.g. 12h, 2d + +# Tag ## tag rm <tagKey> From fc0cfac475bfa3a1ff570bd2149763f0889ff498 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 8 Nov 2023 19:52:40 +0530 Subject: [PATCH 05/10] Docs: Create version command directory Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/build-bin.ts | 2 +- lib/commands/support/{support.ts => index.ts} | 0 lib/commands/{help/version.ts => version/index.ts} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename lib/commands/support/{support.ts => index.ts} (100%) rename lib/commands/{help/version.ts => version/index.ts} (100%) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index 7c83bf1f..69cde586 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import type { JsonVersions } from '../lib/commands/help/version'; +import type { JsonVersions } from '../lib/commands/version/index' import { run as oclifRun } from '@oclif/core'; import * as archiver from 'archiver'; diff --git a/lib/commands/support/support.ts b/lib/commands/support/index.ts similarity index 100% rename from lib/commands/support/support.ts rename to lib/commands/support/index.ts diff --git a/lib/commands/help/version.ts b/lib/commands/version/index.ts similarity index 100% rename from lib/commands/help/version.ts rename to lib/commands/version/index.ts From d9427c3c59882168e2bacc1cd086a1f2bc9dc213 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 8 Nov 2023 20:14:32 +0530 Subject: [PATCH 06/10] Docs: Generate balenaCLI with automatic configuration Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/build-bin.ts | 2 +- automation/capitanodoc/capitanodoc.ts | 7 +- completion/_balena | 10 +- completion/balena-completion.bash | 10 +- docs/balena-cli.md | 243 +++++--------------------- 5 files changed, 44 insertions(+), 228 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index 69cde586..044c5709 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import type { JsonVersions } from '../lib/commands/version/index' +import type { JsonVersions } from '../lib/commands/version/index'; import { run as oclifRun } from '@oclif/core'; import * as archiver from 'archiver'; diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index b5cb5571..b4b4f39f 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -73,7 +73,6 @@ const allCommandsPaths = new GlobSync('build/commands/**/*.js', { }).found; // Throw error if any commands found outside of command directories -// const illegalCommandPaths = allCommandsPaths.filter((commandPath: string) => /^build\/commands\/[^/]+\.js$/.test(commandPath), ); @@ -113,18 +112,16 @@ for (const commandPath of allCommandsPaths) { categoriesMap[heading].files.push(commandPath); } -// Sort Category titles alhpabetically +// Sort Category titles alphabetically capitanoDoc.categories = capitanoDoc.categories.sort((a, b) => a.title.localeCompare(b.title), ); -// Sort Category file paths alhpabetically +// Sort Category file paths alphabetically capitanoDoc.categories.forEach((category) => { category.files.sort((a, b) => a.localeCompare(b)); }); -console.log(capitanoDoc.categories); - /** * Modify and return the `capitanoDoc` object above in order to generate the * CLI documentation at docs/balena-cli.md diff --git a/completion/_balena b/completion/_balena index d93c59c3..3a9d6b40 100644 --- a/completion/_balena +++ b/completion/_balena @@ -8,7 +8,7 @@ _balena() { local context state line curcontext="$curcontext" # Valid top-level completions - main_commands=( api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets help internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util ) + main_commands=( api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util version ) # Sub-completions api_key_cmds=( generate revoke ) app_cmds=( create ) @@ -20,7 +20,6 @@ _balena() { devices_cmds=( supported ) env_cmds=( add rename rm ) fleet_cmds=( create pin purge rename restart rm track-latest ) - help_cmds=( version ) internal_cmds=( osinit ) key_cmds=( add rm ) local_cmds=( configure flash ) @@ -28,7 +27,6 @@ _balena() { os_cmds=( build-config configure download initialize versions ) platform_cmds=( join leave ) release_cmds=( finalize invalidate validate ) - support_cmds=( support ) tag_cmds=( rm set ) @@ -78,9 +76,6 @@ _balena_sec_cmds() { "fleet") _describe -t fleet_cmds 'fleet_cmd' fleet_cmds "$@" && ret=0 ;; - "help") - _describe -t help_cmds 'help_cmd' help_cmds "$@" && ret=0 - ;; "internal") _describe -t internal_cmds 'internal_cmd' internal_cmds "$@" && ret=0 ;; @@ -102,9 +97,6 @@ _balena_sec_cmds() { "release") _describe -t release_cmds 'release_cmd' release_cmds "$@" && ret=0 ;; - "support") - _describe -t support_cmds 'support_cmd' support_cmds "$@" && ret=0 - ;; "tag") _describe -t tag_cmds 'tag_cmd' tag_cmds "$@" && ret=0 ;; diff --git a/completion/balena-completion.bash b/completion/balena-completion.bash index b2802dcf..eee0311a 100644 --- a/completion/balena-completion.bash +++ b/completion/balena-completion.bash @@ -7,7 +7,7 @@ _balena_complete() local cur prev # Valid top-level completions - main_commands="api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets help internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util" + main_commands="api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util version" # Sub-completions api_key_cmds="generate revoke" app_cmds="create" @@ -19,7 +19,6 @@ _balena_complete() devices_cmds="supported" env_cmds="add rename rm" fleet_cmds="create pin purge rename restart rm track-latest" - help_cmds="version" internal_cmds="osinit" key_cmds="add rm" local_cmds="configure flash" @@ -27,7 +26,6 @@ _balena_complete() os_cmds="build-config configure download initialize versions" platform_cmds="join leave" release_cmds="finalize invalidate validate" - support_cmds="support" tag_cmds="rm set" @@ -72,9 +70,6 @@ _balena_complete() fleet) COMPREPLY=( $(compgen -W "$fleet_cmds" -- $cur) ) ;; - help) - COMPREPLY=( $(compgen -W "$help_cmds" -- $cur) ) - ;; internal) COMPREPLY=( $(compgen -W "$internal_cmds" -- $cur) ) ;; @@ -96,9 +91,6 @@ _balena_complete() release) COMPREPLY=( $(compgen -W "$release_cmds" -- $cur) ) ;; - support) - COMPREPLY=( $(compgen -W "$support_cmds" -- $cur) ) - ;; tag) COMPREPLY=( $(compgen -W "$tag_cmds" -- $cur) ) ;; diff --git a/docs/balena-cli.md b/docs/balena-cli.md index 3502e1ff..4c897a7e 100644 --- a/docs/balena-cli.md +++ b/docs/balena-cli.md @@ -1,168 +1,3 @@ -[ - { - title: 'API Key', - files: [ - 'build/commands/api-key/generate.js', - 'build/commands/api-key/revoke.js' - ] - }, - { title: 'API Keys', files: [ 'build/commands/api-keys/index.js' ] }, - { title: 'App', files: [ 'build/commands/app/create.js' ] }, - { - title: 'Authentication', - files: [ - 'build/commands/auth/login.js', - 'build/commands/auth/logout.js', - 'build/commands/auth/whoami.js' - ] - }, - { title: 'Block', files: [ 'build/commands/block/create.js' ] }, - { - title: 'Config', - files: [ - 'build/commands/config/generate.js', - 'build/commands/config/inject.js', - 'build/commands/config/read.js', - 'build/commands/config/reconfigure.js', - 'build/commands/config/write.js' - ] - }, - { - title: 'Deploy', - files: [ - 'build/commands/deploy/build.js', - 'build/commands/deploy/index.js' - ] - }, - { - title: 'Device', - files: [ - 'build/commands/device/deactivate.js', - 'build/commands/device/identify.js', - 'build/commands/device/index.js', - 'build/commands/device/init.js', - 'build/commands/device/local-mode.js', - 'build/commands/device/move.js', - 'build/commands/device/os-update.js', - 'build/commands/device/pin.js', - 'build/commands/device/public-url.js', - 'build/commands/device/purge.js', - 'build/commands/device/reboot.js', - 'build/commands/device/register.js', - 'build/commands/device/rename.js', - 'build/commands/device/restart.js', - 'build/commands/device/rm.js', - 'build/commands/device/shutdown.js', - 'build/commands/device/start-service.js', - 'build/commands/device/stop-service.js', - 'build/commands/device/track-fleet.js' - ] - }, - { - title: 'Devices', - files: [ - 'build/commands/devices/index.js', - 'build/commands/devices/supported.js' - ] - }, - { - title: 'Environment Variable', - files: [ - 'build/commands/env/add.js', - 'build/commands/env/rename.js', - 'build/commands/env/rm.js' - ] - }, - { - title: 'Environment Variables', - files: [ 'build/commands/envs/index.js' ] - }, - { - title: 'Fleet', - files: [ - 'build/commands/fleet/create.js', - 'build/commands/fleet/index.js', - 'build/commands/fleet/pin.js', - 'build/commands/fleet/purge.js', - 'build/commands/fleet/rename.js', - 'build/commands/fleet/restart.js', - 'build/commands/fleet/rm.js', - 'build/commands/fleet/track-latest.js' - ] - }, - { title: 'Fleets', files: [ 'build/commands/fleets/index.js' ] }, - { - title: 'Help and Version', - files: [ 'build/commands/help/version.js' ] - }, - { - title: 'Local', - files: [ - 'build/commands/local/configure.js', - 'build/commands/local/flash.js' - ] - }, - { title: 'Logs', files: [ 'build/commands/logs/index.js' ] }, - { - title: 'Network', - files: [ - 'build/commands/network/scan.js', - 'build/commands/network/ssh.js', - 'build/commands/network/tunnel.js' - ] - }, - { title: 'Notes', files: [ 'build/commands/notes/index.js' ] }, - { title: 'Organizations', files: [ 'build/commands/orgs/index.js' ] }, - { - title: 'OS', - files: [ - 'build/commands/os/build-config.js', - 'build/commands/os/configure.js', - 'build/commands/os/download.js', - 'build/commands/os/initialize.js', - 'build/commands/os/versions.js' - ] - }, - { - title: 'Platform', - files: [ - 'build/commands/platform/join.js', - 'build/commands/platform/leave.js' - ] - }, - { title: 'Preload', files: [ 'build/commands/preload/index.js' ] }, - { title: 'Push', files: [ 'build/commands/push/index.js' ] }, - { - title: 'Release', - files: [ - 'build/commands/release/finalize.js', - 'build/commands/release/index.js', - 'build/commands/release/invalidate.js', - 'build/commands/release/validate.js' - ] - }, - { title: 'Releases', files: [ 'build/commands/releases/index.js' ] }, - { title: 'Settings', files: [ 'build/commands/settings/index.js' ] }, - { - title: 'SSH Key', - files: [ - 'build/commands/key/add.js', - 'build/commands/key/index.js', - 'build/commands/key/rm.js' - ] - }, - { title: 'SSH Keys', files: [ 'build/commands/keys/index.js' ] }, - { title: 'Support', files: [ 'build/commands/support/support.js' ] }, - { - title: 'Tag', - files: [ 'build/commands/tag/rm.js', 'build/commands/tag/set.js' ] - }, - { title: 'Tags', files: [ 'build/commands/tags/index.js' ] }, - { - title: 'Utilities', - files: [ 'build/commands/util/available-drives.js' ] - } -] # balena CLI Documentation The balena CLI is a Command Line Interface for [balenaCloud](https://www.balena.io/cloud/) or @@ -413,10 +248,6 @@ are encouraged to regularly update the balena CLI to the latest version. - [fleets](#fleets) -- Help and Version - - - [version](#version) - - Local - [local configure <target>](#local-configure-target) @@ -503,6 +334,10 @@ are encouraged to regularly update the balena CLI to the latest version. - [util available-drives](#util-available-drives) +- Version + + - [version](#version) + # API Key ## api-key generate <name> @@ -2565,41 +2400,6 @@ do not truncate output to fit screen field to sort by (prepend '-' for descending order) -# Help and Version - -## version - -Display version information for the balena CLI and/or Node.js. Note that the -balena CLI executable installers for Windows and macOS, and the standalone -zip packages, ship with a built-in copy of Node.js. In this case, the -reported version of Node.js regards this built-in copy, rather than any -other `node` engine that may also be available on the command prompt. - -The --json option is recommended when scripting the output of this command, -because the JSON format is less likely to change and it better represents -data types like lists and empty strings. The 'jq' utility may be helpful -in shell scripts (https://stedolan.github.io/jq/manual/). - -This command can also be invoked with 'balena --version' or 'balena -v'. - -Examples: - - $ balena version - $ balena version -a - $ balena version -j - $ balena --version - $ balena -v - -### Options - -#### -a, --all - -include version information for additional components (Node.js) - -#### -j, --json - -output version information in JSON format for programmatic use - # Local ## local configure <target> @@ -4025,3 +3825,38 @@ List available drives which are usable for writing an OS image to. Does not list system drives. ### Options + +# Version + +## version + +Display version information for the balena CLI and/or Node.js. Note that the +balena CLI executable installers for Windows and macOS, and the standalone +zip packages, ship with a built-in copy of Node.js. In this case, the +reported version of Node.js regards this built-in copy, rather than any +other `node` engine that may also be available on the command prompt. + +The --json option is recommended when scripting the output of this command, +because the JSON format is less likely to change and it better represents +data types like lists and empty strings. The 'jq' utility may be helpful +in shell scripts (https://stedolan.github.io/jq/manual/). + +This command can also be invoked with 'balena --version' or 'balena -v'. + +Examples: + + $ balena version + $ balena version -a + $ balena version -j + $ balena --version + $ balena -v + +### Options + +#### -a, --all + +include version information for additional components (Node.js) + +#### -j, --json + +output version information in JSON format for programmatic use From 2de9d526e53c09fc7f2d3a6989020b07b653a324 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Fri, 10 Nov 2023 01:44:27 +0530 Subject: [PATCH 07/10] Docs: Move commands to their own directories, away from their categories Signed-off-by: Vipul Gupta (@vipulgupta2048) --- lib/commands/{deploy/build.ts => build/index.ts} | 0 lib/commands/{platform/join.ts => join/index.ts} | 0 lib/commands/{platform/leave.ts => leave/index.ts} | 0 lib/commands/{network/scan.ts => scan/index.ts} | 0 lib/commands/{network/ssh.ts => ssh/index.ts} | 0 lib/commands/{network/tunnel.ts => tunnel/index.ts} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename lib/commands/{deploy/build.ts => build/index.ts} (100%) rename lib/commands/{platform/join.ts => join/index.ts} (100%) rename lib/commands/{platform/leave.ts => leave/index.ts} (100%) rename lib/commands/{network/scan.ts => scan/index.ts} (100%) rename lib/commands/{network/ssh.ts => ssh/index.ts} (100%) rename lib/commands/{network/tunnel.ts => tunnel/index.ts} (100%) diff --git a/lib/commands/deploy/build.ts b/lib/commands/build/index.ts similarity index 100% rename from lib/commands/deploy/build.ts rename to lib/commands/build/index.ts diff --git a/lib/commands/platform/join.ts b/lib/commands/join/index.ts similarity index 100% rename from lib/commands/platform/join.ts rename to lib/commands/join/index.ts diff --git a/lib/commands/platform/leave.ts b/lib/commands/leave/index.ts similarity index 100% rename from lib/commands/platform/leave.ts rename to lib/commands/leave/index.ts diff --git a/lib/commands/network/scan.ts b/lib/commands/scan/index.ts similarity index 100% rename from lib/commands/network/scan.ts rename to lib/commands/scan/index.ts diff --git a/lib/commands/network/ssh.ts b/lib/commands/ssh/index.ts similarity index 100% rename from lib/commands/network/ssh.ts rename to lib/commands/ssh/index.ts diff --git a/lib/commands/network/tunnel.ts b/lib/commands/tunnel/index.ts similarity index 100% rename from lib/commands/network/tunnel.ts rename to lib/commands/tunnel/index.ts From 4cd8f4c16ec5ce80154fbe43c11f5b89cbc74987 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Fri, 10 Nov 2023 01:45:29 +0530 Subject: [PATCH 08/10] Docs: Generate balena auto-completion Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/capitanodoc/capitanodoc.ts | 6 ++++++ completion/_balena | 14 +------------- completion/balena-completion.bash | 14 +------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index b4b4f39f..6c5cf6b8 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -65,6 +65,12 @@ const commandHeadings: { [key: string]: string } = { orgs: 'Organizations', os: 'OS', util: 'Utilities', + ssh: 'Network', + scan: 'Network', + tunnel: 'Network', + build: 'Deploy', + join: 'Platform', + leave: 'Platform', }; // Fetch all available commands diff --git a/completion/_balena b/completion/_balena index 3a9d6b40..317c5f5b 100644 --- a/completion/_balena +++ b/completion/_balena @@ -8,14 +8,13 @@ _balena() { local context state line curcontext="$curcontext" # Valid top-level completions - main_commands=( api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util version ) + main_commands=( api-key api-keys app auth block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version ) # Sub-completions api_key_cmds=( generate revoke ) app_cmds=( create ) auth_cmds=( login logout whoami ) block_cmds=( create ) config_cmds=( generate inject read reconfigure write ) - deploy_cmds=( build ) device_cmds=( deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet ) devices_cmds=( supported ) env_cmds=( add rename rm ) @@ -23,9 +22,7 @@ _balena() { internal_cmds=( osinit ) key_cmds=( add rm ) local_cmds=( configure flash ) - network_cmds=( scan ssh tunnel ) os_cmds=( build-config configure download initialize versions ) - platform_cmds=( join leave ) release_cmds=( finalize invalidate validate ) tag_cmds=( rm set ) @@ -61,9 +58,6 @@ _balena_sec_cmds() { "config") _describe -t config_cmds 'config_cmd' config_cmds "$@" && ret=0 ;; - "deploy") - _describe -t deploy_cmds 'deploy_cmd' deploy_cmds "$@" && ret=0 - ;; "device") _describe -t device_cmds 'device_cmd' device_cmds "$@" && ret=0 ;; @@ -85,15 +79,9 @@ _balena_sec_cmds() { "local") _describe -t local_cmds 'local_cmd' local_cmds "$@" && ret=0 ;; - "network") - _describe -t network_cmds 'network_cmd' network_cmds "$@" && ret=0 - ;; "os") _describe -t os_cmds 'os_cmd' os_cmds "$@" && ret=0 ;; - "platform") - _describe -t platform_cmds 'platform_cmd' platform_cmds "$@" && ret=0 - ;; "release") _describe -t release_cmds 'release_cmd' release_cmds "$@" && ret=0 ;; diff --git a/completion/balena-completion.bash b/completion/balena-completion.bash index eee0311a..6dfcf37f 100644 --- a/completion/balena-completion.bash +++ b/completion/balena-completion.bash @@ -7,14 +7,13 @@ _balena_complete() local cur prev # Valid top-level completions - main_commands="api-key api-keys app auth block config deploy deploy device device devices env envs fleet fleet fleets internal key key keys local logs network notes orgs os platform preload push release release releases settings support tag tags util version" + main_commands="api-key api-keys app auth block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version" # Sub-completions api_key_cmds="generate revoke" app_cmds="create" auth_cmds="login logout whoami" block_cmds="create" config_cmds="generate inject read reconfigure write" - deploy_cmds="build" device_cmds="deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet" devices_cmds="supported" env_cmds="add rename rm" @@ -22,9 +21,7 @@ _balena_complete() internal_cmds="osinit" key_cmds="add rm" local_cmds="configure flash" - network_cmds="scan ssh tunnel" os_cmds="build-config configure download initialize versions" - platform_cmds="join leave" release_cmds="finalize invalidate validate" tag_cmds="rm set" @@ -55,9 +52,6 @@ _balena_complete() config) COMPREPLY=( $(compgen -W "$config_cmds" -- $cur) ) ;; - deploy) - COMPREPLY=( $(compgen -W "$deploy_cmds" -- $cur) ) - ;; device) COMPREPLY=( $(compgen -W "$device_cmds" -- $cur) ) ;; @@ -79,15 +73,9 @@ _balena_complete() local) COMPREPLY=( $(compgen -W "$local_cmds" -- $cur) ) ;; - network) - COMPREPLY=( $(compgen -W "$network_cmds" -- $cur) ) - ;; os) COMPREPLY=( $(compgen -W "$os_cmds" -- $cur) ) ;; - platform) - COMPREPLY=( $(compgen -W "$platform_cmds" -- $cur) ) - ;; release) COMPREPLY=( $(compgen -W "$release_cmds" -- $cur) ) ;; From 1a4a0e2439bac9e9720a613f6281f2f1eee7a2e0 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 15 Nov 2023 15:10:22 +0530 Subject: [PATCH 09/10] Move auth commands into command directories Signed-off-by: Vipul Gupta (@vipulgupta2048) --- lib/commands/{auth/login.ts => login/index.ts} | 0 lib/commands/{auth/logout.ts => logout/index.ts} | 0 lib/commands/{auth/whoami.ts => whoami/index.ts} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename lib/commands/{auth/login.ts => login/index.ts} (100%) rename lib/commands/{auth/logout.ts => logout/index.ts} (100%) rename lib/commands/{auth/whoami.ts => whoami/index.ts} (100%) diff --git a/lib/commands/auth/login.ts b/lib/commands/login/index.ts similarity index 100% rename from lib/commands/auth/login.ts rename to lib/commands/login/index.ts diff --git a/lib/commands/auth/logout.ts b/lib/commands/logout/index.ts similarity index 100% rename from lib/commands/auth/logout.ts rename to lib/commands/logout/index.ts diff --git a/lib/commands/auth/whoami.ts b/lib/commands/whoami/index.ts similarity index 100% rename from lib/commands/auth/whoami.ts rename to lib/commands/whoami/index.ts From b393f27e1b1f860bc0e1cd42aecd1b8c87870c03 Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Wed, 15 Nov 2023 15:11:17 +0530 Subject: [PATCH 10/10] Remove authentication directory Signed-off-by: Vipul Gupta (@vipulgupta2048) --- automation/capitanodoc/capitanodoc.ts | 4 +++- completion/_balena | 6 +----- completion/balena-completion.bash | 6 +----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 6c5cf6b8..f46ad274 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -56,7 +56,9 @@ interface Documentation { const commandHeadings: { [key: string]: string } = { 'api-key': 'API Key', 'api-keys': 'API Keys', - auth: 'Authentication', + login: 'Authentication', + whoami: 'Authentication', + logout: 'Authentication', env: 'Environment Variable', envs: 'Environment Variables', help: 'Help and Version', diff --git a/completion/_balena b/completion/_balena index 317c5f5b..0fb31492 100644 --- a/completion/_balena +++ b/completion/_balena @@ -8,11 +8,10 @@ _balena() { local context state line curcontext="$curcontext" # Valid top-level completions - main_commands=( api-key api-keys app auth block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version ) + main_commands=( api-key api-keys app block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local login logout logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version whoami ) # Sub-completions api_key_cmds=( generate revoke ) app_cmds=( create ) - auth_cmds=( login logout whoami ) block_cmds=( create ) config_cmds=( generate inject read reconfigure write ) device_cmds=( deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet ) @@ -49,9 +48,6 @@ _balena_sec_cmds() { "app") _describe -t app_cmds 'app_cmd' app_cmds "$@" && ret=0 ;; - "auth") - _describe -t auth_cmds 'auth_cmd' auth_cmds "$@" && ret=0 - ;; "block") _describe -t block_cmds 'block_cmd' block_cmds "$@" && ret=0 ;; diff --git a/completion/balena-completion.bash b/completion/balena-completion.bash index 6dfcf37f..82185b40 100644 --- a/completion/balena-completion.bash +++ b/completion/balena-completion.bash @@ -7,11 +7,10 @@ _balena_complete() local cur prev # Valid top-level completions - main_commands="api-key api-keys app auth block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version" + main_commands="api-key api-keys app block build config deploy device device devices env envs fleet fleet fleets internal join key key keys leave local login logout logs notes orgs os preload push release release releases scan settings ssh support tag tags tunnel util version whoami" # Sub-completions api_key_cmds="generate revoke" app_cmds="create" - auth_cmds="login logout whoami" block_cmds="create" config_cmds="generate inject read reconfigure write" device_cmds="deactivate identify init local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet" @@ -43,9 +42,6 @@ _balena_complete() app) COMPREPLY=( $(compgen -W "$app_cmds" -- $cur) ) ;; - auth) - COMPREPLY=( $(compgen -W "$auth_cmds" -- $cur) ) - ;; block) COMPREPLY=( $(compgen -W "$block_cmds" -- $cur) ) ;;