From owner-svn-src-all@freebsd.org Thu Feb 22 01:57:39 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F2DE6F1840A; Thu, 22 Feb 2018 01:57:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A63FC80D17; Thu, 22 Feb 2018 01:57:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A12F620C3F; Thu, 22 Feb 2018 01:57:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1M1vcHq052957; Thu, 22 Feb 2018 01:57:38 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1M1vc59052956; Thu, 22 Feb 2018 01:57:38 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802220157.w1M1vc59052956@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 22 Feb 2018 01:57:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329786 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329786 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Feb 2018 01:57:39 -0000 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 = ""