Command-line interface module for ComputerCraft that provides a REPL-style command processor with support for custom commands, autocompletion, and command history. Features: Built-in commands (clear, exit, help), command history navigation, tab autocompletion for commands and arguments, colored output for different message types, table pretty-printing functionality, and string utility functions (split, startsWith).
Recommended: Install via installer (handles dependencies automatically):
This pattern downloads and runs libraries at runtime, automatically installing any that are missing:
-- Auto-install and require libraries
local libs = {"cmd"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local cmd = require(libDir .. "cmd")
-- Use the library
-- (your code here)
Alternative: Direct download via wget:
This example shows how to download and use libraries with automatic installation:
-- Auto-install and require libraries
local libs = {"cmd"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local cmd = require(libDir .. "cmd")
-- Use the library
local cmd = require("cmd")
local customCommands = {
hello = {
description = "Say hello to someone",
execute = function(args, context)
local name = args[1] or "World"
context.succ("Hello, " .. name .. "!")
end
}
}
cmd("MyApp", "1.0.0", customCommands)
string.split(self, sep?, plain?)Split a string into an array of substrings based on a separator
self (string): The string to splitsep? (string): The separator to split on (defaults to each character)plain? (boolean): Whether to treat separator as plain text (no pattern matching)string.startsWith(self, target, caseSensitive?)Check if a string starts with a target substring
self (string): The string to checktarget (string): The substring to look for at the beginningcaseSensitive? (boolean): Whether the comparison should be case-sensitive (defaults to false)