mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-03-25 21:06:58 +00:00
Merge pull request #335 from Wilma456/shellcheck
Add Checks to Shell and Multishell
This commit is contained in:
commit
22066a96dd
@ -171,6 +171,9 @@ function multishell.getFocus()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multishell.setFocus( n )
|
function multishell.setFocus( n )
|
||||||
|
if type( n ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( n ) .. ")", 2 )
|
||||||
|
end
|
||||||
if n >= 1 and n <= #tProcesses then
|
if n >= 1 and n <= #tProcesses then
|
||||||
selectProcess( n )
|
selectProcess( n )
|
||||||
redrawMenu()
|
redrawMenu()
|
||||||
@ -180,6 +183,9 @@ function multishell.setFocus( n )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multishell.getTitle( n )
|
function multishell.getTitle( n )
|
||||||
|
if type( n ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( n ) .. ")", 2 )
|
||||||
|
end
|
||||||
if n >= 1 and n <= #tProcesses then
|
if n >= 1 and n <= #tProcesses then
|
||||||
return tProcesses[n].sTitle
|
return tProcesses[n].sTitle
|
||||||
end
|
end
|
||||||
@ -187,6 +193,12 @@ function multishell.getTitle( n )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multishell.setTitle( n, sTitle )
|
function multishell.setTitle( n, sTitle )
|
||||||
|
if type( n ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( n ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( sTitle ) ~= "string" then
|
||||||
|
error( "bad argument #2 (expected string, got " .. type( sTitle ) .. ")", 2 )
|
||||||
|
end
|
||||||
if n >= 1 and n <= #tProcesses then
|
if n >= 1 and n <= #tProcesses then
|
||||||
setProcessTitle( n, sTitle )
|
setProcessTitle( n, sTitle )
|
||||||
redrawMenu()
|
redrawMenu()
|
||||||
@ -198,6 +210,12 @@ function multishell.getCurrent()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multishell.launch( tProgramEnv, sProgramPath, ... )
|
function multishell.launch( tProgramEnv, sProgramPath, ... )
|
||||||
|
if type( tProgramArgs ) ~= "table" then
|
||||||
|
error( "bad argument #1 (expected table, got " .. type( tProgramEnv ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( sProgramPath ) ~= "string" then
|
||||||
|
error( "bad argument #2 (expected string, got " .. type( sProgramPath ) .. ")", 2 )
|
||||||
|
end
|
||||||
local previousTerm = term.current()
|
local previousTerm = term.current()
|
||||||
setMenuVisible( (#tProcesses + 1) >= 2 )
|
setMenuVisible( (#tProcesses + 1) >= 2 )
|
||||||
local nResult = launchProcess( tProgramEnv, sProgramPath, ... )
|
local nResult = launchProcess( tProgramEnv, sProgramPath, ... )
|
||||||
|
@ -68,6 +68,9 @@ local function createShellEnv( sDir )
|
|||||||
|
|
||||||
local sentinel = {}
|
local sentinel = {}
|
||||||
local function require( name )
|
local function require( name )
|
||||||
|
if type( name ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( name ) .. ")", 2 )
|
||||||
|
end
|
||||||
if package.loaded[name] == sentinel then
|
if package.loaded[name] == sentinel then
|
||||||
error("Loop detected requiring '" .. name .. "'", 0)
|
error("Loop detected requiring '" .. name .. "'", 0)
|
||||||
end
|
end
|
||||||
@ -181,6 +184,12 @@ function shell.dir()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.setDir( _sDir )
|
function shell.setDir( _sDir )
|
||||||
|
if type( _sDir ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sDir ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if not fs.isDir( _sDir ) then
|
||||||
|
error( "Not a directory", 2 )
|
||||||
|
end
|
||||||
sDir = _sDir
|
sDir = _sDir
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,10 +198,16 @@ function shell.path()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.setPath( _sPath )
|
function shell.setPath( _sPath )
|
||||||
|
if type( _sPath ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 )
|
||||||
|
end
|
||||||
sPath = _sPath
|
sPath = _sPath
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.resolve( _sPath )
|
function shell.resolve( _sPath )
|
||||||
|
if type( _sPath ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 )
|
||||||
|
end
|
||||||
local sStartChar = string.sub( _sPath, 1, 1 )
|
local sStartChar = string.sub( _sPath, 1, 1 )
|
||||||
if sStartChar == "/" or sStartChar == "\\" then
|
if sStartChar == "/" or sStartChar == "\\" then
|
||||||
return fs.combine( "", _sPath )
|
return fs.combine( "", _sPath )
|
||||||
@ -212,6 +227,9 @@ local function pathWithExtension( _sPath, _sExt )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.resolveProgram( _sCommand )
|
function shell.resolveProgram( _sCommand )
|
||||||
|
if type( _sCommand ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sCommand ) .. ")", 2 )
|
||||||
|
end
|
||||||
-- Substitute aliases firsts
|
-- Substitute aliases firsts
|
||||||
if tAliases[ _sCommand ] ~= nil then
|
if tAliases[ _sCommand ] ~= nil then
|
||||||
_sCommand = tAliases[ _sCommand ]
|
_sCommand = tAliases[ _sCommand ]
|
||||||
@ -327,6 +345,9 @@ local function completeProgramArgument( sProgram, nArgument, sPart, tPreviousPar
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.complete( sLine )
|
function shell.complete( sLine )
|
||||||
|
if type( sLine ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( sLine ) .. ")", 2 )
|
||||||
|
end
|
||||||
if #sLine > 0 then
|
if #sLine > 0 then
|
||||||
local tWords = tokenise( sLine )
|
local tWords = tokenise( sLine )
|
||||||
local nIndex = #tWords
|
local nIndex = #tWords
|
||||||
@ -363,10 +384,19 @@ function shell.complete( sLine )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.completeProgram( sProgram )
|
function shell.completeProgram( sProgram )
|
||||||
|
if type( sProgram ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( sProgram ) .. ")", 2 )
|
||||||
|
end
|
||||||
return completeProgram( sProgram )
|
return completeProgram( sProgram )
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.setCompletionFunction( sProgram, fnComplete )
|
function shell.setCompletionFunction( sProgram, fnComplete )
|
||||||
|
if type( sProgram ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( sProgram ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( fnComplete ) ~= "function" then
|
||||||
|
error( "bad argument #2 (expected function, got " .. type( fnComplete ) .. ")", 2 )
|
||||||
|
end
|
||||||
tCompletionInfo[ sProgram ] = {
|
tCompletionInfo[ sProgram ] = {
|
||||||
fnComplete = fnComplete
|
fnComplete = fnComplete
|
||||||
}
|
}
|
||||||
@ -384,10 +414,19 @@ function shell.getRunningProgram()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.setAlias( _sCommand, _sProgram )
|
function shell.setAlias( _sCommand, _sProgram )
|
||||||
|
if type( _sCommand ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sCommand ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
if type( _sProgram ) ~= "string" then
|
||||||
|
error( "bad argument #2 (expected string, got " .. type( _sProgram ) .. ")", 2 )
|
||||||
|
end
|
||||||
tAliases[ _sCommand ] = _sProgram
|
tAliases[ _sCommand ] = _sProgram
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell.clearAlias( _sCommand )
|
function shell.clearAlias( _sCommand )
|
||||||
|
if type( _sCommand ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( _sCommand ) .. ")", 2 )
|
||||||
|
end
|
||||||
tAliases[ _sCommand ] = nil
|
tAliases[ _sCommand ] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -417,6 +456,9 @@ if multishell then
|
|||||||
end
|
end
|
||||||
|
|
||||||
function shell.switchTab( nID )
|
function shell.switchTab( nID )
|
||||||
|
if type( nID ) ~= "number" then
|
||||||
|
error( "bad argument #1 (expected number, got " .. type( nID ) .. ")", 2 )
|
||||||
|
end
|
||||||
multishell.setFocus( nID )
|
multishell.setFocus( nID )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user