From 3c9ac769827da50d7c3617cba13aeaa01bccbba7 Mon Sep 17 00:00:00 2001 From: myarmolinsky Date: Thu, 26 Sep 2024 08:13:29 -0400 Subject: [PATCH 1/3] git mv `logs/index` to `device/logs` Change-type: patch --- src/commands/{logs/index.ts => device/logs.ts} | 0 tests/commands/{ => device}/logs.spec.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/commands/{logs/index.ts => device/logs.ts} (100%) rename tests/commands/{ => device}/logs.spec.ts (100%) diff --git a/src/commands/logs/index.ts b/src/commands/device/logs.ts similarity index 100% rename from src/commands/logs/index.ts rename to src/commands/device/logs.ts diff --git a/tests/commands/logs.spec.ts b/tests/commands/device/logs.spec.ts similarity index 100% rename from tests/commands/logs.spec.ts rename to tests/commands/device/logs.spec.ts From b77f266bd757d62f110d4fc61128b5aa592f7a4e Mon Sep 17 00:00:00 2001 From: myarmolinsky Date: Thu, 26 Sep 2024 08:20:52 -0400 Subject: [PATCH 2/3] Add alias `device logs` for `logs` Change-type: minor --- completion/_balena | 4 +- completion/balena-completion.bash | 4 +- docs/balena-cli.md | 128 +++++++++--------- src/commands/device/logs.ts | 20 +-- src/help.ts | 1 - tests/commands/device/logs.spec.ts | 10 +- tests/commands/help.spec.ts | 2 +- .../pkg/expected-warnings-darwin-arm64.txt | 6 +- .../pkg/expected-warnings-darwin-x64.txt | 6 +- .../pkg/expected-warnings-linux-arm64.txt | 6 +- .../pkg/expected-warnings-linux-x64.txt | 6 +- .../pkg/expected-warnings-win32-x64.txt | 6 +- 12 files changed, 101 insertions(+), 98 deletions(-) diff --git a/completion/_balena b/completion/_balena index 3dce4fd3..9065907f 100644 --- a/completion/_balena +++ b/completion/_balena @@ -8,13 +8,13 @@ _balena() { local context state line curcontext="$curcontext" # Valid top-level completions - main_commands=( api-key app block build config deploy device devices env fleet internal join leave local login logout logs notes organization os preload push release settings ssh ssh-key support tag tunnel util version whoami ) + main_commands=( api-key app block build config deploy device devices env fleet internal join leave local login logout notes organization os preload push release settings ssh ssh-key support tag tunnel util version whoami ) # Sub-completions api_key_cmds=( generate list revoke ) app_cmds=( create ) block_cmds=( create ) config_cmds=( generate inject read reconfigure write ) - device_cmds=( deactivate detect identify init list local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet ) + device_cmds=( deactivate detect identify init list local-mode logs 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 list rename rm ) fleet_cmds=( create list pin purge rename restart rm track-latest ) diff --git a/completion/balena-completion.bash b/completion/balena-completion.bash index c0fca650..850de28d 100644 --- a/completion/balena-completion.bash +++ b/completion/balena-completion.bash @@ -7,13 +7,13 @@ _balena_complete() local cur prev # Valid top-level completions - main_commands="api-key app block build config deploy device devices env fleet internal join leave local login logout logs notes organization os preload push release settings ssh ssh-key support tag tunnel util version whoami" + main_commands="api-key app block build config deploy device devices env fleet internal join leave local login logout notes organization os preload push release settings ssh ssh-key support tag tunnel util version whoami" # Sub-completions api_key_cmds="generate list revoke" app_cmds="create" block_cmds="create" config_cmds="generate inject read reconfigure write" - device_cmds="deactivate detect identify init list local-mode move os-update pin public-url purge reboot register rename restart rm shutdown start-service stop-service track-fleet" + device_cmds="deactivate detect identify init list local-mode logs 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 list rename rm" fleet_cmds="create list pin purge rename restart rm track-latest" diff --git a/docs/balena-cli.md b/docs/balena-cli.md index b1c738ae..d2e43bf6 100644 --- a/docs/balena-cli.md +++ b/docs/balena-cli.md @@ -202,6 +202,7 @@ are encouraged to regularly update the balena CLI to the latest version. - [device init](#device-init) - [device list](#device-list) - [device local-mode](#device-local-mode) + - [device logs](#device-logs) - [device move](#device-move) - [device os-update](#device-os-update) - [device pin](#device-pin) @@ -242,10 +243,6 @@ are encouraged to regularly update the balena CLI to the latest version. - [local configure](#local-configure) - [local flash](#local-flash) -- Logs - - - [logs](#logs) - - Network - [ssh](#ssh) @@ -1515,6 +1512,70 @@ disable local mode output boolean indicating local mode status +## device logs + +### Aliases + +- `logs` + + +To use one of the aliases, replace `device logs` with the alias. + +### Description + +Show logs for a specific device. + +By default, the command prints all log messages and exits. + +To continuously stream output, and see new logs in real time, use the `--tail` option. + +If an IP or .local address is passed to this command, logs are displayed from +a local mode device with that address. Note that --tail is implied +when this command is provided a local mode device. + +Logs from a single service can be displayed with the --service flag. Just system logs +can be shown with the --system flag. Note that these flags can be used together. + +Note: --service and --system flags must come after the device parameter, as per examples. + +Examples: + + $ balena device logs 23c73a1 + $ balena device logs 23c73a1 --tail + + $ balena device logs 192.168.0.31 + $ balena device logs 192.168.0.31 --service my-service + $ balena device logs 192.168.0.31 --service my-service-1 --service my-service-2 + + $ balena device logs 23c73a1.local --system + $ balena device logs 23c73a1.local --system --service my-service + +### Arguments + +#### DEVICE + +device UUID, IP, or .local address + +### Options + +#### --max-retry MAX-RETRY + +Maximum number of reconnection attempts on "connection lost" errors +(use 0 to disable auto reconnection). + +#### -t, --tail + +continuously stream output + +#### -s, --service SERVICE + +Reject logs not originating from this service. +This can be used in combination with --system or other --service flags. + +#### -S, --system + +Only show system logs. This can be used in combination with --service. + ## device move ### Description @@ -2572,65 +2633,6 @@ Check `balena util available-drives` for available options. answer "yes" to all questions (non interactive use) -# Logs - -## logs - -### Description - -Show logs for a specific device. - -By default, the command prints all log messages and exits. - -To continuously stream output, and see new logs in real time, use the `--tail` option. - -If an IP or .local address is passed to this command, logs are displayed from -a local mode device with that address. Note that --tail is implied -when this command is provided a local mode device. - -Logs from a single service can be displayed with the --service flag. Just system logs -can be shown with the --system flag. Note that these flags can be used together. - -Note: --service and --system flags must come after the device parameter, as per examples. - -Examples: - - $ balena logs 23c73a1 - $ balena logs 23c73a1 --tail - - $ balena logs 192.168.0.31 - $ balena logs 192.168.0.31 --service my-service - $ balena logs 192.168.0.31 --service my-service-1 --service my-service-2 - - $ balena logs 23c73a1.local --system - $ balena logs 23c73a1.local --system --service my-service - -### Arguments - -#### DEVICE - -device UUID, IP, or .local address - -### Options - -#### --max-retry MAX-RETRY - -Maximum number of reconnection attempts on "connection lost" errors -(use 0 to disable auto reconnection). - -#### -t, --tail - -continuously stream output - -#### -s, --service SERVICE - -Reject logs not originating from this service. -This can be used in combination with --system or other --service flags. - -#### -S, --system - -Only show system logs. This can be used in combination with --service. - # Network ## ssh diff --git a/src/commands/device/logs.ts b/src/commands/device/logs.ts index 8c3cbf22..4903482d 100644 --- a/src/commands/device/logs.ts +++ b/src/commands/device/logs.ts @@ -22,7 +22,9 @@ import type { LogMessage } from 'balena-sdk'; const MAX_RETRY = 1000; -export default class LogsCmd extends Command { +export default class DeviceLogsCmd extends Command { + public static aliases = ['logs']; + public static description = stripIndent` Show device logs. @@ -42,15 +44,15 @@ export default class LogsCmd extends Command { Note: --service and --system flags must come after the device parameter, as per examples. `; public static examples = [ - '$ balena logs 23c73a1', - '$ balena logs 23c73a1 --tail', + '$ balena device logs 23c73a1', + '$ balena device logs 23c73a1 --tail', '', - '$ balena logs 192.168.0.31', - '$ balena logs 192.168.0.31 --service my-service', - '$ balena logs 192.168.0.31 --service my-service-1 --service my-service-2', + '$ balena device logs 192.168.0.31', + '$ balena device logs 192.168.0.31 --service my-service', + '$ balena device logs 192.168.0.31 --service my-service-1 --service my-service-2', '', - '$ balena logs 23c73a1.local --system', - '$ balena logs 23c73a1.local --system --service my-service', + '$ balena device logs 23c73a1.local --system', + '$ balena device logs 23c73a1.local --system --service my-service', ]; public static args = { @@ -90,7 +92,7 @@ export default class LogsCmd extends Command { public static primary = true; public async run() { - const { args: params, flags: options } = await this.parse(LogsCmd); + const { args: params, flags: options } = await this.parse(DeviceLogsCmd); const balena = getBalenaSdk(); const { serviceIdToName } = await import('../../utils/cloud'); diff --git a/src/help.ts b/src/help.ts index 39c38771..265d1fbe 100644 --- a/src/help.ts +++ b/src/help.ts @@ -227,7 +227,6 @@ See: https://git.io/JRHUW#deprecation-policy`, readonly manuallySortedPrimaryCommands = [ 'login', 'push', - 'logs', 'ssh', 'fleet', 'device', diff --git a/tests/commands/device/logs.spec.ts b/tests/commands/device/logs.spec.ts index 64670848..9e13d785 100644 --- a/tests/commands/device/logs.spec.ts +++ b/tests/commands/device/logs.spec.ts @@ -17,13 +17,13 @@ import { expect } from 'chai'; -import { BalenaAPIMock } from '../nock/balena-api-mock'; -import { cleanOutput, runCommand } from '../helpers'; -import { SupervisorMock } from '../nock/supervisor-mock'; +import { BalenaAPIMock } from '../../nock/balena-api-mock'; +import { cleanOutput, runCommand } from '../../helpers'; +import { SupervisorMock } from '../../nock/supervisor-mock'; const itS = process.env.BALENA_CLI_TEST_TYPE === 'standalone' ? it : it.skip; -describe('balena logs', function () { +describe('balena device logs', function () { let api: BalenaAPIMock; let supervisor: SupervisorMock; @@ -47,7 +47,7 @@ describe('balena logs', function () { supervisor.expectGetLogs(); supervisor.expectGetLogs(); - const { err, out } = await runCommand('logs 1.2.3.4 --max-retry 1'); + const { err, out } = await runCommand('device logs 1.2.3.4 --max-retry 1'); const errLines = cleanOutput(err, true); const errMsg = diff --git a/tests/commands/help.spec.ts b/tests/commands/help.spec.ts index c8654e7f..14759732 100644 --- a/tests/commands/help.spec.ts +++ b/tests/commands/help.spec.ts @@ -28,7 +28,6 @@ $ balena [COMMAND] [OPTIONS] PRIMARY COMMANDS login login to balena push start a remote build on the balenaCloud build servers or a local mode device - logs show device logs ssh [service] SSH into the host or application container of a device app display information about a single application device show info about a single device @@ -56,6 +55,7 @@ ADDITIONAL COMMANDS device identify identify a device device init initialise a device with balenaOS device list list all devices + device logs show device logs device move move one or more devices to another application device os-update start a Host OS update for a device device public-url get or manage the public URL for a device diff --git a/tests/test-data/pkg/expected-warnings-darwin-arm64.txt b/tests/test-data/pkg/expected-warnings-darwin-arm64.txt index 10cdbde5..ada9925e 100644 --- a/tests/test-data/pkg/expected-warnings-darwin-arm64.txt +++ b/tests/test-data/pkg/expected-warnings-darwin-arm64.txt @@ -85,6 +85,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/logs.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/move.js @@ -190,9 +193,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logout/index.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js diff --git a/tests/test-data/pkg/expected-warnings-darwin-x64.txt b/tests/test-data/pkg/expected-warnings-darwin-x64.txt index 62f7814c..bc7ec278 100644 --- a/tests/test-data/pkg/expected-warnings-darwin-x64.txt +++ b/tests/test-data/pkg/expected-warnings-darwin-x64.txt @@ -85,6 +85,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/logs.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/move.js @@ -190,9 +193,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logout/index.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js diff --git a/tests/test-data/pkg/expected-warnings-linux-arm64.txt b/tests/test-data/pkg/expected-warnings-linux-arm64.txt index 10cdbde5..ada9925e 100644 --- a/tests/test-data/pkg/expected-warnings-linux-arm64.txt +++ b/tests/test-data/pkg/expected-warnings-linux-arm64.txt @@ -85,6 +85,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/logs.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/move.js @@ -190,9 +193,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logout/index.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js diff --git a/tests/test-data/pkg/expected-warnings-linux-x64.txt b/tests/test-data/pkg/expected-warnings-linux-x64.txt index 62f7814c..bc7ec278 100644 --- a/tests/test-data/pkg/expected-warnings-linux-x64.txt +++ b/tests/test-data/pkg/expected-warnings-linux-x64.txt @@ -85,6 +85,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/logs.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/move.js @@ -190,9 +193,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logout/index.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js diff --git a/tests/test-data/pkg/expected-warnings-win32-x64.txt b/tests/test-data/pkg/expected-warnings-win32-x64.txt index 4eae0f76..348a8568 100644 --- a/tests/test-data/pkg/expected-warnings-win32-x64.txt +++ b/tests/test-data/pkg/expected-warnings-win32-x64.txt @@ -85,6 +85,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\device\local-mode.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\device\logs.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\device\move.js @@ -190,9 +193,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\logout\index.js -> Warning Entry 'main' not found in %1 - %1: node_modules\@oclif\core\package.json - %2: build\commands\logs\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\notes\index.js From 8e9b992a59d0f2b813e1ff983b3c79dc7d42dc00 Mon Sep 17 00:00:00 2001 From: myarmolinsky Date: Mon, 21 Oct 2024 07:45:11 -0400 Subject: [PATCH 3/3] Deduplicate dependencies --- npm-shrinkwrap.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 82d88a87..fa5b5a53 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3739,9 +3739,9 @@ } }, "node_modules/@types/node": { - "version": "20.16.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.12.tgz", - "integrity": "sha512-LfPFB0zOeCeCNQV3i+67rcoVvoN5n0NVuR2vLG0O5ySQMgchuZlC4lgz546ZOJyDtj5KIgOxy+lacOimfqZAIA==", + "version": "20.16.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.13.tgz", + "integrity": "sha512-GjQ7im10B0labo8ZGXDGROUl9k0BNyDgzfGpb4g/cl+4yYDWVKcozANF4FGr4/p0O/rAkQClM6Wiwkije++1Tg==", "dependencies": { "undici-types": "~6.19.2" } @@ -5475,9 +5475,9 @@ } }, "node_modules/balena-sdk/node_modules/@types/node": { - "version": "18.19.56", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.56.tgz", - "integrity": "sha512-4EMJlWwwGnVPflJAtM14p9eVSa6BOv5b92mCsh5zcM1UagNtEtrbbtaE6WE1tw2TabavatnwqXjlIpcAEuJJNg==", + "version": "18.19.57", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.57.tgz", + "integrity": "sha512-I2ioBd/IPrYDMv9UNR5NlPElOZ68QB7yY5V2EsLtSrTO0LM0PnCEFF9biLWHf5k+sIy4ohueCV9t4gk1AEdlVA==", "dependencies": { "undici-types": "~5.26.4" }