Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ FLAGS
Leading slashes and a version prefix in the path are
optional. For example, "actor-runs/{runId}" and
"/v2/actor-runs/{runId}" are both accepted.
-H, --header=<value> Additional HTTP header(s). Pass a
-H, --header=<value> Additional HTTP header(s). Pass a
single "key:value" string, or a JSON object like
'{"X-Foo": "bar", "X-Baz": "qux"}' to send multiple
headers. The flag can only be used once; use the JSON form
for multiple headers.
-l, --list-endpoints List all available Apify API
endpoints.
-X, --method=<option> The HTTP method to use. Defaults
-X, --method=<option> The HTTP method to use. Defaults
to GET.
<options: GET|POST|PUT|PATCH|DELETE>
-p, --params=<value> Query parameters as a JSON object,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/command-framework/help/CommandHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class CommandHelp extends BaseCommandRenderer {
.split('\n')
.map((line) => {
// For lines that don't start with a short flag, add 4 spaces to indent them further, and align with the flags that also have a short form
if (!/^-[a-z]/.test(line.trim())) {
if (!/^-[a-z]/i.test(line.trim())) {
return ` ${line}`;
}

Expand Down
25 changes: 25 additions & 0 deletions test/local/lib/command-framework/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type BuiltApifyCommand as _BuiltApifyCommand,
commandRegistry,
} from '../../../../src/lib/command-framework/apify-command.js';
import { Flags } from '../../../../src/lib/command-framework/flags.js';
import {
registerCommandForHelpGeneration,
renderHelpForCommand,
Expand Down Expand Up @@ -63,6 +64,17 @@ class FakeActorPushData extends BuiltApifyCommand {
];
}

class FakeMixedFlags extends BuiltApifyCommand {
static override name = 'mixed-flags' as const;
static override description = 'A command with lowercase, uppercase and long-only flags.';
static override flags = {
body: Flags.string({ char: 'd', description: 'The request body.' }),
header: Flags.string({ char: 'H', description: 'Additional HTTP header(s).' }),
method: Flags.string({ char: 'X', description: 'The HTTP method to use.' }),
profile: Flags.string({ description: 'The stored account to use for this command.' }),
};
}

class FakeUtility extends BuiltApifyCommand {
static override name = 'utility' as const;
static override description = 'A utility command.';
Expand Down Expand Up @@ -132,6 +144,19 @@ describe('Help rendering', () => {
expect(output).toContain('Pass --template to skip the prompt.');
});

test('aligns short flags of any case in the same column', () => {
registerCommandForHelpGeneration('apify', FakeMixedFlags);
const output = stripAnsi(renderHelpForCommand(FakeMixedFlags));

const flagLines = output.split('\n').filter((line) => /^\s+(-\w, )?--/.test(line));
const shortFlagColumns = flagLines.filter((line) => /^\s+-\w, --/.test(line)).map((line) => line.indexOf('-'));
const longFlagColumns = flagLines.map((line) => line.indexOf('--'));

expect(shortFlagColumns).toHaveLength(3);
expect(new Set(shortFlagColumns).size).toBe(1);
expect(new Set(longFlagColumns).size).toBe(1);
});

test('renders example descriptions as shell-style # comments', () => {
registerCommandForHelpGeneration('apify', FakeRunsAbort);
const output = stripAnsi(renderHelpForCommand(FakeRunsAbort));
Expand Down
Loading