Shell#
Different functions exist to enrich the beaver build system with your own commands, options and flags.
- opt(long_name, short_name = nil, default:)#
Define an option that can be passed to the command line. The return value is what is passed on the command line
- Parameters:
long_name – The option name to be used on the command line, preceded by
--.short_name – Optionally a short name of 1 letter as an alias for the option, on the command line preceded by
-.
- Param:
default: A default value if the option is not specified on the command line.
- Returns:
The value passed on the command line.
- Return type:
Return type depends on the default value. If no default value is passed, the return type will be a String.
Example
value = opt("option", "o", default: 1)$ beaver -- --option=5 $ beaver -- -o4 $ beaver -- -o 3
- flag(long_name, short_name = nil, default:)#
Define a flag on the command line that evaluates to true or false. The flag can be negated by preceding it with “no-“.
- Parameters:
long_name – The option name to be used on the command line, preceded by
--.short_name – Optionally a short name of 1 letter as an alias for the option, on the command line preceded by
-.
- Param:
default: A default value if the option is not specified on the command line.
- Return type:
Boolean
Example
value = flag("has-cairo") puts value
$ beaver -- --has-cairo true $ beaver -- --no-has-cairo false
- cmd(name, &command)#
Define a command. Commands can be called from the command line just like the standard “run” or “test” commands.
The first command defined is also the default command. :param name: The name on the command. This is how it is called from the command line. :param command: A code block to execute when the command is called.
Example
cmd "hello-world" do puts "Hello world" end
$ beaver hello-world Hello world
Utilities#
- sh(*args)#
The
shfunction prints out the shell command it runs and then executes it. When an error occurs in the shell command, it raises an exception.- Parameters:
args – The shell command.
Example
# We can pass a string to the sh function containing the command sh "echo 'Hello world!'" # Or we can pass an array with each argument individually, beaver will then # automatically quote all the arguments sh "echo" "Hello world!"
- split_args(args)#
Turns a string of arguments into an array of arguments as would be parsed by the shell.
- Parameters:
args – The arguments to split.
Example
split_args("a b 35 'Hello World'") #=> ["a", "b", "35", "Hello World"]
- which(prog)#
Gets the path to a program available in
$PATH.- Parameters:
prog – The name of the program.