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.\" 27d4f74556SKyle Evans.\" $FreeBSD$ 28d4f74556SKyle Evans.\" 2907c4b78dSWarner Losh.Dd July 24, 2021 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 804634bb1fSKyle EvansThe 81d4f74556SKyle Evans.Nm 824634bb1fSKyle Evansmodule provides the following default commands: 834634bb1fSKyle Evans.Bl -bullet 844634bb1fSKyle Evans.\"-width toggle-module -offset indent 854634bb1fSKyle Evans.It 864634bb1fSKyle Evans.Ic autoboot 874634bb1fSKyle Evans.It 884634bb1fSKyle Evans.Ic boot 894634bb1fSKyle Evans.It 904634bb1fSKyle Evans.Ic boot-conf 914634bb1fSKyle Evans.It 924634bb1fSKyle Evans.Ic reload-conf 934634bb1fSKyle Evans.It 946b51baf6SWarner Losh.Ic disable-device 954634bb1fSKyle Evans.It 964634bb1fSKyle Evans.Ic disable-module 974634bb1fSKyle Evans.It 9807c4b78dSWarner Losh.Ic enable-module 9907c4b78dSWarner Losh.It 1004634bb1fSKyle Evans.Ic toggle-module 1017ed84fa1SKyle Evans.It 1027ed84fa1SKyle Evans.Ic show-module-options 1034634bb1fSKyle Evans.El 104af876563SKyle Evans.Pp 105af876563SKyle EvansFor 106af876563SKyle Evans.Ic autoboot , 107af876563SKyle Evans.Ic boot , 108af876563SKyle Evansand 109af876563SKyle Evans.Ic boot-conf , 110af876563SKyle Evansthe 111d4f74556SKyle Evans.Xr core.lua 8 112d4f74556SKyle Evansmodule will load all ELF modules as-needed before executing the equivalent 113d4f74556SKyle Evansbuilt-in loader commands. 114d4f74556SKyle EvansAll non-kernel arguments to these commands are passed in the same order to the 115d4f74556SKyle Evansloader command. 116af876563SKyle Evans.Pp 117af876563SKyle EvansThe 118af876563SKyle Evans.Ic reload-conf 119af876563SKyle Evanscommand will reload the configuration from disk. 120af876563SKyle EvansThis is useful if you have manually changed currdev and would like to easily 121af876563SKyle Evansreload the configuration from the new device. 1224634bb1fSKyle Evans.Pp 1234634bb1fSKyle EvansThe 1244634bb1fSKyle Evans.Ic enable-module , 1254634bb1fSKyle Evans.Ic disable-module , 1264634bb1fSKyle Evansand 1274634bb1fSKyle Evans.Ic toggle-module 1284634bb1fSKyle Evanscommands manipulate the list of modules to be loaded along with the kernel. 1294634bb1fSKyle EvansModules blacklisted are considered disabled by 1304634bb1fSKyle Evans.Ic toggle-module . 1314634bb1fSKyle EvansThese commands will override any such restriction as needed. 1327ed84fa1SKyle EvansThe 1337ed84fa1SKyle Evans.Ic show-module-options 1347ed84fa1SKyle Evanscommand will dump the list of modules that loader has been made aware of and 1357ed84fa1SKyle Evansany applicable options using paged output. 13607c4b78dSWarner Losh.Pp 13707c4b78dSWarner LoshThe 1386b51baf6SWarner Losh.Ic disable-device 13907c4b78dSWarner Loshcommand sets the environment variable that disables the device argument. 140d4f74556SKyle Evans.Ss Exported Functions 141d4f74556SKyle EvansThe following functions are exported from 142d4f74556SKyle Evans.Nm : 143d4f74556SKyle Evans.Bl -tag -width cli.arguments -offset indent 144d4f74556SKyle Evans.It Fn cli.arguments ... 145d4f74556SKyle EvansTakes varargs passed on the stack from 146d4f74556SKyle Evans.Xr loader 8 147d4f74556SKyle Evansto 148d4f74556SKyle Evans.Ic cli_execute , 149d4f74556SKyle Evanssplits them out into two return values: the command name, traditionally argv[0], 150d4f74556SKyle Evansand the rest of argv. 151d4f74556SKyle Evans.El 152d4f74556SKyle Evans.Sh SEE ALSO 153d4f74556SKyle Evans.Xr loader.conf 5 , 154d4f74556SKyle Evans.Xr core.lua 8 , 155d4f74556SKyle Evans.Xr loader 8 156d4f74556SKyle Evans.Sh AUTHORS 157d4f74556SKyle EvansThe 158d4f74556SKyle Evans.Nm 159d4f74556SKyle Evansfile was originally written by 160d4f74556SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 161