Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
CLI.LUA(8)		  BSD System Manager's Manual		    CLI.LUA(8)

NAME
     cli.lua --	FreeBSD	Lua CLI	module

DESCRIPTION
     cli.lua contains the main functionality required to add new CLI commands,
     which can be executed at the loader prompt.

     Before hooking into the functionality provided by cli.lua,	it must	be in-
     cluded with a statement such as the following:

	   local cli = require("cli")

   Adding new commands
     New loader	commands may be	created	by adding functions to the object re-
     turned by requiring the cli.lua module.

     For instance:

	   local cli = require("cli")

	   cli.foo = function(...)
		   -- Expand args to command name and the rest of argv.	 These arguments
		   -- are pushed directly to the stack by loader, then handed off to
		   -- cli_execute.  cli_execute	then passes them on to the invoked
		   -- function,	where they appear as varargs that must be peeled apart into
		   -- their respective components.
		   local _, argv = cli.arguments(...)

		   print("This is the foo command!")
		   for k, v in ipairs(argv) do
			   print("arg #" .. tostring(k)	.. ": '" .. v .. "'")
		   end
		   -- Perform a	loader command directly.  This will not	get dispatched back
		   -- to Lua, so it is acceptable to have a function of	the exact same name
		   -- in loader.  Lua will have	the first chance to handle any commands
		   -- executed at the loader prompt.
		   loader.perform("foo")
	   end

     This function may be invoked by a user at the loader prompt by simply
     typing foo.  Arguments may	be passed to it	as usual, space-delimited.

   Default Commands
     As	of present, the	cli.lua	module by default provides commands for
     autoboot, boot, and boot-conf. In all three cases,	the core.lua(8)	module
     will load all ELF modules as-needed before	executing the equivalent
     built-in loader commands.	All non-kernel arguments to these commands are
     passed in the same	order to the loader command.

   Exported Functions
     The following functions are exported from cli.lua:

	   cli.arguments(...)
			  Takes	varargs	passed on the stack from loader(8) to
			  cli_execute, splits them out into two	return values:
			  the command name, traditionally argv[0], and the
			  rest of argv.

SEE ALSO
     loader.conf(5), core.lua(8), loader(8)

AUTHORS
     The cli.lua file was originally written by	Kyle Evans
     <kevans@FreeBSD.org>.

BSD			       October 31, 2018				   BSD

NAME | DESCRIPTION | SEE ALSO | AUTHORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=cli.lua&sektion=8&manpath=FreeBSD+12.1-RELEASE+and+Ports>

home | help