Skip to content

Commit 482d0b2

Browse files
authored
chore!: move from yargs to node:util (#871)
BREAKING CHANGE: The shorthand flag for `--input-file` in the `call` command has been changed from `-if` to `-f`. Our argument parsing was changed from yargs to the built-in one from nodejs. This does come with some caveats (specifically aliases like `-if` will be interpreted as setting the flags `-i` and `-f` (if both are defined) or as `f` as the value of the `-i` flag.).
1 parent 1f29f18 commit 482d0b2

File tree

16 files changed

+940
-657
lines changed

16 files changed

+940
-657
lines changed

features/test-implementations/1.setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ Given<TestWorld>(/the local actor is pushed to the Apify platform/i, { timeout:
243243
pushedActorIds.push(this.testActor.name);
244244
} else {
245245
// This throws on errors
246-
result.unwrap();
246+
const err = result.unwrapErr();
247+
248+
throw new Error(`Failed to push actor: ${err.message}`);
247249
}
248250
});

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@
110110
"tiged": "~2.12.7",
111111
"which": "^5.0.0",
112112
"widest-line": "^5.0.0",
113-
"wrap-ansi": "^9.0.0",
114-
"yargs": "^17.7.2"
113+
"wrap-ansi": "^9.0.0"
115114
},
116115
"devDependencies": {
117116
"@apify/eslint-config": "^1.0.0",
@@ -135,7 +134,6 @@
135134
"@types/node": "^22.0.0",
136135
"@types/semver": "^7.5.8",
137136
"@types/which": "^3.0.4",
138-
"@types/yargs": "^17.0.33",
139137
"@yarnpkg/core": "^4.1.2",
140138
"apify": "^3.2.4",
141139
"chai": "^4.4.1",

src/commands/_register.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export const apifyCommands = [
5757
RunCommand,
5858
ValidateInputSchemaCommand,
5959
HelpCommand,
60+
61+
// test commands
62+
// (await import('./_testCommands/_FlagTests.js')).FlagTest,
6063
] as const satisfies (typeof BuiltApifyCommand)[];
6164

6265
export const actorCommands = [
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
2+
import { Flags } from '../../lib/command-framework/flags.js';
3+
4+
export class FlagTest extends ApifyCommand<typeof FlagTest> {
5+
static override name = '_flag';
6+
7+
static override flags = {
8+
foo: Flags.string({
9+
description: 'Foo flag',
10+
// required: true,
11+
}),
12+
bar: Flags.string({
13+
description: 'Bar flag',
14+
}),
15+
fooBar: Flags.string({
16+
description: 'Foo bar flag',
17+
// required: true,
18+
}),
19+
'spaced message': Flags.string({
20+
description: 'Spaced message flag',
21+
}),
22+
choice: Flags.string({
23+
description: 'Choices flag',
24+
aliases: ['alias1'],
25+
choices: ['1', '2', '3'],
26+
}),
27+
int: Flags.integer({
28+
exclusive: ['foo'],
29+
}),
30+
'space me': Flags.string({
31+
description: 'Space message flag',
32+
exclusive: ['lines-in'],
33+
}),
34+
'lines-in': Flags.integer({
35+
description: 'Lines in flag',
36+
exclusive: ['space me'],
37+
}),
38+
fooBar2: Flags.boolean({
39+
description: 'Foo bar flag',
40+
exclusive: ['lines-in'],
41+
}),
42+
};
43+
44+
override async run() {
45+
console.log(this.flags);
46+
}
47+
}

src/commands/actors/call.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
4242
exclusive: ['input-file'],
4343
}),
4444
'input-file': Flags.string({
45-
aliases: ['if'],
45+
char: 'f',
4646
description:
4747
'Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.',
4848
required: false,

src/commands/cli-management/upgrade.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export class UpgradeCommand extends ApifyCommand<typeof UpgradeCommand> {
7777
const { installMethod } = useCLIMetadata();
7878

7979
if (!result.shouldUpdate || result.currentVersion === DEVELOPMENT_VERSION_MARKER) {
80+
cliDebugPrint('[upgrade] no update needed', {
81+
shouldUpdate: result.shouldUpdate,
82+
currentVersion: result.currentVersion,
83+
});
84+
8085
// Always print, unless the command was called automatically by the CLI for a version check
8186
if (!this.flags.internalAutomaticCall) {
8287
info({ message: `${this.cliName} is up to date 👍 \n` });

0 commit comments

Comments
 (0)