Skip to content

Alias Expansion

Chris Hall edited this page Jan 9, 2020 · 4 revisions

Aliases can be defined in both masterplans and planfiles using similar syntax.

There's two important things to remember when defining aliases:

  1. The first alias with a particular name defined is the only alias that will work.
  2. Aliases are only expanded from the command line.

What this means, in essence, is that aliases are designed as a user convenience and user aliases (from masterplans) will override any defined in planfiles.

Aliases defined in masterplans are much more powerful than those from planfiles. Aliases from masterplans can specify an entire "plan stack"1 as well as arguments to that plan.

Take the follow alias as an example:

define_alias '2-add-2', 'calculator add -- 2 2'

When used on the command line (mastermind 2-add-2) it's expanded out as if the user had actually typed: mastermind calculator add -- 2 2.

Aliases are expanded recursively. So, aliases can be defined that reference other aliases:

define_alias 'foo', 'foobar'
define_alias 'bar', 'foo sub'

In this case, mastermind bar would expand to mastermind foobar sub.

Care should be taken here as circular references or self-references be avoided. For example, the following aliases would expand forever and fail:

define_alias 'foo', 'foo bar' # self-referential

define_alias 'bar', 'baz'
define_alias 'baz', 'bar' # circular-reference

As demonstrated earlier, aliases add arguments to the command line. However, how they add arguments may not be immediately obvious. Take the following alias:

define_alias 'plus-2', 'calculator calculate -- 2 +'

If executed like mastermind plus-2 -- 5 - as you can probably guess from how the alias is written - the resulting expansion would be as if mastermind calculator calculate -- 2 + 5 had been invoked instead.

1: The sequence of plan names needed to get to an executable plan.

Clone this wiki locally