Install

Bash Completion

The -generate-bash-conf option outputs the bash completion configuration to stdout. Either manually copy it or you can for instance use tee:

blade -generate-bash-conf | sudo tee /etc/bash_completion.d/blade

Note: The location of the bash completion configuration might differ depending on distribution and platform

Note: zsh can also run bash completion commands.

Getting Started

Create a Bladerunner file. All targets will be executed with the current directory set to the directory containing the Bladerunner file. The blade command will search for the Bladerunner file in the file tree.

To create a hello target define a function on the target table. In the function you can execute arbitrary lua code.

function target.hello()
print("hello world")
end

To execute the target run

blade hello

Lets expand the example by processing command line parameters.

function target.hello(use)
use = use or "lua"
if use == "shell" then
blade.sh([[echo "hello world"]])
elseif use == "lua" then
print("hello world")
else
print("unknown option: " .. use)
end
end

Run the following to test the new target

blade hello
blade hello lua
blade hello shell
blade hello foo

Targets

Defining new blade targets is done by adding functions to the target table.

function target.install(...)
-- If the ... notation is used arguments are assigned to the arg variable
-- arg.n is special and returns the number of elements in arg
-- To test: blade install -i --dev /var/log
print("Number of inputs: ", arg.n)
for index, value in ipairs(arg) do
print(index, "=", value)
end
end

target: help

The only built in target is help. It will print an automatically generated help message. It is possible to target help messages, see blade.help

blade help

target:

If not defining a target when running blade the help target will be executed. This can be overridden by setting blade.default.

Example:

-- set the default target to `test`
blade.default = target.test
-- run a custom function for the default target
function blade.default()
-- default target code
end

Setup and teardown

It is possible to run setup and teardown code that is run before and after the blade target. Returning false in the setup or teardown will abort the target execution.

blade.setup

Example:

function blade.setup()
-- setup code
end

teardown

Example:

function blade.teardown()
-- teardown code
end

Blade API

A small set of convince functions are provided, attached to a lua table called blade.

blade.shell(shell) => shell

The default shell used is bash, setting the blade.shell variable overrides that.

Example:

sh = blade.shell("zsh")
print(sh)
-- prints 'zsh'

blade.sh(command) => exitStatus, stdout, stderr

Run arbitrary shell commands, executed in bash by default. If the command returns a non zero exit code the target execution will be aborted. The command is echoed to stdout, to suppress this use blade._sh instead.