Skip to main content
function Task.alias
def Task.alias(
*,
defaults: dict[str, typing.Any] = ,
summary: str = ,
description: str = ,
display_name: str = ,
group: list[str] = [],
name: str = 
) -> Task
Define an alias of this task with overridden arg defaults. The alias is a new top-level CLI command that shares this task’s implementation and traits, but exposes overridden defaults for one or more of its args. The base task is undisturbed — both commands coexist, and a CLI flag still wins over the alias’s default (so aspect buildifier --formatter-target=X overrides the alias default).

Naming

Assign the result to a snake_case variable; the CLI command name is derived from the variable. The base task’s name is never inherited. Use name = "explicit-name" to override.

Constraints

  • defaults keys must already exist on the base task.
  • The value type must match the base arg’s variant (args.stringstr, args.intint, args.string_listlist[str], etc.). args.string(values = [...]) re-checks membership on the new default.
  • args.trailing_var_args carries no default in the schema and cannot be overridden via defaults.
  • Aliases cannot add args beyond the base. Use task() if you need to.

Example

load("@aspect//format.axl", "format")

buildifier = format.alias(
    defaults = {
        "formatter_target": "@buildifier_prebuilt//buildifier",
    },
    summary = "Format Starlark files with buildifier.",
)

def config(ctx: ConfigContext):
    ctx.tasks.add(buildifier)