1088b4f5fSWarner Losh-- 2088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3afad05b2SKyle Evans-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 4088b4f5fSWarner Losh-- All rights reserved. 5088b4f5fSWarner Losh-- 6088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 7088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 8088b4f5fSWarner Losh-- are met: 9088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 10088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 11088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 12088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 13088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 14088b4f5fSWarner Losh-- 15088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25088b4f5fSWarner Losh-- SUCH DAMAGE. 26088b4f5fSWarner Losh-- 27088b4f5fSWarner Losh-- $FreeBSD$ 28088b4f5fSWarner Losh-- 29088b4f5fSWarner Losh 30*aedd6be5SKyle Evanslocal config = require("config") 31*aedd6be5SKyle Evanslocal menu = require("menu") 32*aedd6be5SKyle Evanslocal password = require("password") 33088b4f5fSWarner Losh 34afad05b2SKyle Evans-- Declares a global function cli_execute that attempts to dispatch the 35afad05b2SKyle Evans-- arguments passed as a lua function. This gives lua a chance to intercept 36afad05b2SKyle Evans-- builtin CLI commands like "boot" 37afad05b2SKyle Evansfunction cli_execute(...) 38*aedd6be5SKyle Evans local argv = {...} 3962daefa5SKyle Evans -- Just in case... 4062daefa5SKyle Evans if (#argv == 0) then 41*aedd6be5SKyle Evans loader.command(...) 42*aedd6be5SKyle Evans return 4362daefa5SKyle Evans end 4462daefa5SKyle Evans 45*aedd6be5SKyle Evans local cmd_name = argv[1] 46*aedd6be5SKyle Evans local cmd = _G[cmd_name] 47afad05b2SKyle Evans if (cmd ~= nil) and (type(cmd) == "function") then 48afad05b2SKyle Evans -- Pass argv wholesale into cmd. We could omit argv[0] since the 49afad05b2SKyle Evans -- traditional reasons for including it don't necessarily apply, 50afad05b2SKyle Evans -- it may not be totally redundant if we want to have one global 51afad05b2SKyle Evans -- handling multiple commands 52*aedd6be5SKyle Evans cmd(...) 53afad05b2SKyle Evans else 54*aedd6be5SKyle Evans loader.command(...) 55afad05b2SKyle Evans end 56afad05b2SKyle Evans 57afad05b2SKyle Evansend 58afad05b2SKyle Evans 59*aedd6be5SKyle Evansconfig.load() 60*aedd6be5SKyle Evanspassword.check() 61*aedd6be5SKyle Evansmenu.run() 62