cmd v1.0.0

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).

Installation

Recommended: Install via installer (handles dependencies automatically):

wget run https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua cmd
View on GitHub →

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:

wget https://raw.githubusercontent.com/Twijn/cc-misc/main/util/cmd.lua

Examples

Using with Runtime Installation

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

Usage Examples

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)

Functions

string.split(self, sep?, plain?)

View source on GitHub

Split a string into an array of substrings based on a separator

Parameters:
Returns: string[] # Array of split substrings

string.startsWith(self, target, caseSensitive?)

View source on GitHub

Check if a string starts with a target substring

Parameters:
Returns: boolean # True if the string starts with the target