xref: /freebsd/stand/lua/cli.lua.8 (revision 7ed84fa14b00cdacfe9b43019cba7a14b33af352)
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*7ed84fa1SKyle Evans.Dd December 17, 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
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
944634bb1fSKyle Evans.Ic enable-module
954634bb1fSKyle Evans.It
964634bb1fSKyle Evans.Ic disable-module
974634bb1fSKyle Evans.It
984634bb1fSKyle Evans.Ic toggle-module
99*7ed84fa1SKyle Evans.It
100*7ed84fa1SKyle 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.
130*7ed84fa1SKyle EvansThe
131*7ed84fa1SKyle Evans.Ic show-module-options
132*7ed84fa1SKyle Evanscommand will dump the list of modules that loader has been made aware of and
133*7ed84fa1SKyle Evansany applicable options using paged output.
134d4f74556SKyle Evans.Ss Exported Functions
135d4f74556SKyle EvansThe following functions are exported from
136d4f74556SKyle Evans.Nm :
137d4f74556SKyle Evans.Bl -tag -width cli.arguments -offset indent
138d4f74556SKyle Evans.It Fn cli.arguments ...
139d4f74556SKyle EvansTakes varargs passed on the stack from
140d4f74556SKyle Evans.Xr loader 8
141d4f74556SKyle Evansto
142d4f74556SKyle Evans.Ic cli_execute ,
143d4f74556SKyle Evanssplits them out into two return values: the command name, traditionally argv[0],
144d4f74556SKyle Evansand the rest of argv.
145d4f74556SKyle Evans.El
146d4f74556SKyle Evans.Sh SEE ALSO
147d4f74556SKyle Evans.Xr loader.conf 5 ,
148d4f74556SKyle Evans.Xr core.lua 8 ,
149d4f74556SKyle Evans.Xr loader 8
150d4f74556SKyle Evans.Sh AUTHORS
151d4f74556SKyle EvansThe
152d4f74556SKyle Evans.Nm
153d4f74556SKyle Evansfile was originally written by
154d4f74556SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org .
155