args.ts

Declarations
#

11 declarations

view source

Args
#

args.ts view source

Args

These extend the CLI args for tasks. Anything can be assigned to a task's args. It's just a mutable POJO dictionary. Downstream tasks will see args that upstream events mutate, unless invoke_task is called with modified args. Upstream tasks can use listeners to respond to downstream events and values. It's a beautiful mutable spaghetti mess. cant get enough The raw CLI args are handled by mri - https://github.com/lukeed/mri

_

type Array<string>

help

type boolean

ArgSchema
#

ArgValue
#

parse_args
#

args.ts view source

<TOutput extends Record<string, ArgValue> = Args, TInput extends Record<string, ArgValue> = Args>(unparsed_args: TInput, schema: ZodType<TOutput, TInput, $ZodTypeInternals<TOutput, TInput>>): ZodSafeParseResult<...>

Parses user input args with a Zod schema. Sets the correct source of truth for no- versions of args, to the opposite of the unprefixed versions when not included in unparsed_args. This is needed because CLI args don't have a normal way of setting falsy values, so instead the args parser mri will pass through the truthy versions of args without the no- prefix. When we declare task args schemas, we need include both versions with their defaults to get correct --help output. Parsing like this also ensures data consistency for both versions because mri only creates one. A simpler implementation could replace mri, but it handles some finicky details well.

unparsed_args

type TInput

schema

type ZodType<TOutput, TInput, $ZodTypeInternals<TOutput, TInput>>

returns

ZodSafeParseResult<TOutput>

print_command_args
#

serialize_args
#

to_forwarded_args
#

args.ts view source

(command: string, raw_rest_args?: string[] | undefined, cache?: Record<string, Args | undefined>): Args

Parses process.argv for the specified command, so given gro taskname arg1 --arg2 -- eslint eslintarg1 --eslintarg2 -- tsc --tscarg1 --tscarg2 the command 'eslint' returns eslintarg1 --eslintarg2 and 'tsc' returns --tscarg1 and --tscarg2.

command

type string

raw_rest_args?

type string[] | undefined
optional

cache

type Record<string, Args | undefined>
default to_forwarded_args_by_command(raw_rest_args)

returns

Args

to_forwarded_args_by_command
#

args.ts view source

(raw_rest_args?: string[]): Record<string, Args | undefined>

raw_rest_args

type string[]
default to_raw_rest_args()

returns

Record<string, Args | undefined>

to_implicit_forwarded_args
#

args.ts view source

(command_to_strip?: string | undefined, raw_rest_args?: string[]): Args

Gets all args after the first -- without assuming a command name. This is useful for tasks that want to forward args directly to a tool without requiring users to specify the tool name explicitly. Optionally strips a specific command name if present for backward compatibility.

command_to_strip?

type string | undefined
optional

raw_rest_args

type string[]
default to_raw_rest_args()

returns

Args

examples

Example 1

to_raw_rest_args
#

args.ts view source

(argv?: string[]): string[]

Gets the array of raw string args starting with the first --, if any.

argv

type string[]
default process.argv

returns

string[]

to_task_args
#

args.ts view source

(argv?: string[]): { task_name: string; args: Args; }

Parses task_name and args from process.argv using mri, ignoring anything after any --.

argv

type string[]
default process.argv

returns

{ task_name: string; args: Args; }

Imported by
#