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

chore: upgrade oclif to v2 #161

Merged
merged 9 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"/oclif.manifest.json"
],
"dependencies": {
"@oclif/core": "^1.26.2",
"@oclif/core": "^2",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^2.4.7",
"@prantlf/jsonlint": "^11.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { KnockEnv } from "@/lib/helpers/const";
import { withSpinner } from "@/lib/helpers/request";
import { promptToConfirm } from "@/lib/helpers/ux";

export default class Commit extends BaseCommand {
export default class Commit extends BaseCommand<typeof Commit> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change allows us to type this.props more precisely for each command.

static summary = "Commit all changes in development environment.";

static flags = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commit/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseCommand from "@/lib/base-command";
import { withSpinner } from "@/lib/helpers/request";
import { promptToConfirm } from "@/lib/helpers/ux";

export default class CommitPromote extends BaseCommand {
export default class CommitPromote extends BaseCommand<typeof CommitPromote> {
static summary = "Promote all changes to the destination environment.";

static flags = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/knock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const JOKES = [
["Beets.", "Beets who?", "Beets me!"],
];

export default class Knock extends BaseCommand {
export default class Knock extends BaseCommand<typeof Knock> {
// Because, it's a secret :)
static hidden = true;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseCommand from "@/lib/base-command";

export default class Ping extends BaseCommand {
export default class Ping extends BaseCommand<typeof Ping> {
// Deprecated, in favor of the whoami command.
static hidden = true;

Expand Down
17 changes: 10 additions & 7 deletions src/commands/translation/get.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { CliUx, Flags } from "@oclif/core";
import { Args, Flags, ux } from "@oclif/core";

import * as ApiV1 from "@/lib/api-v1";
import BaseCommand from "@/lib/base-command";
import { formatDate } from "@/lib/helpers/date";
import { withSpinner } from "@/lib/helpers/request";
import * as Translation from "@/lib/marshal/translation";

export default class TranslationGet extends BaseCommand {
export default class TranslationGet extends BaseCommand<typeof TranslationGet> {
static summary = "Display a single translation from an environment.";

static description = Translation.translationRefDescription;

static flags = {
environment: Flags.string({
default: "development",
Expand All @@ -21,7 +19,12 @@ export default class TranslationGet extends BaseCommand {
}),
};

static args = [{ name: "translationRef", required: true }];
static args = {
translationRef: Args.string({
description: Translation.translationRefDescription,
required: true,
}),
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main changes in oclif v2. Args are now defined with Args, just like for flags.


static enableJsonFlag = true;

Expand Down Expand Up @@ -82,7 +85,7 @@ export default class TranslationGet extends BaseCommand {
},
];

CliUx.ux.table(rows, {
ux.table(rows, {
key: {
header: "Translation",
minWidth: 24,
Expand All @@ -94,6 +97,6 @@ export default class TranslationGet extends BaseCommand {
});

this.log("");
CliUx.ux.styledJSON(JSON.parse(translation.content));
ux.styledJSON(JSON.parse(translation.content));
}
}
8 changes: 5 additions & 3 deletions src/commands/translation/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CliUx, Flags } from "@oclif/core";
import { Flags, ux } from "@oclif/core";
import { AxiosResponse } from "axios";

import * as ApiV1 from "@/lib/api-v1";
Expand All @@ -13,7 +13,9 @@ import {
import { withSpinner } from "@/lib/helpers/request";
import * as Translation from "@/lib/marshal/translation";

export default class TranslationList extends BaseCommand {
export default class TranslationList extends BaseCommand<
typeof TranslationList
> {
static summary = "Display all translations for an environment.";

static flags = {
Expand Down Expand Up @@ -64,7 +66,7 @@ export default class TranslationList extends BaseCommand {
* Translations list table
*/

CliUx.ux.table(entries, {
ux.table(entries, {
ref: {
header: "Ref",
get: (entry) => Translation.formatRef(entry),
Expand Down
15 changes: 10 additions & 5 deletions src/commands/translation/pull.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flags } from "@oclif/core";
import { Args, Flags } from "@oclif/core";

import * as ApiV1 from "@/lib/api-v1";
import BaseCommand from "@/lib/base-command";
Expand All @@ -16,12 +16,12 @@ import { promptToConfirm, spinner } from "@/lib/helpers/ux";
import * as Translation from "@/lib/marshal/translation";
import { TranslationDirContext } from "@/lib/run-context";

export default class TranslationPull extends BaseCommand {
export default class TranslationPull extends BaseCommand<
typeof TranslationPull
> {
static summary =
"Pull one or more translations from an environment into a local file system.";

static description = Translation.translationRefDescription;

static flags = {
environment: Flags.string({
default: "development",
Expand All @@ -43,7 +43,12 @@ export default class TranslationPull extends BaseCommand {
}),
};

static args = [{ name: "translationRef", required: false }];
static args = {
translationRef: Args.string({
description: Translation.translationRefDescription,
required: false,
}),
};

async run(): Promise<void> {
const target = await Translation.ensureValidCommandTarget(
Expand Down
15 changes: 10 additions & 5 deletions src/commands/translation/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flags } from "@oclif/core";
import { Args, Flags } from "@oclif/core";

import BaseCommand from "@/lib/base-command";
import { KnockEnv } from "@/lib/helpers/const";
Expand All @@ -11,12 +11,12 @@ import * as Translation from "@/lib/marshal/translation";

import TranslationValidate from "./validate";

export default class TranslationPush extends BaseCommand {
export default class TranslationPush extends BaseCommand<
typeof TranslationPush
> {
static summary =
"Push one or more translations from a local file system to Knock.";

static description = Translation.translationRefDescription;

static flags = {
environment: Flags.string({
summary:
Expand All @@ -41,7 +41,12 @@ export default class TranslationPush extends BaseCommand {
}),
};

static args = [{ name: "translationRef", required: false }];
static args = {
translationRef: Args.string({
description: Translation.translationRefDescription,
required: false,
}),
};

async run(): Promise<void> {
const { flags } = this.props;
Expand Down
19 changes: 13 additions & 6 deletions src/commands/translation/validate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Flags } from "@oclif/core";
import { Args, Flags } from "@oclif/core";

import * as ApiV1 from "@/lib/api-v1";
import BaseCommand, { Props } from "@/lib/base-command";
Expand All @@ -10,12 +10,14 @@ import { indentString } from "@/lib/helpers/string";
import { spinner } from "@/lib/helpers/ux";
import * as Translation from "@/lib/marshal/translation";

export default class TranslationValidate extends BaseCommand {
import TranslationPush from "./push";

export default class TranslationValidate extends BaseCommand<
typeof TranslationValidate
> {
static summary =
"Validate one or more translations from a local file system.";

static description = Translation.translationRefDescription;

static flags = {
environment: Flags.string({
summary:
Expand All @@ -34,7 +36,12 @@ export default class TranslationValidate extends BaseCommand {
}),
};

static args = [{ name: "translationRef", required: false }];
static args = {
translationRef: Args.string({
description: Translation.translationRefDescription,
required: false,
}),
};

async run(): Promise<void> {
const target = await Translation.ensureValidCommandTarget(
Expand Down Expand Up @@ -75,7 +82,7 @@ export default class TranslationValidate extends BaseCommand {

static async validateAll(
api: ApiV1.T,
props: Props,
props: Props<typeof TranslationValidate | typeof TranslationPush>,
translations: Translation.TranslationFileData[],
): Promise<SourceError[]> {
// TODO: Throw if a non validation error (e.g. authentication error) instead
Expand Down
2 changes: 1 addition & 1 deletion src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BaseCommand from "@/lib/base-command";
import { withSpinner } from "@/lib/helpers/request";
import { indentString } from "@/lib/helpers/string";

export default class Whoami extends BaseCommand {
export default class Whoami extends BaseCommand<typeof Whoami> {
static summary = "Verify the provided service token.";

static enableJsonFlag = true;
Expand Down
12 changes: 9 additions & 3 deletions src/commands/workflow/activate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Flags } from "@oclif/core";
import { Args, Flags } from "@oclif/core";

import * as ApiV1 from "@/lib/api-v1";
import BaseCommand from "@/lib/base-command";
import { booleanStr } from "@/lib/helpers/flag";
import { withSpinner } from "@/lib/helpers/request";
import { promptToConfirm } from "@/lib/helpers/ux";

export default class WorkflowActivate extends BaseCommand {
export default class WorkflowActivate extends BaseCommand<
typeof WorkflowActivate
> {
static summary = "Activate or deactivate a workflow in a given environment.";

static description = `
Expand All @@ -33,7 +35,11 @@ with \`false\` in order to deactivate it.
}),
};

static args = [{ name: "workflowKey", required: true }];
static args = {
workflowKey: Args.string({
required: true,
}),
};

async run(): Promise<void> {
const { args, flags } = this.props;
Expand Down
17 changes: 11 additions & 6 deletions src/commands/workflow/get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CliUx, Flags } from "@oclif/core";
import { Args, Flags, ux } from "@oclif/core";

import * as ApiV1 from "@/lib/api-v1";
import BaseCommand from "@/lib/base-command";
Expand All @@ -7,7 +7,7 @@ import { withSpinner } from "@/lib/helpers/request";
import * as Conditions from "@/lib/marshal/conditions";
import * as Workflow from "@/lib/marshal/workflow";

export default class WorkflowGet extends BaseCommand {
export default class WorkflowGet extends BaseCommand<typeof WorkflowGet> {
static summary = "Display a single workflow from an environment.";

static flags = {
Expand All @@ -20,7 +20,11 @@ export default class WorkflowGet extends BaseCommand {
}),
};

static args = [{ name: "workflowKey", required: true }];
static args = {
workflowKey: Args.string({
required: true,
}),
};

static enableJsonFlag = true;

Expand Down Expand Up @@ -82,7 +86,7 @@ export default class WorkflowGet extends BaseCommand {
},
];

CliUx.ux.table(rows, {
ux.table(rows, {
key: {
header: "Workflow",
minWidth: 24,
Expand All @@ -95,8 +99,9 @@ export default class WorkflowGet extends BaseCommand {

this.log("");

// Leading space is there intentionally to align the left padding.
if (workflow.steps.length === 0) {
return CliUx.ux.log(" This workflow has no steps to display.");
return ux.log(" This workflow has no steps to display.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
return ux.log(" This workflow has no steps to display.");
return ux.log("This workflow has no steps to display.");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the leading space is there intentionally to align the left spacing in the display. Will add a quick comment.

}

/*
Expand All @@ -105,7 +110,7 @@ export default class WorkflowGet extends BaseCommand {

const steps = workflow.steps.map((step, index) => ({ ...step, index }));

CliUx.ux.table(steps, {
ux.table(steps, {
index: {
header: "Steps",
get: (step) => step.index + 1,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/workflow/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CliUx, Flags } from "@oclif/core";
import { Flags, ux } from "@oclif/core";
import { AxiosResponse } from "axios";

import * as ApiV1 from "@/lib/api-v1";
Expand All @@ -13,7 +13,7 @@ import {
import { withSpinner } from "@/lib/helpers/request";
import * as Workflow from "@/lib/marshal/workflow";

export default class WorkflowList extends BaseCommand {
export default class WorkflowList extends BaseCommand<typeof WorkflowList> {
static summary = "Display all workflows for an environment.";

static flags = {
Expand Down Expand Up @@ -64,7 +64,7 @@ export default class WorkflowList extends BaseCommand {
* Workflows list table
*/

CliUx.ux.table(entries, {
ux.table(entries, {
key: {
header: "Key",
},
Expand Down
10 changes: 7 additions & 3 deletions src/commands/workflow/new.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "node:path";

import { Flags } from "@oclif/core";
import { Args, Flags } from "@oclif/core";
import * as fs from "fs-extra";

import BaseCommand from "@/lib/base-command";
Expand All @@ -9,13 +9,17 @@ import { spinner } from "@/lib/helpers/ux";
import * as Workflow from "@/lib/marshal/workflow";
import { WorkflowDirContext } from "@/lib/run-context";

export default class WorkflowNew extends BaseCommand {
export default class WorkflowNew extends BaseCommand<typeof WorkflowNew> {
static flags = {
steps: Flags.string({ aliases: ["step"] }),
force: Flags.boolean(),
};

static args = [{ name: "workflowKey", required: true }];
static args = {
workflowKey: Args.string({
required: true,
}),
};

// TODO(KNO-3072): Unhide after we move the generator logic to the backend.
static hidden = true;
Expand Down
Loading