use arg[0] in all usage printouts (#571)

This commit is contained in:
Lupus590 2020-11-04 14:03:08 +00:00 committed by GitHub
parent cc96e41d3e
commit d13bd2cce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 79 additions and 51 deletions

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs > 2 then
print("Usage: alias <alias> <program>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <alias> <program>")
return
end

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: cd <path>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <path>")
return
end

View File

@ -4,7 +4,8 @@ if not commands then
return
end
if #tArgs == 0 then
printError("Usage: exec <command>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
printError("Usage: " .. programName .. " <command>")
return
end

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs < 2 then
print("Usage: cp <source> <destination>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <source> <destination>")
return
end

View File

@ -1,7 +1,8 @@
local args = table.pack(...)
if args.n < 1 then
print("Usage: rm <paths>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <paths>")
return
end

View File

@ -1,7 +1,8 @@
-- Get file to edit
local tArgs = { ... }
if #tArgs == 0 then
print("Usage: edit <path>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <path>")
return
end

View File

@ -1,7 +1,8 @@
-- Get arguments
local tArgs = { ... }
if #tArgs == 0 then
print("Usage: eject <drive>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <drive>")
return
end

View File

@ -34,7 +34,8 @@ end
-- Determines if the file exists, and can be edited on this computer
local tArgs = { ... }
if #tArgs == 0 then
print("Usage: paint <path>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <path>")
return
end
local sPath = shell.resolve(tArgs[1])

View File

@ -1,10 +1,11 @@
local tArgs = { ... }
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("dj play")
print("dj play <drive>")
print("dj stop")
print(programName .. " play")
print(programName .. " play <drive>")
print(programName .. " stop")
end
if #tArgs > 2 then

View File

@ -1,8 +1,9 @@
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("gps host")
print("gps host <x> <y> <z>")
print("gps locate")
print(programName .. " host")
print(programName .. " host <x> <y> <z>")
print(programName .. " locate")
end
local tArgs = { ... }

View File

@ -1,8 +1,9 @@
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("pastebin put <filename>")
print("pastebin get <code> <filename>")
print("pastebin run <code> <arguments>")
print(programName .. " put <filename>")
print(programName .. " get <code> <filename>")
print(programName .. " run <code> <arguments>")
end
local tArgs = { ... }

View File

@ -1,7 +1,8 @@
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage:")
print("wget <url> [filename]")
print("wget run <url>")
print(programName .. " <url> [filename]")
print(programName .. " run <url>")
end
local tArgs = { ... }

View File

@ -1,11 +1,12 @@
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("label get")
print("label get <drive>")
print("label set <text>")
print("label set <drive> <text>")
print("label clear")
print("label clear <drive>")
print(programName .. " get")
print(programName .. " get <drive>")
print(programName .. " set <text>")
print(programName .. " set <drive> <text>")
print(programName .. " clear")
print(programName .. " clear <drive>")
end
local function checkDrive(sDrive)

View File

@ -1,7 +1,8 @@
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: mkdir <paths>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <paths>")
return
end

View File

@ -1,5 +1,6 @@
local function printUsage()
print("Usage: monitor <name> <program> <arguments>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <name> <program> <arguments>")
return
end

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs < 2 then
print("Usage: mv <source> <destination>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <source> <destination>")
return
end

View File

@ -1,9 +1,10 @@
local tArgs = { ... }
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("chat host <hostname>")
print("chat join <hostname> <nickname>")
print(programName .. " host <hostname>")
print(programName .. " join <hostname> <nickname>")
end
local sOpenedModem = nil

View File

@ -1,11 +1,12 @@
local tArgs = { ... }
local function printUsage()
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usages:")
print("redstone probe")
print("redstone set <side> <value>")
print("redstone set <side> <color> <value>")
print("redstone pulse <side> <count> <period>")
print(programName .. " probe")
print(programName .. " set <side> <value>")
print(programName .. " set <side> <color> <value>")
print(programName .. " pulse <side> <count> <period>")
end
local sCommand = tArgs[1]

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs < 2 then
print("Usage: rename <source> <destination>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <source> <destination>")
return
end

View File

@ -11,7 +11,8 @@ end
local tArgs = { ... }
local nLimit = nil
if #tArgs < 1 then
print("Usage: craft [number]")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " [number]")
return
else
nLimit = tonumber(tArgs[1])

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
local function printUsage()
print("Usage: equip <slot> <side>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <slot> <side>")
end
if #tArgs ~= 2 then

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
if #tArgs ~= 1 then
print("Usage: excavate <diameter>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <diameter>")
return
end

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: go <direction> <distance>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <direction> <distance>")
return
end

View File

@ -6,7 +6,8 @@ end
local tArgs = { ... }
local nLimit = 1
if #tArgs > 1 then
print("Usage: refuel [number]")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " [number]")
return
elseif #tArgs > 0 then
if tArgs[1] == "all" then

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
if #tArgs ~= 1 then
print("Usage: tunnel <length>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <length>")
return
end

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: turn <direction> <turns>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <direction> <turns>")
return
end

