Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Feb 2018 01:57:38 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329786 - head/stand/lua
Message-ID:  <201802220157.w1M1vc59052956@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu Feb 22 01:57:38 2018
New Revision: 329786
URL: https://svnweb.freebsd.org/changeset/base/329786

Log:
  lualoader: Attach cli command functions to cli module
  
  Instead of the global namespace, let's attach these to the cli module. Other
  users, including the "local" module, can attach functions to the cli module
  at will to add other cli commands and things will still Just Work.
  
  This distills down the candidates for functions that may be invoked via the
  cli to a minimal set (boot, autoboot, arguments), rather than any function
  that happens to live in the global lua namespace.

Modified:
  head/stand/lua/cli.lua

Modified: head/stand/lua/cli.lua
==============================================================================
--- head/stand/lua/cli.lua	Thu Feb 22 01:50:30 2018	(r329785)
+++ head/stand/lua/cli.lua	Thu Feb 22 01:57:38 2018	(r329786)
@@ -64,24 +64,6 @@ local parse_boot_args = function(argv, with_kernel)
 	end
 end
 
--- Globals
-
-function boot(...)
-	local cmd_name, argv = cli.arguments(...)
-	local kernel, argstr = parse_boot_args(argv)
-	if kernel ~= nil then
-		loader.perform("unload")
-		config.selectkernel(kernel)
-	end
-	core.boot(argstr)
-end
-
-function autoboot(...)
-	local cmd_name, argv = cli.arguments(...)
-	local argstr = parse_boot_args(argv, false)
-	core.autoboot(argstr)
-end
-
 -- Declares a global function cli_execute that attempts to dispatch the
 -- arguments passed as a lua function. This gives lua a chance to intercept
 -- builtin CLI commands like "boot"
@@ -94,7 +76,7 @@ function cli_execute(...)
 	end
 
 	local cmd_name = argv[1]
-	local cmd = _G[cmd_name]
+	local cmd = cli[cmd_name]
 	if cmd ~= nil and type(cmd) == "function" then
 		-- Pass argv wholesale into cmd. We could omit argv[0] since the
 		-- traditional reasons for including it don't necessarily apply,
@@ -109,6 +91,23 @@ end
 
 -- Module exports
 
+function cli.boot(...)
+	local cmd_name, argv = cli.arguments(...)
+	local kernel, argstr = parse_boot_args(argv)
+	if kernel ~= nil then
+		loader.perform("unload")
+		config.selectkernel(kernel)
+	end
+	core.boot(argstr)
+end
+
+function cli.autoboot(...)
+	local cmd_name, argv = cli.arguments(...)
+	local argstr = parse_boot_args(argv, false)
+	core.autoboot(argstr)
+end
+
+-- Used for splitting cli varargs into cmd_name and the rest of argv
 function cli.arguments(...)
 	local argv = {...}
 	local cmd_name = ""



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802220157.w1M1vc59052956>