xref: /freebsd/stand/lua/cli.lua.8 (revision df21a004be237a1dccd03c7b47254625eea62fa9)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd March 29, 2025
28.Dt CLI.LUA 8
29.Os
30.Sh NAME
31.Nm cli.lua
32.Nd bootloader command line interpreter module
33.Sh DESCRIPTION
34.Nm
35contains the main functionality required to add new CLI commands, which can be
36executed at the loader prompt.
37.Pp
38Before hooking into the functionality provided by
39.Nm ,
40it must be included with a statement such as the following:
41.Pp
42.Dl local cli = require("cli")
43.Ss Adding new commands
44New loader commands may be created by adding functions to the object returned by
45requiring the
46.Nm
47module.
48.Pp
49For instance:
50.Pp
51.Bd -literal -offset indent -compact
52local cli = require("cli")
53
54cli.foo = function(...)
55	-- Expand args to command name and the rest of argv.
56	-- These arguments are pushed directly to the stack by
57	-- loader, then handed off to cli_execute.  cli_execute
58	-- then passes them on to the invoked function, where
59	-- they appear as varargs that must be peeled apart into
60	-- their respective components.
61	local _, argv = cli.arguments(...)
62
63	print("This is the foo command!")
64	for k, v in ipairs(argv) do
65		print("arg #" .. tostring(k) .. ": '" .. v .. "'")
66	end
67	-- Perform a loader command directly.  This will not get
68	-- dispatched back to Lua, so it is acceptable to have a
69	-- function of the exact same name in loader.  Lua will
70	-- have the first chance to handle any commands executed
71	-- at the loader prompt.
72	loader.perform("foo")
73end
74.Ed
75.Pp
76This function may be invoked by a user at the loader prompt by simply typing
77.Ic foo .
78Arguments may be passed to it as usual, space-delimited.
79.Ss Default Commands
80The
81.Nm
82module provides the following default commands:
83.Bl -bullet
84.\"-width toggle-module -offset indent
85.It
86.Ic autoboot
87.It
88.Ic boot
89.It
90.Ic boot-conf
91.It
92.Ic reload-conf
93.It
94.Ic disable-device
95.It
96.Ic disable-module
97.It
98.Ic enable-module
99.It
100.Ic toggle-module
101.It
102.Ic show-module-options
103.El
104.Pp
105For
106.Ic autoboot ,
107.Ic boot ,
108and
109.Ic boot-conf ,
110the
111.Xr core.lua 8
112module will load all ELF modules as-needed before executing the equivalent
113built-in loader commands.
114All non-kernel arguments to these commands are passed in the same order to the
115loader command.
116.Pp
117The
118.Ic reload-conf
119command will reload the configuration from disk.
120This is useful if you have manually changed currdev and would like to easily
121reload the configuration from the new device.
122.Pp
123The
124.Ic enable-module ,
125.Ic disable-module ,
126and
127.Ic toggle-module
128commands manipulate the list of modules to be loaded along with the kernel.
129Modules blacklisted are considered disabled by
130.Ic toggle-module .
131These commands will override any such restriction as needed.
132The
133.Ic show-module-options
134command will dump the list of modules that loader has been made aware of and
135any applicable options using paged output.
136.Pp
137The
138.Ic disable-device
139command sets the environment variable that disables the device argument.
140.Ss Exported Functions
141The following functions are exported from
142.Nm :
143.Bl -tag -width cli.arguments -offset indent
144.It Fn cli.arguments ...
145Takes varargs passed on the stack from
146.Xr loader 8
147to
148.Ic cli_execute ,
149splits them out into two return values: the command name, traditionally argv[0],
150and the rest of argv.
151.El
152.Sh SEE ALSO
153.Xr loader.conf 5 ,
154.Xr core.lua 8 ,
155.Xr loader 8
156.Sh AUTHORS
157The
158.Nm
159file was originally written by
160.An Kyle Evans Aq Mt kevans@FreeBSD.org .
161