loader.lua (aedd6be5c7c3096828fafa6c1528f3966b9e3aa5) loader.lua (9f71d421c89dde4e5a642f4555bcd20558fd91b0)
1--
2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
4-- All rights reserved.
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:

--- 23 unchanged lines hidden (view full) ---

32local password = require("password")
33
34-- Declares a global function cli_execute that attempts to dispatch the
35-- arguments passed as a lua function. This gives lua a chance to intercept
36-- builtin CLI commands like "boot"
37function cli_execute(...)
38 local argv = {...}
39 -- Just in case...
1--
2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
4-- All rights reserved.
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:

--- 23 unchanged lines hidden (view full) ---

32local password = require("password")
33
34-- Declares a global function cli_execute that attempts to dispatch the
35-- arguments passed as a lua function. This gives lua a chance to intercept
36-- builtin CLI commands like "boot"
37function cli_execute(...)
38 local argv = {...}
39 -- Just in case...
40 if (#argv == 0) then
40 if #argv == 0 then
41 loader.command(...)
42 return
43 end
44
45 local cmd_name = argv[1]
46 local cmd = _G[cmd_name]
41 loader.command(...)
42 return
43 end
44
45 local cmd_name = argv[1]
46 local cmd = _G[cmd_name]
47 if (cmd ~= nil) and (type(cmd) == "function") then
47 if cmd ~= nil and type(cmd) == "function" then
48 -- Pass argv wholesale into cmd. We could omit argv[0] since the
49 -- traditional reasons for including it don't necessarily apply,
50 -- it may not be totally redundant if we want to have one global
51 -- handling multiple commands
52 cmd(...)
53 else
54 loader.command(...)
55 end
56
57end
58
59config.load()
60password.check()
61menu.run()
48 -- Pass argv wholesale into cmd. We could omit argv[0] since the
49 -- traditional reasons for including it don't necessarily apply,
50 -- it may not be totally redundant if we want to have one global
51 -- handling multiple commands
52 cmd(...)
53 else
54 loader.command(...)
55 end
56
57end
58
59config.load()
60password.check()
61menu.run()