1d4f74556SKyle Evans.\" 2*4d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 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.\" 2707c4b78dSWarner Losh.Dd July 24, 2021 28d4f74556SKyle Evans.Dt CLI.LUA 8 29d4f74556SKyle Evans.Os 30d4f74556SKyle Evans.Sh NAME 31d4f74556SKyle Evans.Nm cli.lua 32d4f74556SKyle Evans.Nd FreeBSD Lua CLI module 33d4f74556SKyle Evans.Sh DESCRIPTION 34d4f74556SKyle Evans.Nm 35d4f74556SKyle Evanscontains the main functionality required to add new CLI commands, which can be 36d4f74556SKyle Evansexecuted at the loader prompt. 37d4f74556SKyle Evans.Pp 38d4f74556SKyle EvansBefore hooking into the functionality provided by 39d4f74556SKyle Evans.Nm , 40d4f74556SKyle Evansit must be included with a statement such as the following: 41d4f74556SKyle Evans.Pp 42d4f74556SKyle Evans.Dl local cli = require("cli") 43d4f74556SKyle Evans.Ss Adding new commands 44d4f74556SKyle EvansNew loader commands may be created by adding functions to the object returned by 45d4f74556SKyle Evansrequiring the 46d4f74556SKyle Evans.Nm 47d4f74556SKyle Evansmodule. 48d4f74556SKyle Evans.Pp 49d4f74556SKyle EvansFor instance: 50d4f74556SKyle Evans.Pp 51d4f74556SKyle Evans.Bd -literal -offset indent -compact 52d4f74556SKyle Evanslocal cli = require("cli") 53d4f74556SKyle Evans 54d4f74556SKyle Evanscli.foo = function(...) 55d4f74556SKyle Evans -- Expand args to command name and the rest of argv. These arguments 56d4f74556SKyle Evans -- are pushed directly to the stack by loader, then handed off to 57d4f74556SKyle Evans -- cli_execute. cli_execute then passes them on to the invoked 58d4f74556SKyle Evans -- function, where they appear as varargs that must be peeled apart into 59d4f74556SKyle Evans -- their respective components. 60d4f74556SKyle Evans local _, argv = cli.arguments(...) 61d4f74556SKyle Evans 62d4f74556SKyle Evans print("This is the foo command!") 63d4f74556SKyle Evans for k, v in ipairs(argv) do 64d4f74556SKyle Evans print("arg #" .. tostring(k) .. ": '" .. v .. "'") 65d4f74556SKyle Evans end 66d4f74556SKyle Evans -- Perform a loader command directly. This will not get dispatched back 67d4f74556SKyle Evans -- to Lua, so it is acceptable to have a function of the exact same name 68d4f74556SKyle Evans -- in loader. Lua will have the first chance to handle any commands 69d4f74556SKyle Evans -- executed at the loader prompt. 70d4f74556SKyle Evans loader.perform("foo") 71d4f74556SKyle Evansend 72d4f74556SKyle Evans.Ed 73d4f74556SKyle Evans.Pp 74d4f74556SKyle EvansThis function may be invoked by a user at the loader prompt by simply typing 75d4f74556SKyle Evans.Ic foo . 76d4f74556SKyle EvansArguments may be passed to it as usual, space-delimited. 77d4f74556SKyle Evans.Ss Default Commands 784634bb1fSKyle EvansThe 79d4f74556SKyle Evans.Nm 804634bb1fSKyle Evansmodule provides the following default commands: 814634bb1fSKyle Evans.Bl -bullet 824634bb1fSKyle Evans.\"-width toggle-module -offset indent 834634bb1fSKyle Evans.It 844634bb1fSKyle Evans.Ic autoboot 854634bb1fSKyle Evans.It 864634bb1fSKyle Evans.Ic boot 874634bb1fSKyle Evans.It 884634bb1fSKyle Evans.Ic boot-conf 894634bb1fSKyle Evans.It 904634bb1fSKyle Evans.Ic reload-conf 914634bb1fSKyle Evans.It 926b51baf6SWarner Losh.Ic disable-device 934634bb1fSKyle Evans.It 944634bb1fSKyle Evans.Ic disable-module 954634bb1fSKyle Evans.It 9607c4b78dSWarner Losh.Ic enable-module 9707c4b78dSWarner Losh.It 984634bb1fSKyle Evans.Ic toggle-module 997ed84fa1SKyle Evans.It 1007ed84fa1SKyle Evans.Ic show-module-options 1014634bb1fSKyle Evans.El 102af876563SKyle Evans.Pp 103af876563SKyle EvansFor 104af876563SKyle Evans.Ic autoboot , 105af876563SKyle Evans.Ic boot , 106af876563SKyle Evansand 107af876563SKyle Evans.Ic boot-conf , 108af876563SKyle Evansthe 109d4f74556SKyle Evans.Xr core.lua 8 110d4f74556SKyle Evansmodule will load all ELF modules as-needed before executing the equivalent 111d4f74556SKyle Evansbuilt-in loader commands. 112d4f74556SKyle EvansAll non-kernel arguments to these commands are passed in the same order to the 113d4f74556SKyle Evansloader command. 114af876563SKyle Evans.Pp 115af876563SKyle EvansThe 116af876563SKyle Evans.Ic reload-conf 117af876563SKyle Evanscommand will reload the configuration from disk. 118af876563SKyle EvansThis is useful if you have manually changed currdev and would like to easily 119af876563SKyle Evansreload the configuration from the new device. 1204634bb1fSKyle Evans.Pp 1214634bb1fSKyle EvansThe 1224634bb1fSKyle Evans.Ic enable-module , 1234634bb1fSKyle Evans.Ic disable-module , 1244634bb1fSKyle Evansand 1254634bb1fSKyle Evans.Ic toggle-module 1264634bb1fSKyle Evanscommands manipulate the list of modules to be loaded along with the kernel. 1274634bb1fSKyle EvansModules blacklisted are considered disabled by 1284634bb1fSKyle Evans.Ic toggle-module . 1294634bb1fSKyle EvansThese commands will override any such restriction as needed. 1307ed84fa1SKyle EvansThe 1317ed84fa1SKyle Evans.Ic show-module-options 1327ed84fa1SKyle Evanscommand will dump the list of modules that loader has been made aware of and 1337ed84fa1SKyle Evansany applicable options using paged output. 13407c4b78dSWarner Losh.Pp 13507c4b78dSWarner LoshThe 1366b51baf6SWarner Losh.Ic disable-device 13707c4b78dSWarner Loshcommand sets the environment variable that disables the device argument. 138d4f74556SKyle Evans.Ss Exported Functions 139d4f74556SKyle EvansThe following functions are exported from 140d4f74556SKyle Evans.Nm : 141d4f74556SKyle Evans.Bl -tag -width cli.arguments -offset indent 142d4f74556SKyle Evans.It Fn cli.arguments ... 143d4f74556SKyle EvansTakes varargs passed on the stack from 144d4f74556SKyle Evans.Xr loader 8 145d4f74556SKyle Evansto 146d4f74556SKyle Evans.Ic cli_execute , 147d4f74556SKyle Evanssplits them out into two return values: the command name, traditionally argv[0], 148d4f74556SKyle Evansand the rest of argv. 149d4f74556SKyle Evans.El 150d4f74556SKyle Evans.Sh SEE ALSO 151d4f74556SKyle Evans.Xr loader.conf 5 , 152d4f74556SKyle Evans.Xr core.lua 8 , 153d4f74556SKyle Evans.Xr loader 8 154d4f74556SKyle Evans.Sh AUTHORS 155d4f74556SKyle EvansThe 156d4f74556SKyle Evans.Nm 157d4f74556SKyle Evansfile was originally written by 158d4f74556SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 159