View File

@ -5,7 +5,8 @@ end
local tArgs = { ... }
local function printUsage()
print("Usage: unequip <side>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <side>")
end
if #tArgs ~= 1 then

View File

@ -1,6 +1,7 @@
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: type <path>")
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <path>")
return
end

View File

@ -10,7 +10,7 @@ describe("The exec program", function()
it("displays its usage when given no argument", function()
stub(_G, "commands", {})
expect(capture(stub, "/rom/programs/command/exec.lua"))
:matches { ok = true, output = "", error = "Usage: exec <command>\n" }
:matches { ok = true, output = "", error = "Usage: /rom/programs/command/exec.lua <command>\n" }
end)
it("runs a command", function()

View File

@ -35,6 +35,6 @@ describe("The copy program", function()
it("displays the usage when given no arguments", function()
expect(capture(stub, "copy"))
:matches { ok = true, output = "Usage: cp <source> <destination>\n", error = "" }
:matches { ok = true, output = "Usage: copy <source> <destination>\n", error = "" }
end)
end)

View File

@ -69,6 +69,6 @@ describe("The move program", function()
it("displays the usage with no arguments", function()
expect(capture(stub, "move"))
:matches { ok = true, output = "Usage: mv <source> <destination>\n", error = "" }
:matches { ok = true, output = "Usage: move <source> <destination>\n", error = "" }
end)
end)

View File

@ -19,7 +19,7 @@ describe("The craft program", function()
stub(_G, "turtle", { craft = function() end })
expect(capture(stub, "/rom/programs/turtle/craft.lua"))
:matches { ok = true, output = "Usage: craft [number]\n", error = "" }
:matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua [number]\n", error = "" }
end)
it("crafts multiple items", function()

View File

@ -13,7 +13,7 @@ describe("The turtle equip program", function()
stub(_G, "turtle", {})
expect(capture(stub, "/rom/programs/turtle/equip.lua"))
:matches { ok = true, output = "Usage: equip <slot> <side>\n", error = "" }
:matches { ok = true, output = "Usage: /rom/programs/turtle/equip.lua <slot> <side>\n", error = "" }
end)
it("equip nothing", function()

View File

@ -32,7 +32,7 @@ describe("The refuel program", function()
it("displays its usage when given too many argument", function()
setup_turtle(0, 5, 0)
expect(capture(stub, "/rom/programs/turtle/refuel.lua a b"))
:matches { ok = true, output = "Usage: refuel [number]\n", error = "" }
:matches { ok = true, output = "Usage: /rom/programs/turtle/refuel.lua [number]\n", error = "" }
end)
it("requires a numeric argument", function()

View File

@ -13,7 +13,7 @@ describe("The turtle unequip program", function()
stub(_G, "turtle", {})
expect(capture(stub, "/rom/programs/turtle/unequip.lua"))
:matches { ok = true, output = "Usage: unequip <side>\n", error = "" }
:matches { ok = true, output = "Usage: /rom/programs/turtle/unequip.lua <side>\n", error = "" }
end)
it("says when nothing was unequipped", function()