1d4f74556SKyle Evans.\" 2d4f74556SKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3d4f74556SKyle Evans.\" 4d4f74556SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 5d4f74556SKyle Evans.\" 6d4f74556SKyle Evans.\" Redistribution and use in source and binary forms, with or without 7d4f74556SKyle Evans.\" modification, are permitted provided that the following conditions 8d4f74556SKyle Evans.\" are met: 9d4f74556SKyle Evans.\" 1. Redistributions of source code must retain the above copyright 10d4f74556SKyle Evans.\" notice, this list of conditions and the following disclaimer. 11d4f74556SKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 12d4f74556SKyle Evans.\" notice, this list of conditions and the following disclaimer in the 13d4f74556SKyle Evans.\" documentation and/or other materials provided with the distribution. 14d4f74556SKyle Evans.\" 15d4f74556SKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16d4f74556SKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17d4f74556SKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18d4f74556SKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19d4f74556SKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20d4f74556SKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21d4f74556SKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22d4f74556SKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23d4f74556SKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24d4f74556SKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25d4f74556SKyle Evans.\" SUCH DAMAGE. 26d4f74556SKyle Evans.\" 27d4f74556SKyle Evans.\" $FreeBSD$ 28d4f74556SKyle Evans.\" 29*af876563SKyle Evans.Dd September 13, 2019 30d4f74556SKyle Evans.Dt CLI.LUA 8 31d4f74556SKyle Evans.Os 32d4f74556SKyle Evans.Sh NAME 33d4f74556SKyle Evans.Nm cli.lua 34d4f74556SKyle Evans.Nd FreeBSD Lua CLI module 35d4f74556SKyle Evans.Sh DESCRIPTION 36d4f74556SKyle Evans.Nm 37d4f74556SKyle Evanscontains the main functionality required to add new CLI commands, which can be 38d4f74556SKyle Evansexecuted at the loader prompt. 39d4f74556SKyle Evans.Pp 40d4f74556SKyle EvansBefore hooking into the functionality provided by 41d4f74556SKyle Evans.Nm , 42d4f74556SKyle Evansit must be included with a statement such as the following: 43d4f74556SKyle Evans.Pp 44d4f74556SKyle Evans.Dl local cli = require("cli") 45d4f74556SKyle Evans.Ss Adding new commands 46d4f74556SKyle EvansNew loader commands may be created by adding functions to the object returned by 47d4f74556SKyle Evansrequiring the 48d4f74556SKyle Evans.Nm 49d4f74556SKyle Evansmodule. 50d4f74556SKyle Evans.Pp 51d4f74556SKyle EvansFor instance: 52d4f74556SKyle Evans.Pp 53d4f74556SKyle Evans.Bd -literal -offset indent -compact 54d4f74556SKyle Evanslocal cli = require("cli") 55d4f74556SKyle Evans 56d4f74556SKyle Evanscli.foo = function(...) 57d4f74556SKyle Evans -- Expand args to command name and the rest of argv. These arguments 58d4f74556SKyle Evans -- are pushed directly to the stack by loader, then handed off to 59d4f74556SKyle Evans -- cli_execute. cli_execute then passes them on to the invoked 60d4f74556SKyle Evans -- function, where they appear as varargs that must be peeled apart into 61d4f74556SKyle Evans -- their respective components. 62d4f74556SKyle Evans local _, argv = cli.arguments(...) 63d4f74556SKyle Evans 64d4f74556SKyle Evans print("This is the foo command!") 65d4f74556SKyle Evans for k, v in ipairs(argv) do 66d4f74556SKyle Evans print("arg #" .. tostring(k) .. ": '" .. v .. "'") 67d4f74556SKyle Evans end 68d4f74556SKyle Evans -- Perform a loader command directly. This will not get dispatched back 69d4f74556SKyle Evans -- to Lua, so it is acceptable to have a function of the exact same name 70d4f74556SKyle Evans -- in loader. Lua will have the first chance to handle any commands 71d4f74556SKyle Evans -- executed at the loader prompt. 72d4f74556SKyle Evans loader.perform("foo") 73d4f74556SKyle Evansend 74d4f74556SKyle Evans.Ed 75d4f74556SKyle Evans.Pp 76d4f74556SKyle EvansThis function may be invoked by a user at the loader prompt by simply typing 77d4f74556SKyle Evans.Ic foo . 78d4f74556SKyle EvansArguments may be passed to it as usual, space-delimited. 79d4f74556SKyle Evans.Ss Default Commands 80d4f74556SKyle EvansAs of present, the 81d4f74556SKyle Evans.Nm 82d4f74556SKyle Evansmodule by default provides commands for 8383f7a74cSKyle Evans.Ic autoboot , 8483f7a74cSKyle Evans.Ic boot , 85*af876563SKyle Evans.Ic boot-conf , 86d4f74556SKyle Evansand 87*af876563SKyle Evans.Ic reload-conf . 88*af876563SKyle Evans.Pp 89*af876563SKyle EvansFor 90*af876563SKyle Evans.Ic autoboot , 91*af876563SKyle Evans.Ic boot , 92*af876563SKyle Evansand 93*af876563SKyle Evans.Ic boot-conf , 94*af876563SKyle Evansthe 95d4f74556SKyle Evans.Xr core.lua 8 96d4f74556SKyle Evansmodule will load all ELF modules as-needed before executing the equivalent 97d4f74556SKyle Evansbuilt-in loader commands. 98d4f74556SKyle EvansAll non-kernel arguments to these commands are passed in the same order to the 99d4f74556SKyle Evansloader command. 100*af876563SKyle Evans.Pp 101*af876563SKyle EvansThe 102*af876563SKyle Evans.Ic reload-conf 103*af876563SKyle Evanscommand will reload the configuration from disk. 104*af876563SKyle EvansThis is useful if you have manually changed currdev and would like to easily 105*af876563SKyle Evansreload the configuration from the new device. 106d4f74556SKyle Evans.Ss Exported Functions 107d4f74556SKyle EvansThe following functions are exported from 108d4f74556SKyle Evans.Nm : 109d4f74556SKyle Evans.Bl -tag -width cli.arguments -offset indent 110d4f74556SKyle Evans.It Fn cli.arguments ... 111d4f74556SKyle EvansTakes varargs passed on the stack from 112d4f74556SKyle Evans.Xr loader 8 113d4f74556SKyle Evansto 114d4f74556SKyle Evans.Ic cli_execute , 115d4f74556SKyle Evanssplits them out into two return values: the command name, traditionally argv[0], 116d4f74556SKyle Evansand the rest of argv. 117d4f74556SKyle Evans.El 118d4f74556SKyle Evans.Sh SEE ALSO 119d4f74556SKyle Evans.Xr loader.conf 5 , 120d4f74556SKyle Evans.Xr core.lua 8 , 121d4f74556SKyle Evans.Xr loader 8 122d4f74556SKyle Evans.Sh AUTHORS 123d4f74556SKyle EvansThe 124d4f74556SKyle Evans.Nm 125d4f74556SKyle Evansfile was originally written by 126d4f74556SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 127