From 10df63ae9e7182f77e7c177483798e20ec9ef236 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Tue, 23 Jul 2019 13:30:13 -0600 Subject: [PATCH] consistent command line processing-usage --- monitor/mwm.lua | 11 ++++++----- monitor/termShare.lua | 8 +++++--- neural/mobFollow.lua | 2 +- neural/mobRancher.lua | 22 ++++++++++++++++++---- swshop/Shoplogs.lua | 1 + 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/monitor/mwm.lua b/monitor/mwm.lua index 8ad3ef1..a1e5eb1 100644 --- a/monitor/mwm.lua +++ b/monitor/mwm.lua @@ -12,22 +12,23 @@ local window = _G.window local function syntax() printError('Syntax:') - error('mwm sessionName [monitor]') + error('mwm [--config=filename] [monitor]') end -local args = { ... } +local args = Util.parse(...) local UID = 0 local multishell = { } local processes = { } local parentTerm = term.current() -local sessionFile = args[1] or 'usr/config/mwm' +local sessionFile = args.config or 'usr/config/mwm' +local monName = args[1] local running local parentMon local defaultEnv = Util.shallowCopy(_ENV) defaultEnv.multishell = multishell -if args[2] then - parentMon = peripheral.wrap(args[2]) or syntax() +if monName then + parentMon = peripheral.wrap(monName) or syntax() else parentMon = peripheral.find('monitor') or syntax() end diff --git a/monitor/termShare.lua b/monitor/termShare.lua index f37b76b..2c44372 100644 --- a/monitor/termShare.lua +++ b/monitor/termShare.lua @@ -1,3 +1,5 @@ +local Util = require('opus.util') + local device = _G.device local multishell = _ENV.multishell local os = _G.os @@ -6,9 +8,9 @@ local term = _G.term -- list this terminal in the devices list so it's available via -- peripheral sharing -local args = { ... } -local name = args[1] or error('Syntax: termShare [device name] ') -local title = args[2] +local args = Util.parse(...) +local name = args[1] or error('Syntax: termShare [--title=title] term_name') +local title = args.title device[name] = term.current() device[name].name = name diff --git a/neural/mobFollow.lua b/neural/mobFollow.lua index 5f2da19..1ef1601 100644 --- a/neural/mobFollow.lua +++ b/neural/mobFollow.lua @@ -6,7 +6,7 @@ local Proxy = require('core.proxy') local os = _G.os local args = { ... } -local remoteId = args[1] or error('mobFollow <remote id>') +local remoteId = args[1] or error('mobFollow REMOTE_ID') local ni = Proxy.create(remoteId, 'device/neuralInterface') if not ni then diff --git a/neural/mobRancher.lua b/neural/mobRancher.lua index 83c58d2..c09d7d3 100644 --- a/neural/mobRancher.lua +++ b/neural/mobRancher.lua @@ -3,15 +3,20 @@ Must be run on a mob with the same height. ]] +local Array = require('opus.array') +local Config = require('opus.config') local neural = require('neural.interface') local Sound = require('opus.sound') local Map = require('opus.map') local os = _G.os -local BREEDING = 'Cow' +local config = Config.load('mobRancher', { + animal = 'Cow', + maxAdults = 12, +}) + local WALK_SPEED = 1.5 -local MAX_GROWN = 12 neural.assertModules({ 'plethora:sensor', @@ -76,8 +81,17 @@ local function kill(entity) end local function getEntities() + local sheep = Array.filter(neural.sense(), function(entity) + if entity.name == 'Sheep' and entity.y > -.5 then + return true + end + end) + if #sheep > config.maxAdults then + return sheep + end + return Map.filter(neural.sense(), function(entity) - if entity.name == BREEDING and entity.y > -.5 then + if entity.name == config.animal and entity.y > -.5 then return true end end) @@ -107,7 +121,7 @@ while true do local entities = getEntities() - if Map.size(entities) > MAX_GROWN then + if Map.size(entities) > config.maxAdults then kill(randomEntity(entities)) else local entity = getHungry(entities) diff --git a/swshop/Shoplogs.lua b/swshop/Shoplogs.lua index 2427bc4..2eb605e 100644 --- a/swshop/Shoplogs.lua +++ b/swshop/Shoplogs.lua @@ -7,6 +7,7 @@ local colors = _G.colors local fs = _G.fs UI:configure('Shoplogs', ...) + local args = Util.parse( ... ) local logFile = args[1] or '/usr/swshop.log'