]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - stand/lua/cli.lua.8
Merge llvm-project release/18.x llvmorg-18.1.1-0-gdba2a75e9c7e
[FreeBSD/FreeBSD.git] / stand / lua / cli.lua.8
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 July 24, 2021
28 .Dt CLI.LUA 8
29 .Os
30 .Sh NAME
31 .Nm cli.lua
32 .Nd FreeBSD Lua CLI module
33 .Sh DESCRIPTION
34 .Nm
35 contains the main functionality required to add new CLI commands, which can be
36 executed at the loader prompt.
37 .Pp
38 Before hooking into the functionality provided by
39 .Nm ,
40 it must be included with a statement such as the following:
41 .Pp
42 .Dl local cli = require("cli")
43 .Ss Adding new commands
44 New loader commands may be created by adding functions to the object returned by
45 requiring the
46 .Nm
47 module.
48 .Pp
49 For instance:
50 .Pp
51 .Bd -literal -offset indent -compact
52 local cli = require("cli")
53
54 cli.foo = function(...)
55         -- Expand args to command name and the rest of argv.  These arguments
56         -- are pushed directly to the stack by loader, then handed off to
57         -- cli_execute.  cli_execute then passes them on to the invoked
58         -- function, where they appear as varargs that must be peeled apart into
59         -- their respective components.
60         local _, argv = cli.arguments(...)
61
62         print("This is the foo command!")
63         for k, v in ipairs(argv) do
64                 print("arg #" .. tostring(k) .. ": '" .. v .. "'")
65         end
66         -- Perform a loader command directly.  This will not get dispatched back
67         -- to Lua, so it is acceptable to have a function of the exact same name
68         -- in loader.  Lua will have the first chance to handle any commands
69         -- executed at the loader prompt.
70         loader.perform("foo")
71 end
72 .Ed
73 .Pp
74 This function may be invoked by a user at the loader prompt by simply typing
75 .Ic foo .
76 Arguments may be passed to it as usual, space-delimited.
77 .Ss Default Commands
78 The
79 .Nm
80 module provides the following default commands:
81 .Bl -bullet
82 .\"-width toggle-module -offset indent
83 .It
84 .Ic autoboot
85 .It
86 .Ic boot
87 .It
88 .Ic boot-conf
89 .It
90 .Ic reload-conf
91 .It
92 .Ic disable-device
93 .It
94 .Ic disable-module
95 .It
96 .Ic enable-module
97 .It
98 .Ic toggle-module
99 .It
100 .Ic show-module-options
101 .El
102 .Pp
103 For
104 .Ic autoboot ,
105 .Ic boot ,
106 and
107 .Ic boot-conf ,
108 the
109 .Xr core.lua 8
110 module will load all ELF modules as-needed before executing the equivalent
111 built-in loader commands.
112 All non-kernel arguments to these commands are passed in the same order to the
113 loader command.
114 .Pp
115 The
116 .Ic reload-conf
117 command will reload the configuration from disk.
118 This is useful if you have manually changed currdev and would like to easily
119 reload the configuration from the new device.
120 .Pp
121 The
122 .Ic enable-module ,
123 .Ic disable-module ,
124 and
125 .Ic toggle-module
126 commands manipulate the list of modules to be loaded along with the kernel.
127 Modules blacklisted are considered disabled by
128 .Ic toggle-module .
129 These commands will override any such restriction as needed.
130 The
131 .Ic show-module-options
132 command will dump the list of modules that loader has been made aware of and
133 any applicable options using paged output.
134 .Pp
135 The
136 .Ic disable-device
137 command sets the environment variable that disables the device argument.
138 .Ss Exported Functions
139 The following functions are exported from
140 .Nm :
141 .Bl -tag -width cli.arguments -offset indent
142 .It Fn cli.arguments ...
143 Takes varargs passed on the stack from
144 .Xr loader 8
145 to
146 .Ic cli_execute ,
147 splits them out into two return values: the command name, traditionally argv[0],
148 and the rest of argv.
149 .El
150 .Sh SEE ALSO
151 .Xr loader.conf 5 ,
152 .Xr core.lua 8 ,
153 .Xr loader 8
154 .Sh AUTHORS
155 The
156 .Nm
157 file was originally written by
158 .An Kyle Evans Aq Mt kevans@FreeBSD.org .