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*4634bb1fSKyle Evans.Dd December 12, 2020 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 80*4634bb1fSKyle EvansThe 81d4f74556SKyle Evans.Nm 82*4634bb1fSKyle Evansmodule provides the following default commands: 83*4634bb1fSKyle Evans.Bl -bullet 84*4634bb1fSKyle Evans.\"-width toggle-module -offset indent 85*4634bb1fSKyle Evans.It 86*4634bb1fSKyle Evans.Ic autoboot 87*4634bb1fSKyle Evans.It 88*4634bb1fSKyle Evans.Ic boot 89*4634bb1fSKyle Evans.It 90*4634bb1fSKyle Evans.Ic boot-conf 91*4634bb1fSKyle Evans.It 92*4634bb1fSKyle Evans.Ic reload-conf 93*4634bb1fSKyle Evans.It 94*4634bb1fSKyle Evans.Ic enable-module 95*4634bb1fSKyle Evans.It 96*4634bb1fSKyle Evans.Ic disable-module 97*4634bb1fSKyle Evans.It 98*4634bb1fSKyle Evans.Ic toggle-module 99*4634bb1fSKyle Evans.El 100af876563SKyle Evans.Pp 101af876563SKyle EvansFor 102af876563SKyle Evans.Ic autoboot , 103af876563SKyle Evans.Ic boot , 104af876563SKyle Evansand 105af876563SKyle Evans.Ic boot-conf , 106af876563SKyle Evansthe 107d4f74556SKyle Evans.Xr core.lua 8 108d4f74556SKyle Evansmodule will load all ELF modules as-needed before executing the equivalent 109d4f74556SKyle Evansbuilt-in loader commands. 110d4f74556SKyle EvansAll non-kernel arguments to these commands are passed in the same order to the 111d4f74556SKyle Evansloader command. 112af876563SKyle Evans.Pp 113af876563SKyle EvansThe 114af876563SKyle Evans.Ic reload-conf 115af876563SKyle Evanscommand will reload the configuration from disk. 116af876563SKyle EvansThis is useful if you have manually changed currdev and would like to easily 117af876563SKyle Evansreload the configuration from the new device. 118*4634bb1fSKyle Evans.Pp 119*4634bb1fSKyle EvansThe 120*4634bb1fSKyle Evans.Ic enable-module , 121*4634bb1fSKyle Evans.Ic disable-module , 122*4634bb1fSKyle Evansand 123*4634bb1fSKyle Evans.Ic toggle-module 124*4634bb1fSKyle Evanscommands manipulate the list of modules to be loaded along with the kernel. 125*4634bb1fSKyle EvansModules blacklisted are considered disabled by 126*4634bb1fSKyle Evans.Ic toggle-module . 127*4634bb1fSKyle EvansThese commands will override any such restriction as needed. 128d4f74556SKyle Evans.Ss Exported Functions 129d4f74556SKyle EvansThe following functions are exported from 130d4f74556SKyle Evans.Nm : 131d4f74556SKyle Evans.Bl -tag -width cli.arguments -offset indent 132d4f74556SKyle Evans.It Fn cli.arguments ... 133d4f74556SKyle EvansTakes varargs passed on the stack from 134d4f74556SKyle Evans.Xr loader 8 135d4f74556SKyle Evansto 136d4f74556SKyle Evans.Ic cli_execute , 137d4f74556SKyle Evanssplits them out into two return values: the command name, traditionally argv[0], 138d4f74556SKyle Evansand the rest of argv. 139d4f74556SKyle Evans.El 140d4f74556SKyle Evans.Sh SEE ALSO 141d4f74556SKyle Evans.Xr loader.conf 5 , 142d4f74556SKyle Evans.Xr core.lua 8 , 143d4f74556SKyle Evans.Xr loader 8 144d4f74556SKyle Evans.Sh AUTHORS 145d4f74556SKyle EvansThe 146d4f74556SKyle Evans.Nm 147d4f74556SKyle Evansfile was originally written by 148d4f74556SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 149