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