task_args.ts

view source

Declarations
#

11 declarations

CliTaskArgs
#

task_args.ts view source

CliTaskArgs import type {CliTaskArgs} from '@fuzdev/gro/task_args.js';

The task the CLI names and its args, parsed from the CLI args.

task_name

The first positional arg: a builtin name, TASK_VERB, or '' for none.

type string

task_path

The path after TASK_VERB, null when absent or for any other task_name.

type string | null

args

type Args

has_forwarded_flag
#

task_args.ts view source

(forwarded_argv: string[], name: string, ignore_case?: boolean): boolean import {has_forwarded_flag} from '@fuzdev/gro/task_args.js';

Whether forwarded_argv names the flag name, by a scan of flag names, not a parse: --name, --name=…, --no-name, or --no-name=…, and a one-character name also as a short flag starting -name, like -o or -odist (not a later letter of a group like -wo). Tasks use it to drop a flag of their own that the user's forwarded text overrides.

forwarded_argv

the verbatim forwarded args, from to_forwarded_argv

type string[]

name

the flag name without dashes

type string

ignore_case?

match the long forms case-insensitively, for tools like tsc

type boolean
optional default false

returns

boolean

merge_forwarded_args
#

task_args.ts view source

(args: Args | undefined, forwarded: Args): Args import {merge_forwarded_args} from '@fuzdev/gro/task_args.js';

Merges forwarded args over args, moving each forwarded key after every key of args. args_parse resolves a no-x pair given both ways to the later key, so a forwarded --color overrides a direct -C (an alias of no-color), where a spread keeps the overridden key at its original position. Keys match by spelling, not by schema alias, so a forwarded alias (-n) doesn't displace a direct canonical key (--name), which args_parse prefers.

args

the direct args, if any, not mutated

type Args | undefined

forwarded

the args forwarded to this command, which win over args

type Args

returns

Args

a new object with the keys of args not in forwarded, then the keys of forwarded

RUN_TASK_NAME
#

task_args.ts view source

internal

"run" import {RUN_TASK_NAME} from '@fuzdev/gro/task_args.js';

The builtin whose script args the CLI leaves unparsed, gro run <path> ...rest, and which it runs like node, printing no timings.

to_forwarded_args
#

task_args.ts view source

(command: string, raw_rest_args: readonly string[], root: string): Args import {to_forwarded_args} from '@fuzdev/gro/task_args.js';

Gets the parsed args forwarded to the Gro task command, like gro test given gro check -- gro test --coverage, or {} when none are. Outside tools get verbatim args with to_forwarded_argv instead.

command

gro and the task name, from to_task_command

type string

raw_rest_args

the CLI args from the first -- on, from to_raw_rest_args

type readonly string[]

root

the project root a section's task path is relative to

type string

returns

Args

throws

  • TaskError - when a `gro` section is malformed, see `to_forwarded_args_by_command`

to_forwarded_args_by_command
#

task_args.ts view source

(raw_rest_args: readonly string[], root: string): Record<string, Args | undefined> import {to_forwarded_args_by_command} from '@fuzdev/gro/task_args.js';

Parses each Gro task section of raw_rest_args, those after a -- whose first arg is gro, into args keyed by gro and the task name: -- gro test --a is keyed gro test, and -- gro task src/lib/x.task.ts --a is keyed by gro task and the normalized path. Other sections are left verbatim for outside tools, see to_forwarded_argv. When a task has several sections, the last one wins.

raw_rest_args

the CLI args from the first -- on, from to_raw_rest_args

type readonly string[]

root

the project root a section's task path is relative to

type string

returns

Record<string, Args | undefined>

the forwarded args of each Gro task command

throws

  • TaskError - when a `gro` section names no task, a `gro task` section no path, a section names a path without `gro task` or a task with the removed `gro/` prefix, or a flag replaces a section's positional args

to_forwarded_argv
#

task_args.ts view source

(command: string, raw_rest_args: readonly string[]): string[] import {to_forwarded_argv} from '@fuzdev/gro/task_args.js';

Gets the verbatim args forwarded to the outside tool command, unparsed, from the section after a -- whose first arg is command, the last one when several are. Given gro check -- eslint --max-warnings -1 -- tsc --noEmit, 'eslint' returns ['--max-warnings', '-1']. Gro tasks get parsed args with to_forwarded_args instead. A literal -- can't be forwarded, as it separates the sections.

command

the tool's CLI name, the section's first arg

type string

raw_rest_args

the CLI args from the first -- on, from to_raw_rest_args

type readonly string[]

returns

string[]

the args after command, empty when no section names it

to_forwarded_flag_value
#

task_args.ts view source

(forwarded_argv: string[], name: string, short?: string | undefined): string | null import {to_forwarded_flag_value} from '@fuzdev/gro/task_args.js';

Gets the value of the last flag name in forwarded_argv, by a scan, not a parse: --name value or --name=value, and for a one-character short, -short value or -shortvalue, not inside a group of short flags like -wo dir.

forwarded_argv

the verbatim forwarded args, from to_forwarded_argv

type string[]

name

the long flag name without dashes

type string

short?

the one-character short flag name, if any

type string
optional

returns

string | null

the value, or null when the flag is absent or has no value

to_implicit_forwarded_argv
#

task_args.ts view source

(task_name: string, cli_args: readonly string[], root: string, command?: string | undefined): string[] import {to_implicit_forwarded_argv} from '@fuzdev/gro/task_args.js';

Gets the verbatim args of the first section after a -- for a tool run by task_name without naming it, like gro test -- --watch for vitest, only when task_name is the task the CLI invoked, so a nested task gets none. A first section starting with gro (a Gro task's) or with command (an explicit section, read by to_forwarded_argv) is none.

task_name

the asking task's name, a builtin name or a normalized task path

type string

cli_args

the args after the CLI's own path, as in the args host module

type readonly string[]

root

the project root a task path in cli_args is relative to

type string

command?

the tool's CLI name, whose explicit section isn't implicit

type string
optional

returns

string[]

the first section's args, empty when absent or not for task_name

to_raw_rest_args
#

task_args.ts view source

(cli_args: readonly string[]): string[] import {to_raw_rest_args} from '@fuzdev/gro/task_args.js';

Gets the array of raw string args starting with the first --, if any. gro run <path> ...rest has none, as everything after the path is the script's.

cli_args

the args after the CLI's own path, as in the args host module

type readonly string[]

returns

string[]

to_task_args
#

task_args.ts view source

(cli_args: readonly string[]): CliTaskArgs import {to_task_args} from '@fuzdev/gro/task_args.js';

Parses the task and its args from the CLI args, ignoring anything after any --. gro task <path> consumes one more positional, the path, and refuses a flag before it. gro run [--help] <path> ...rest refuses any other flag before the path and appends the path and rest verbatim to the positionals, unparsed and including any --, so the script gets exactly what follows its path.

cli_args

the args after the CLI's own path, the task name first, as in the args host module

type readonly string[]

returns

CliTaskArgs

throws

  • TaskError - when a flag replaces the positional args, like `--_` or `--no-_`, `gro run` has a flag other than `--help` before its path, or `gro task` has a flag before its path or one other than `--help` with none

Depends on
#

Imported by
#