mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
New configuration for shell_config
It is now possible to configure each individual command that will be compiled in the shell: ``` shell = { commands = {'ls', 'ver', 'type' } } ``` If not specified, all the available commands will be compiled (which is backwards compatible). Also, the `advanced_shell` attribute is gone, replaced with an `advanced` key in the shell configuration. So write this: ``` shell = { advanced = true } ``` instead of this: ``` advanced_shell = true ```
This commit is contained in:
parent
03dc1d5c1a
commit
788f4e3fd1
@ -3,7 +3,7 @@ local utils = require "utils.utils"
|
||||
local sf = string.format
|
||||
|
||||
-- List of platforms to build
|
||||
local ci_boards = {"ek-lm3s8962", "elua-puc", "mbed", "arm2368"}
|
||||
local ci_boards = {"ek-lm3s8962", "elua-puc", "mbed", "arm2368", "stm32f4discovery"}
|
||||
|
||||
-- Variants to build for each platform
|
||||
-- TODO: is "lualong" also needed here?
|
||||
|
@ -8,7 +8,7 @@ return {
|
||||
cdc = { buf_size = 128 },
|
||||
wofs = true,
|
||||
romfs = true,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
cints = true,
|
||||
luaints = true,
|
||||
|
@ -6,7 +6,7 @@ return {
|
||||
sercon = { uart = "1", speed = 115200, buf_size = 128 },
|
||||
romfs = true,
|
||||
cdc = false,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -6,7 +6,7 @@ return {
|
||||
sercon = { uart = 0, speed = 0 },
|
||||
wofs = true,
|
||||
romfs = true,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
mmcfs = { spi = 0, cs_port = 0, cs_pin = 0 },
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ return {
|
||||
components = {
|
||||
sercon = { uart = 2, speed = 115200 },
|
||||
romfs = true,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -5,7 +5,7 @@ return {
|
||||
components = {
|
||||
sercon = { uart = 2, speed = 115200 },
|
||||
romfs = true,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -5,7 +5,7 @@ return {
|
||||
components = {
|
||||
sercon = { uart = 0, speed = 115200 },
|
||||
romfs = true,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -6,7 +6,7 @@ return {
|
||||
sercon = { uart = "1", speed = 115200 },
|
||||
romfs = true,
|
||||
cdc = false,
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -6,7 +6,7 @@ return {
|
||||
sercon = { uart = "cdc", speed = 115200 },
|
||||
romfs = true,
|
||||
cdc = { buf_size = 128 },
|
||||
advanced_shell = true,
|
||||
shell = { advanced = true },
|
||||
term = { lines = 25, cols = 80 },
|
||||
linenoise = { shell_lines = 10, lua_lines = 50 },
|
||||
stm32f4_enc = true,
|
||||
|
@ -115,15 +115,16 @@ local function build_validator( realvname )
|
||||
return false, sf( "value of attribute '%s' for element '%s' in section '%s' must be an array", aname, elname, sectname )
|
||||
end
|
||||
end
|
||||
local newv = {}
|
||||
for i = 1, #aval do
|
||||
local res, err = realvname( adesc, aname, aval[ i ], elname, sectname )
|
||||
if not res then
|
||||
return false, sf( "error at index %d: %s", i, err )
|
||||
else
|
||||
aval[ i ] = res
|
||||
newv[ #newv + 1 ] = res
|
||||
end
|
||||
end
|
||||
return aval
|
||||
return newv
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@ local function sermux_auxgen( eldesc, data, generated )
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- MMXFS support
|
||||
-- MMCFS support
|
||||
|
||||
local function mmcfs_auxcheck( eldesc, data, enabled )
|
||||
local ports, pins, spis = data.MMCFS_CS_PORT.value, data.MMCFS_CS_PIN.value, data.MMCFS_SPI_NUM.value
|
||||
@ -47,6 +47,28 @@ local function mmcfs_gen( eldesc, data, generated )
|
||||
return data
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Shell support
|
||||
|
||||
-- Mapping between shell commands and their corresponding functions in shell.c
|
||||
local shell_cmd_map = {
|
||||
help = "shell_help", lua = "shell_lua", recv = "shell_recv", ver = "shell_ver",
|
||||
exit = "NULL", ls = "shell_ls", dir = "shell_ls", cat = "shell_cat",
|
||||
type = "shell_cat", cp = "shell_cp", wofmt = "shell_wofmt", mkdir = "shell_mkdir",
|
||||
rm = "shell_adv_rm", mv = "shell_adv_mv"
|
||||
}
|
||||
|
||||
local function shell_gen( eldesc, data, generated )
|
||||
local cmds, advv = data._DUMMY_SHELL_DATA.value, data.BUILD_ADVANCED_SHELL.value
|
||||
local data = '#define SHELL_COMMAND_LIST\\\n'
|
||||
for i, c in pairs( cmds ) do
|
||||
data = data .. sf(' { "%s", %s },\\\n', c, shell_cmd_map[c] )
|
||||
end
|
||||
data = data .. " { NULL, NULL }\n"
|
||||
if advv == 1 then data = data .. "#define BUILD_ADVANCED_SHELL\n" end
|
||||
return data
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Return a CDC component
|
||||
-- This should be included by each backend that supports USB UARTs
|
||||
@ -68,7 +90,7 @@ function init()
|
||||
local components = {}
|
||||
|
||||
-- Serial console
|
||||
components.sercon = {
|
||||
components.sercon = {
|
||||
macro = 'BUILD_CON_GENERIC',
|
||||
attrs = {
|
||||
uart = at.uart_attr( 'CON_UART_ID' ),
|
||||
@ -96,9 +118,14 @@ function init()
|
||||
}
|
||||
}
|
||||
-- Shell
|
||||
components.shell = { macro = 'BUILD_SHELL' }
|
||||
-- Advanced shell
|
||||
components.advanced_shell = { macro = 'BUILD_ADVANCED_SHELL', autoenable = 'shell' }
|
||||
local shell_cmds_attr = at.choice_attr( '_DUMMY_SHELL_DATA', utils.table_keys( shell_cmd_map ), utils.table_keys( shell_cmd_map ))
|
||||
components.shell = { macro = 'BUILD_SHELL',
|
||||
attrs = {
|
||||
commands = at.array_of( shell_cmds_attr, false ),
|
||||
advanced = at.bool_attr( 'BUILD_ADVANCED_SHELL', false )
|
||||
},
|
||||
gen = shell_gen
|
||||
}
|
||||
-- Term
|
||||
components.term = {
|
||||
macro = 'BUILD_TERM',
|
||||
@ -123,7 +150,7 @@ function init()
|
||||
needs = 'cints'
|
||||
}
|
||||
-- Linenoise
|
||||
components.linenoise = {
|
||||
components.linenoise = {
|
||||
macro = 'BUILD_LINENOISE',
|
||||
attrs = {
|
||||
shell_lines = at.int_attr( 'LINENOISE_HISTORY_SIZE_SHELL' ),
|
||||
|
@ -41,7 +41,7 @@ function config_element( section, sectname, name, data, req )
|
||||
end
|
||||
-- Set default values where needed
|
||||
for name, data in pairs( attrs ) do
|
||||
if not conf[ data.macro ] and data.default then
|
||||
if not conf[ data.macro ] and ( data.default ~= nil ) then
|
||||
conf[ data.macro ] = { name = name, desc = data, value = data.default, sectname = sectname, elname = name, from_default = true }
|
||||
end
|
||||
end
|
||||
|
@ -194,23 +194,10 @@ void shellh_show_help( const char *cmd, const char *helptext )
|
||||
// Public interface
|
||||
|
||||
// Insert shell commands here
|
||||
// SHELL_COMMAND_LIST is generated by the configurator
|
||||
static const SHELL_COMMAND shell_commands[] =
|
||||
{
|
||||
{ "help", shell_help },
|
||||
{ "lua", shell_lua },
|
||||
{ "recv", shell_recv },
|
||||
{ "ver", shell_ver },
|
||||
{ "exit", NULL },
|
||||
{ "ls", shell_ls },
|
||||
{ "dir", shell_ls },
|
||||
{ "cat", shell_cat },
|
||||
{ "type", shell_cat },
|
||||
{ "cp", shell_cp },
|
||||
{ "wofmt", shell_wofmt },
|
||||
{ "mkdir", shell_mkdir },
|
||||
{ "rm", shell_adv_rm },
|
||||
{ "mv", shell_adv_mv },
|
||||
{ NULL, NULL }
|
||||
SHELL_COMMAND_LIST
|
||||
};
|
||||
|
||||
// Executes the given shell command
|
||||
|
Loading…
x
Reference in New Issue
Block a user