Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add balena update command for updating the CLI #2634

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Help from '@oclif/plugin-help';
import { Help } from '@oclif/core';
import { HelpFormatter } from '@oclif/core/lib/help/formatter';
import * as indent from 'indent-string';
import { getChalk } from './utils/lazy';
import { renderList } from '@oclif/plugin-help/lib/list';
import { ExpectedError } from './errors';

// Partially overrides standard implementation of help plugin
Expand All @@ -39,9 +39,11 @@ function getHelpSubject(args: string[]): string | undefined {
}

export default class BalenaHelp extends Help {
public helpFormatter = new HelpFormatter(this.config);

public static usage: 'help [command]';

public showHelp(argv: string[]) {
public async showHelp(argv: string[]) {
const chalk = getChalk();
const subject = getHelpSubject(argv);
if (!subject) {
Expand All @@ -52,7 +54,7 @@ export default class BalenaHelp extends Help {

const command = this.config.findCommand(subject);
if (command) {
this.showCommandHelp(command);
await this.showCommandHelp(command);
return;
}

Expand Down Expand Up @@ -187,14 +189,15 @@ See: https://git.io/JRHUW#deprecation-policy`,
return '';
}

const body = renderList(
const body = this.helpFormatter.renderList(
commands
.filter((c) => c.usage != null && c.usage !== '')
.map((c) => [c.usage, this.formatDescription(c.description)]),
{
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
indentation: 2,
multiline: true,
},
);

Expand Down
6 changes: 4 additions & 2 deletions lib/utils/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type * as BalenaSdk from 'balena-sdk';
import type { Chalk } from 'chalk';
import type * as visuals from 'resin-cli-visuals';
import type * as CliForm from 'resin-cli-form';
import type { ux } from 'cli-ux';
import type { ux } from '@oclif/core';

// Equivalent of _.once but avoiding the need to import lodash for lazy deps
const once = <T>(fn: () => T) => {
Expand Down Expand Up @@ -57,7 +57,9 @@ export const getCliForm = once(
() => require('resin-cli-form') as typeof CliForm,
);

export const getCliUx = once(() => require('cli-ux').ux as typeof ux);
export const getCliUx = once(
() => require('@oclif/core/lib/cli-ux') as typeof ux,
);

// Directly export stripIndent as we always use it immediately, but importing just `stripIndent` reduces startup time
export const stripIndent =
Expand Down