magus v0.4.2 is out. See what's new
¶ View generated markdown
4 min read

charm

Constructors for charm values: RFC 6902 JSON Patches over a target's argv (see docs/charms.md).

Naming convention: import the module under its bare name (import "charm"), reach members with a backslash, and call methods in camelCase: charm\someMethod.

Methods

append

Append vals to the end of the argv.

Signature: charm\append(vals) -> Charm - source

Parameter Type Optional Description
vals []string

Returns: map[string]any

prepend

Insert vals at the front of the argv, in order.

Signature: charm\prepend(vals) -> Charm - source

Parameter Type Optional Description
vals []string

Returns: map[string]any

after

Insert vals immediately after the first argv element equal to anchor.

Signature: charm\after(argv, anchor, vals) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string
vals []string

Returns: map[string]any

before

Insert vals immediately before the first argv element equal to anchor.

Signature: charm\before(argv, anchor, vals) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string
vals []string

Returns: map[string]any

set

Replace the first argv element equal to anchor with val.

Signature: charm\set(argv, anchor, val) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string
val string

Returns: map[string]any

drop

Drop (remove) the first argv element equal to anchor.

Signature: charm\drop(argv, anchor) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string

Returns: map[string]any

afterFunc

Insert vals after the first argv element for which fn(s) is truthy.

Signature: charm\afterFunc(argv, fn, vals) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback
vals []string

Returns: map[string]any

beforeFunc

Insert vals before the first argv element for which fn(s) is truthy.

Signature: charm\beforeFunc(argv, fn, vals) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback
vals []string

Returns: map[string]any

setFunc

Replace the first argv element for which fn(s) is truthy with val.

Signature: charm\setFunc(argv, fn, val) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback
val string

Returns: map[string]any

dropFunc

Drop (remove) the first argv element for which fn(s) is truthy.

Signature: charm\dropFunc(argv, fn) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback

Returns: map[string]any

path

Return the JSON Pointer ("/N") of the first argv element equal to anchor - the index, auto-calculated, for hand-built move/copy/test ops.

Signature: charm\path(argv, anchor) -> string - source

Parameter Type Optional Description
argv []string
anchor string

Returns: string

pathFunc

Return the JSON Pointer ("/N") of the first argv element for which fn(s) is truthy.

Signature: charm\pathFunc(argv, fn) -> string - source

Parameter Type Optional Description
argv []string
fn Callback

Returns: string

move

Move the first argv element equal to anchor to the JSON Pointer to ("/-" end, "/0" front, or charm.path(...)).

Signature: charm\move(argv, anchor, to) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string
to string

Returns: map[string]any

moveFunc

Move the first argv element for which fn(s) is truthy to the JSON Pointer to.

Signature: charm\moveFunc(argv, fn, to) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback
to string

Returns: map[string]any

copy

Copy the first argv element equal to anchor to the JSON Pointer to ("/-" end, "/0" front, or charm.path(...)).

Signature: charm\copy(argv, anchor, to) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string
to string

Returns: map[string]any

copyFunc

Copy the first argv element for which fn(s) is truthy to the JSON Pointer to.

Signature: charm\copyFunc(argv, fn, to) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback
to string

Returns: map[string]any

test

Guard: assert the first argv element equal to anchor is still at its position when the patch applies (else the run errors).

Signature: charm\test(argv, anchor) -> Charm - source

Parameter Type Optional Description
argv []string
anchor string

Returns: map[string]any

testFunc

Guard: assert the first argv element for which fn(s) is truthy is still at its position when the patch applies.

Signature: charm\testFunc(argv, fn) -> Charm - source

Parameter Type Optional Description
argv []string
fn Callback

Returns: map[string]any

generatedreference/buzz/charmmodulestdlibmagusfile
Last updated (4f8cc295)
Earlier changes on this page (6)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. See targets.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. See targets.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). See operations.

Charm

An execution modifier attached with : (lint:rw) that changes how a target runs, not which one; the built-in rw flips a check-only target to mutate in place, and ci always strips it. See charms.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.