mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Merge pull request #2846 from balena-io/use-default-usage
Use oclif default usage instead of manually filling it out
This commit is contained in:
commit
680d592af2
2
automation/capitanodoc/doc-types.d.ts
vendored
2
automation/capitanodoc/doc-types.d.ts
vendored
@ -26,7 +26,7 @@ export interface Document {
|
||||
|
||||
export interface Category {
|
||||
title: string;
|
||||
commands: OclifCommand[];
|
||||
commands: Array<OclifCommand & { name: string }>;
|
||||
}
|
||||
|
||||
export { OclifCommand };
|
||||
|
@ -18,7 +18,6 @@ import * as path from 'path';
|
||||
import { getCapitanoDoc } from './capitanodoc';
|
||||
import type { Category, Document, OclifCommand } from './doc-types';
|
||||
import * as markdown from './markdown';
|
||||
import { stripIndent } from '../../src/utils/lazy';
|
||||
|
||||
/**
|
||||
* Generates the markdown document (as a string) for the CLI documentation
|
||||
@ -39,7 +38,7 @@ export async function renderMarkdown(): Promise<string> {
|
||||
};
|
||||
|
||||
for (const jsFilename of commandCategory.files) {
|
||||
category.commands.push(...(await importOclifCommands(jsFilename)));
|
||||
category.commands.push(await importOclifCommands(jsFilename));
|
||||
}
|
||||
result.categories.push(category);
|
||||
}
|
||||
@ -47,51 +46,23 @@ export async function renderMarkdown(): Promise<string> {
|
||||
return markdown.render(result);
|
||||
}
|
||||
|
||||
// Help is now managed via a plugin
|
||||
// This fake command allows capitanodoc to include help in docs
|
||||
class FakeHelpCommand {
|
||||
description = stripIndent`
|
||||
List balena commands, or get detailed help for a specific command.
|
||||
async function importOclifCommands(jsFilename: string) {
|
||||
const command = (await import(path.join(process.cwd(), jsFilename)))
|
||||
.default as OclifCommand;
|
||||
|
||||
List balena commands, or get detailed help for a specific command.
|
||||
`;
|
||||
|
||||
examples = [
|
||||
'$ balena help',
|
||||
'$ balena help login',
|
||||
'$ balena help os download',
|
||||
];
|
||||
|
||||
args = {
|
||||
command: {
|
||||
description: 'command to show help for',
|
||||
},
|
||||
};
|
||||
|
||||
usage = 'help [command]';
|
||||
|
||||
flags = {
|
||||
verbose: {
|
||||
description: 'show additional commands',
|
||||
char: '-v',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function importOclifCommands(
|
||||
jsFilename: string,
|
||||
): Promise<OclifCommand[]> {
|
||||
// TODO: Currently oclif commands with no `usage` overridden will cause
|
||||
// an error when parsed. This should be improved so that `usage` does not have
|
||||
// to be overridden if not necessary.
|
||||
|
||||
const command: OclifCommand =
|
||||
jsFilename === 'help'
|
||||
? (new FakeHelpCommand() as unknown as OclifCommand)
|
||||
: ((await import(path.join(process.cwd(), jsFilename)))
|
||||
.default as OclifCommand);
|
||||
|
||||
return [command];
|
||||
return {
|
||||
...command,
|
||||
// build/commands/device/index.js -> device
|
||||
// build/commands/device/list.js -> device list
|
||||
name: jsFilename
|
||||
.split('/')
|
||||
.slice(2)
|
||||
.join(' ')
|
||||
.split('.')
|
||||
.slice(0, 1)
|
||||
.join(' ')
|
||||
.split(' index')[0],
|
||||
} as Category['commands'][0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,8 +22,8 @@ import { getManualSortCompareFunction } from '../../src/utils/helpers';
|
||||
import { capitanoizeOclifUsage } from '../../src/utils/oclif-utils';
|
||||
import type { Category, Document, OclifCommand } from './doc-types';
|
||||
|
||||
function renderOclifCommand(command: OclifCommand): string[] {
|
||||
const result = [`## ${ent.encode(command.usage || '')}`];
|
||||
function renderOclifCommand(command: Category['commands'][0]): string[] {
|
||||
const result = [`## ${ent.encode(command.name || '')}`];
|
||||
const description = (command.description || '')
|
||||
.split('\n')
|
||||
.slice(1) // remove the first line, which oclif uses as help header
|
||||
@ -80,7 +80,7 @@ function renderToc(categories: Category[]): string[] {
|
||||
result.push(
|
||||
category.commands
|
||||
.map((command) => {
|
||||
const signature = capitanoizeOclifUsage(command.usage);
|
||||
const signature = capitanoizeOclifUsage(command.name);
|
||||
return `\t- [${ent.encode(signature)}](${getAnchor(signature)})`;
|
||||
})
|
||||
.join('\n'),
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,8 +40,6 @@ export default class GenerateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'api-key generate <name>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -41,8 +41,6 @@ export default class RevokeCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'api-key revoke <ids>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -30,8 +30,6 @@ export default class ApiKeysCmd extends Command {
|
||||
`;
|
||||
public static examples = ['$ balena api-keys'];
|
||||
|
||||
public static usage = 'api-keys';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
user: Flags.boolean({
|
||||
|
@ -56,8 +56,6 @@ export default class AppCreateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'app create <name>';
|
||||
|
||||
public static flags = {
|
||||
organization: Flags.string({
|
||||
char: 'o',
|
||||
|
@ -56,8 +56,6 @@ export default class BlockCreateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'block create <name>';
|
||||
|
||||
public static flags = {
|
||||
organization: Flags.string({
|
||||
char: 'o',
|
||||
|
@ -84,8 +84,6 @@ ${dockerignoreHelp}
|
||||
source: Args.string({ description: 'path of project source directory' }),
|
||||
};
|
||||
|
||||
public static usage = 'build [source]';
|
||||
|
||||
public static flags = {
|
||||
arch: Flags.string({
|
||||
description: 'the architecture to build for',
|
||||
|
@ -60,8 +60,6 @@ export default class ConfigGenerateCmd extends Command {
|
||||
'$ balena config generate --fleet myorg/fleet --version 2.12.7 --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 15',
|
||||
];
|
||||
|
||||
public static usage = 'config generate';
|
||||
|
||||
public static flags = {
|
||||
version: Flags.string({
|
||||
description: 'a balenaOS version',
|
||||
|
@ -43,8 +43,6 @@ export default class ConfigInjectCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'config inject <file>';
|
||||
|
||||
public static flags = {
|
||||
drive: cf.driveOrImg,
|
||||
help: cf.help,
|
||||
|
@ -36,8 +36,6 @@ export default class ConfigReadCmd extends Command {
|
||||
'$ balena config read --drive balena.img',
|
||||
];
|
||||
|
||||
public static usage = 'config read';
|
||||
|
||||
public static flags = {
|
||||
drive: cf.driveOrImg,
|
||||
help: cf.help,
|
||||
|
@ -39,8 +39,6 @@ export default class ConfigReconfigureCmd extends Command {
|
||||
'$ balena config reconfigure --drive balena.img --advanced',
|
||||
];
|
||||
|
||||
public static usage = 'config reconfigure';
|
||||
|
||||
public static flags = {
|
||||
drive: cf.driveOrImg,
|
||||
advanced: Flags.boolean({
|
||||
|
@ -48,8 +48,6 @@ export default class ConfigWriteCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'config write <key> <value>';
|
||||
|
||||
public static flags = {
|
||||
drive: cf.driveOrImg,
|
||||
help: cf.help,
|
||||
|
@ -108,8 +108,6 @@ ${dockerignoreHelp}
|
||||
image: Args.string({ description: 'the image to deploy' }),
|
||||
};
|
||||
|
||||
public static usage = 'deploy <fleet> [image]';
|
||||
|
||||
public static flags = {
|
||||
source: Flags.string({
|
||||
description:
|
||||
|
@ -41,8 +41,6 @@ export default class DeviceDeactivateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device deactivate <uuid>';
|
||||
|
||||
public static flags = {
|
||||
yes: cf.yes,
|
||||
help: cf.help,
|
||||
|
@ -36,8 +36,6 @@ export default class DeviceIdentifyCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device identify <uuid>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -62,8 +62,6 @@ export default class DeviceCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device <uuid>';
|
||||
|
||||
public static flags = {
|
||||
json: cf.json,
|
||||
help: cf.help,
|
||||
|
@ -74,8 +74,6 @@ export default class DeviceInitCmd extends Command {
|
||||
'$ balena device init --fleet myFleet --os-version 2.83.21+rev1.prod --drive /dev/disk5 --config config.json --yes',
|
||||
];
|
||||
|
||||
public static usage = 'device init';
|
||||
|
||||
public static flags = {
|
||||
fleet: cf.fleet,
|
||||
yes: cf.yes,
|
||||
|
@ -42,8 +42,6 @@ export default class DeviceLocalModeCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device local-mode <uuid>';
|
||||
|
||||
public static flags = {
|
||||
enable: Flags.boolean({
|
||||
description: 'enable local mode',
|
||||
|
@ -54,8 +54,6 @@ export default class DeviceMoveCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device move <uuid(s)>';
|
||||
|
||||
public static flags = {
|
||||
fleet: cf.fleet,
|
||||
help: cf.help,
|
||||
|
@ -47,8 +47,6 @@ export default class DeviceOsUpdateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device os-update <uuid>';
|
||||
|
||||
public static flags = {
|
||||
version: Flags.string({
|
||||
description: 'a balenaOS version',
|
||||
|
@ -44,8 +44,6 @@ export default class DevicePinCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device pin <uuid> [releaseToPinTo]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -44,8 +44,6 @@ export default class DevicePublicUrlCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device public-url <uuid>';
|
||||
|
||||
public static flags = {
|
||||
enable: Flags.boolean({
|
||||
description: 'enable the public URL',
|
||||
|
@ -35,8 +35,6 @@ export default class DevicePurgeCmd extends Command {
|
||||
'$ balena device purge 55d43b3,23c73a1',
|
||||
];
|
||||
|
||||
public static usage = 'device purge <uuid>';
|
||||
|
||||
public static args = {
|
||||
uuid: Args.string({
|
||||
description: 'comma-separated list (no blank spaces) of device UUIDs',
|
||||
|
@ -35,8 +35,6 @@ export default class DeviceRebootCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device reboot <uuid>';
|
||||
|
||||
public static flags = {
|
||||
force: cf.force,
|
||||
help: cf.help,
|
||||
|
@ -44,8 +44,6 @@ export default class DeviceRegisterCmd extends Command {
|
||||
fleet: ca.fleetRequired,
|
||||
};
|
||||
|
||||
public static usage = 'device register <fleet>';
|
||||
|
||||
public static flags = {
|
||||
uuid: Flags.string({
|
||||
description: 'custom uuid',
|
||||
|
@ -43,8 +43,6 @@ export default class DeviceRenameCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device rename <uuid> [newName]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -53,8 +53,6 @@ export default class DeviceRestartCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device restart <uuid>';
|
||||
|
||||
public static flags = {
|
||||
service: Flags.string({
|
||||
description:
|
||||
|
@ -43,8 +43,6 @@ export default class DeviceRmCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device rm <uuid(s)>';
|
||||
|
||||
public static flags = {
|
||||
yes: cf.yes,
|
||||
help: cf.help,
|
||||
|
@ -36,8 +36,6 @@ export default class DeviceShutdownCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device shutdown <uuid>';
|
||||
|
||||
public static flags = {
|
||||
force: cf.force,
|
||||
help: cf.help,
|
||||
|
@ -46,8 +46,6 @@ export default class DeviceStartServiceCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device start-service <uuid>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -46,8 +46,6 @@ export default class DeviceStopServiceCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device stop-service <uuid>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -35,8 +35,6 @@ export default class DeviceTrackFleetCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'device track-fleet <uuid>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -53,8 +53,6 @@ export default class DevicesCmd extends Command {
|
||||
'$ balena devices -f myorg/myfleet',
|
||||
];
|
||||
|
||||
public static usage = 'devices';
|
||||
|
||||
public static flags = {
|
||||
fleet: cf.fleet,
|
||||
json: cf.json,
|
||||
|
@ -21,7 +21,6 @@ import Command from '../../command';
|
||||
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
|
||||
export default class DevicesSupportedCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -40,11 +39,6 @@ export default class DevicesSupportedCmd extends Command {
|
||||
'$ balena devices supported --json',
|
||||
];
|
||||
|
||||
public static usage = (
|
||||
'devices supported ' +
|
||||
new CommandHelp({ args: DevicesSupportedCmd.args }).defaultUsage()
|
||||
).trim();
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
json: Flags.boolean({
|
||||
|
1
src/commands/env/add.ts
vendored
1
src/commands/env/add.ts
vendored
@ -92,7 +92,6 @@ export default class EnvAddCmd extends Command {
|
||||
|
||||
// Required for supporting empty string ('') `value` args.
|
||||
public static strict = false;
|
||||
public static usage = 'env add <name> [value]';
|
||||
|
||||
public static flags = {
|
||||
fleet: { ...cf.fleet, exclusive: ['device'] },
|
||||
|
2
src/commands/env/rename.ts
vendored
2
src/commands/env/rename.ts
vendored
@ -53,8 +53,6 @@ export default class EnvRenameCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'env rename <id> <value>';
|
||||
|
||||
public static flags = {
|
||||
config: ec.booleanConfig,
|
||||
device: ec.booleanDevice,
|
||||
|
2
src/commands/env/rm.ts
vendored
2
src/commands/env/rm.ts
vendored
@ -52,8 +52,6 @@ export default class EnvRmCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'env rm <id>';
|
||||
|
||||
public static flags = {
|
||||
config: ec.booleanConfig,
|
||||
device: ec.booleanDevice,
|
||||
|
@ -94,8 +94,6 @@ export default class EnvsCmd extends Command {
|
||||
'$ balena envs --device 7cf02a6 --service MyService',
|
||||
];
|
||||
|
||||
public static usage = 'envs';
|
||||
|
||||
public static flags = {
|
||||
fleet: { ...cf.fleet, exclusive: ['device'] },
|
||||
config: Flags.boolean({
|
||||
|
@ -56,8 +56,6 @@ export default class FleetCreateCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'fleet create <name>';
|
||||
|
||||
public static flags = {
|
||||
organization: Flags.string({
|
||||
char: 'o',
|
||||
|
@ -41,8 +41,6 @@ export default class FleetCmd extends Command {
|
||||
fleet: ca.fleetRequired,
|
||||
};
|
||||
|
||||
public static usage = 'fleet <fleet>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
view: Flags.boolean({
|
||||
|
@ -44,8 +44,6 @@ export default class FleetPinCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'fleet pin <slug> [releaseToPinTo]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -40,8 +40,6 @@ export default class FleetPurgeCmd extends Command {
|
||||
fleet: ca.fleetRequired,
|
||||
};
|
||||
|
||||
public static usage = 'fleet purge <fleet>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -48,8 +48,6 @@ export default class FleetRenameCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'fleet rename <fleet> [newName]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -39,8 +39,6 @@ export default class FleetRestartCmd extends Command {
|
||||
fleet: ca.fleetRequired,
|
||||
};
|
||||
|
||||
public static usage = 'fleet restart <fleet>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -42,8 +42,6 @@ export default class FleetRmCmd extends Command {
|
||||
fleet: ca.fleetRequired,
|
||||
};
|
||||
|
||||
public static usage = 'fleet rm <fleet>';
|
||||
|
||||
public static flags = {
|
||||
yes: cf.yes,
|
||||
help: cf.help,
|
||||
|
@ -38,8 +38,6 @@ export default class FleetTrackLatestCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'fleet track-latest <slug>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -39,8 +39,6 @@ export default class FleetsCmd extends Command {
|
||||
|
||||
public static examples = ['$ balena fleets'];
|
||||
|
||||
public static usage = 'fleets';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
json: cf.json,
|
||||
|
@ -18,7 +18,6 @@
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
|
||||
// 'Internal' commands are called during the execution of other commands.
|
||||
// `osinit` is called during `os initialize`
|
||||
@ -48,11 +47,6 @@ export default class OsinitCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = (
|
||||
'internal osinit ' +
|
||||
new CommandHelp({ args: OsinitCmd.args }).defaultUsage()
|
||||
).trim();
|
||||
|
||||
public static hidden = true;
|
||||
public static root = true;
|
||||
public static offlineCompatible = true;
|
||||
|
@ -60,9 +60,6 @@ export default class JoinCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
// Hardcoded to preserve camelcase
|
||||
public static usage = 'join [deviceIpOrHostname]';
|
||||
|
||||
public static flags = {
|
||||
fleet: cf.fleet,
|
||||
pollInterval: Flags.integer({
|
||||
|
@ -29,7 +29,7 @@ export default class KeyAddCmd extends Command {
|
||||
|
||||
If \`path\` is omitted, the command will attempt to read the SSH key from stdin.
|
||||
|
||||
About SSH keys
|
||||
About SSH keys
|
||||
An "SSH key" actually consists of a public/private key pair. A typical name
|
||||
for the private key file is "id_rsa", and a typical name for the public key
|
||||
file is "id_rsa.pub". Both key files are saved to your computer (with the
|
||||
@ -37,7 +37,7 @@ export default class KeyAddCmd extends Command {
|
||||
saved to your balena account. This means that if you change computers or
|
||||
otherwise lose the private key, you cannot recover the private key through
|
||||
your balena account. You can however add new keys, and delete the old ones.
|
||||
|
||||
|
||||
To generate a new SSH key pair, a nice guide can be found in GitHub's docs:
|
||||
https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
|
||||
Skip the step about adding the key to a GitHub account, and instead add it to
|
||||
@ -61,8 +61,6 @@ export default class KeyAddCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'key add <name> [path]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -38,8 +38,6 @@ export default class KeyCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'key <id>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -40,8 +40,6 @@ export default class KeyRmCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'key rm <id>';
|
||||
|
||||
public static flags = {
|
||||
yes: cf.yes,
|
||||
help: cf.help,
|
||||
|
@ -27,8 +27,6 @@ export default class KeysCmd extends Command {
|
||||
`;
|
||||
public static examples = ['$ balena keys'];
|
||||
|
||||
public static usage = 'keys';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -50,8 +50,6 @@ export default class LeaveCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'leave [deviceIpOrHostname]';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -40,8 +40,6 @@ export default class LocalConfigureCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'local configure <target>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -46,8 +46,6 @@ export default class LocalFlashCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'local flash <image>';
|
||||
|
||||
public static flags = {
|
||||
drive: cf.drive,
|
||||
yes: cf.yes,
|
||||
|
@ -63,8 +63,6 @@ export default class LoginCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'login';
|
||||
|
||||
public static flags = {
|
||||
web: Flags.boolean({
|
||||
default: false,
|
||||
|
@ -26,8 +26,6 @@ export default class LogoutCmd extends Command {
|
||||
`;
|
||||
public static examples = ['$ balena logout'];
|
||||
|
||||
public static usage = 'logout';
|
||||
|
||||
public async run() {
|
||||
await this.parse(LogoutCmd);
|
||||
await getBalenaSdk().auth.logout();
|
||||
|
@ -61,8 +61,6 @@ export default class LogsCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'logs <device>';
|
||||
|
||||
public static flags = {
|
||||
'max-retry': Flags.integer({
|
||||
description: stripIndent`
|
||||
|
@ -42,8 +42,6 @@ export default class NoteCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'note <|note>';
|
||||
|
||||
public static flags = {
|
||||
device: { exclusive: ['dev'], ...cf.device },
|
||||
dev: Flags.string({
|
||||
|
@ -27,8 +27,6 @@ export default class OrgsCmd extends Command {
|
||||
`;
|
||||
public static examples = ['$ balena orgs'];
|
||||
|
||||
public static usage = 'orgs';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -46,8 +46,6 @@ export default class OsBuildConfigCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'os build-config <image> <device-type>';
|
||||
|
||||
public static flags = {
|
||||
advanced: Flags.boolean({
|
||||
description: 'show advanced configuration options',
|
||||
|
@ -92,8 +92,6 @@ export default class OsConfigureCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'os configure <image>';
|
||||
|
||||
public static flags = {
|
||||
advanced: Flags.boolean({
|
||||
char: 'v',
|
||||
|
@ -62,8 +62,6 @@ export default class OsDownloadCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'os download <type>';
|
||||
|
||||
public static flags = {
|
||||
output: Flags.string({
|
||||
description: 'output path',
|
||||
|
@ -48,8 +48,6 @@ export default class OsInitializeCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'os initialize <image>';
|
||||
|
||||
public static flags = {
|
||||
type: cf.deviceType,
|
||||
drive: cf.drive,
|
||||
|
@ -40,8 +40,6 @@ export default class OsVersionsCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'os versions <type>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
esr: Flags.boolean({
|
||||
|
@ -80,8 +80,6 @@ export default class PreloadCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'preload <image>';
|
||||
|
||||
public static flags = {
|
||||
fleet: cf.fleet,
|
||||
commit: Flags.string({
|
||||
|
@ -99,8 +99,6 @@ export default class PushCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'push <fleetOrDevice>';
|
||||
|
||||
public static flags = {
|
||||
source: Flags.string({
|
||||
description: stripIndent`
|
||||
|
@ -40,8 +40,6 @@ export default class ReleaseFinalizeCmd extends Command {
|
||||
'$ balena release finalize 1234567',
|
||||
];
|
||||
|
||||
public static usage = 'release finalize <commitOrId>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -42,8 +42,6 @@ export default class ReleaseCmd extends Command {
|
||||
'$ balena release d3f3151f5ad25ca6b070aa4d08296aca --json',
|
||||
];
|
||||
|
||||
public static usage = 'release <commitOrId>';
|
||||
|
||||
public static flags = {
|
||||
json: cf.json,
|
||||
help: cf.help,
|
||||
|
@ -35,8 +35,6 @@ export default class ReleaseInvalidateCmd extends Command {
|
||||
'$ balena release invalidate 1234567',
|
||||
];
|
||||
|
||||
public static usage = 'release invalidate <commitOrId>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -34,8 +34,6 @@ export default class ReleaseValidateCmd extends Command {
|
||||
'$ balena release validate 1234567',
|
||||
];
|
||||
|
||||
public static usage = 'release validate <commitOrId>';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -38,8 +38,6 @@ export default class ReleasesCmd extends Command {
|
||||
'$ balena releases myorg/myfleet --json',
|
||||
];
|
||||
|
||||
public static usage = 'releases <fleet>';
|
||||
|
||||
public static flags = {
|
||||
json: cf.json,
|
||||
help: cf.help,
|
||||
|
@ -38,8 +38,6 @@ export default class ScanCmd extends Command {
|
||||
'$ balena scan --verbose',
|
||||
];
|
||||
|
||||
public static usage = 'scan';
|
||||
|
||||
public static flags = {
|
||||
verbose: Flags.boolean({
|
||||
default: false,
|
||||
|
@ -27,8 +27,6 @@ export default class SettingsCmd extends Command {
|
||||
`;
|
||||
public static examples = ['$ balena settings'];
|
||||
|
||||
public static usage = 'settings';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -75,8 +75,6 @@ export default class SshCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'ssh <fleetOrDevice> [service]';
|
||||
|
||||
public static flags = {
|
||||
port: Flags.integer({
|
||||
description: stripIndent`
|
||||
|
@ -52,8 +52,6 @@ export default class SupportCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'support <action>';
|
||||
|
||||
public static flags = {
|
||||
device: Flags.string({
|
||||
description: 'comma-separated list (no spaces) of device UUIDs',
|
||||
|
@ -45,8 +45,6 @@ export default class TagRmCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'tag rm <tagKey>';
|
||||
|
||||
public static flags = {
|
||||
fleet: {
|
||||
...cf.fleet,
|
||||
|
@ -58,7 +58,6 @@ export default class TagSetCmd extends Command {
|
||||
|
||||
// Required for supporting empty string ('') `value` args.
|
||||
public static strict = false;
|
||||
public static usage = 'tag set <tagKey> [value]';
|
||||
|
||||
public static flags = {
|
||||
fleet: {
|
||||
|
@ -38,8 +38,6 @@ export default class TagsCmd extends Command {
|
||||
'$ balena tags --release b376b0e544e9429483b656490e5b9443b4349bd6',
|
||||
];
|
||||
|
||||
public static usage = 'tags';
|
||||
|
||||
public static flags = {
|
||||
fleet: {
|
||||
...cf.fleet,
|
||||
|
@ -78,8 +78,6 @@ export default class TunnelCmd extends Command {
|
||||
}),
|
||||
};
|
||||
|
||||
public static usage = 'tunnel <deviceOrFleet>';
|
||||
|
||||
public static flags = {
|
||||
port: Flags.string({
|
||||
description:
|
||||
|
@ -27,8 +27,6 @@ export default class UtilAvailableDrivesCmd extends Command {
|
||||
Does not list system drives.
|
||||
`;
|
||||
|
||||
public static usage = 'util available-drives';
|
||||
|
||||
public static flags = {
|
||||
help: cf.help,
|
||||
};
|
||||
|
@ -49,8 +49,6 @@ export default class VersionCmd extends Command {
|
||||
`$ balena -v`,
|
||||
];
|
||||
|
||||
public static usage = 'version';
|
||||
|
||||
public static offlineCompatible = true;
|
||||
|
||||
public static flags = {
|
||||
|
@ -27,8 +27,6 @@ export default class WhoamiCmd extends Command {
|
||||
|
||||
public static examples = ['$ balena whoami'];
|
||||
|
||||
public static usage = 'whoami';
|
||||
|
||||
public static authenticated = true;
|
||||
|
||||
public async run() {
|
||||
|
34
src/help.ts
34
src/help.ts
@ -14,9 +14,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import type { Command } from '@oclif/core';
|
||||
import { Help } from '@oclif/core';
|
||||
import * as indent from 'indent-string';
|
||||
import { getChalk } from './utils/lazy';
|
||||
import type { ResolvableReturnType } from 'balena-sdk/typings/utils';
|
||||
|
||||
// Partially overrides standard implementation of help plugin
|
||||
// https://github.com/oclif/plugin-help/blob/master/src/index.ts
|
||||
@ -37,8 +39,6 @@ function getHelpSubject(args: string[]): string | undefined {
|
||||
}
|
||||
|
||||
export default class BalenaHelp extends Help {
|
||||
public static usage: 'help [command]';
|
||||
|
||||
public async showHelp(argv: string[]) {
|
||||
const chalk = getChalk();
|
||||
const subject = getHelpSubject(argv);
|
||||
@ -96,9 +96,9 @@ export default class BalenaHelp extends Help {
|
||||
})
|
||||
.filter((c): c is (typeof commands)[0] => !!c);
|
||||
|
||||
let usageLength = 0;
|
||||
let cmdLength = 0;
|
||||
for (const cmd of primaryCommands) {
|
||||
usageLength = Math.max(usageLength, cmd.usage?.length || 0);
|
||||
cmdLength = Math.max(cmdLength, cmd.id.length);
|
||||
}
|
||||
|
||||
let additionalCmdSection: string[];
|
||||
@ -112,16 +112,15 @@ export default class BalenaHelp extends Help {
|
||||
// Find longest usage, and pad usage of first command in each category
|
||||
// This is to ensure that both categories align visually
|
||||
for (const cmd of additionalCommands) {
|
||||
usageLength = Math.max(usageLength, cmd.usage?.length || 0);
|
||||
cmdLength = Math.max(cmdLength, cmd.id.length);
|
||||
}
|
||||
|
||||
if (
|
||||
typeof primaryCommands[0].usage === 'string' &&
|
||||
typeof additionalCommands[0].usage === 'string'
|
||||
typeof primaryCommands[0].id === 'string' &&
|
||||
typeof additionalCommands[0].id === 'string'
|
||||
) {
|
||||
primaryCommands[0].usage = primaryCommands[0].usage.padEnd(usageLength);
|
||||
additionalCommands[0].usage =
|
||||
additionalCommands[0].usage.padEnd(usageLength);
|
||||
primaryCommands[0].id = primaryCommands[0].id.padEnd(cmdLength);
|
||||
additionalCommands[0].id = additionalCommands[0].id.padEnd(cmdLength);
|
||||
}
|
||||
|
||||
additionalCmdSection = [
|
||||
@ -145,7 +144,7 @@ prevent exit with an error as per Deprecation Policy
|
||||
See: https://git.io/JRHUW#deprecation-policy`,
|
||||
],
|
||||
];
|
||||
globalOps[0][0] = globalOps[0][0].padEnd(usageLength);
|
||||
globalOps[0][0] = globalOps[0][0].padEnd(cmdLength);
|
||||
|
||||
const { deprecationPolicyNote, reachingOut } =
|
||||
require('./utils/messages') as typeof import('./utils/messages');
|
||||
@ -185,15 +184,20 @@ See: https://git.io/JRHUW#deprecation-policy`,
|
||||
return outLines.join('\n');
|
||||
}
|
||||
|
||||
protected formatCommands(commands: any[]): string {
|
||||
protected formatCommands(
|
||||
commands: Array<
|
||||
Command.Loadable | ResolvableReturnType<Command.Loadable['load']>
|
||||
>,
|
||||
): string {
|
||||
if (commands.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const body = this.renderList(
|
||||
commands
|
||||
.filter((c) => c.usage != null && c.usage !== '')
|
||||
.map((c) => [c.usage, this.formatDescription(c.description)]),
|
||||
commands.map((c) => [
|
||||
c.id.replaceAll(':', ' '),
|
||||
this.formatDescription(c.description),
|
||||
]),
|
||||
{
|
||||
spacer: '\n',
|
||||
stripAnsi: this.opts.stripAnsi,
|
||||
|
@ -34,13 +34,11 @@ export const trackPromise = new Promise((resolve) => {
|
||||
*/
|
||||
const hook: Hook<'prerun'> = async function (options) {
|
||||
const events = await import('../../events');
|
||||
const usage: string | string[] | undefined = options.Command.usage;
|
||||
const cmdSignature =
|
||||
usage == null ? '*' : typeof usage === 'string' ? usage : usage.join(' ');
|
||||
const cmd = options.Command.id;
|
||||
|
||||
// Intentionally do not await for the track promise here, in order to
|
||||
// run the command tracking and the command itself in parallel.
|
||||
trackResolve(events.trackCommand(cmdSignature));
|
||||
trackResolve(events.trackCommand(cmd));
|
||||
};
|
||||
|
||||
export default hook;
|
||||
|
@ -15,33 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is a partial copy-and-paste of
|
||||
* @oclif/plugin-help/command/CommandHelp, which is used to generate oclif's
|
||||
* command help output.
|
||||
*/
|
||||
export class CommandHelp {
|
||||
constructor(public command: { args?: { [name: string]: any } }) {}
|
||||
|
||||
protected arg(name: string, required: boolean): string {
|
||||
name = name.toUpperCase();
|
||||
if (required) {
|
||||
return `${name}`;
|
||||
}
|
||||
return `[${name}]`;
|
||||
}
|
||||
|
||||
public defaultUsage(): string {
|
||||
const argsObject = this.command.args ?? {};
|
||||
|
||||
return Object.entries(argsObject)
|
||||
.filter(([_name, { hidden }]) => !hidden)
|
||||
.map(([name, { required }]) => this.arg(name, required))
|
||||
.join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert e.g. 'env add NAME [VALUE]' to 'env add <name> [value]' */
|
||||
/** Convert e.g. 'env set NAME [VALUE]' to 'env set <name> [value]' */
|
||||
export function capitanoizeOclifUsage(
|
||||
oclifUsage: string | string[] | undefined,
|
||||
): string {
|
||||
|
Loading…
Reference in New Issue
Block a user