From 2ca49fba62f59135c2ed3ec7958cb78073ff486b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 Jul 2017 02:45:02 -0400 Subject: encapsulate TrainerMod's argument parsing (#302) --- .../Framework/Commands/Player/AddWeaponCommand.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs') diff --git a/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs b/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs index ee94093f..c4ea3d6f 100644 --- a/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs +++ b/src/TrainerMod/Framework/Commands/Player/AddWeaponCommand.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using StardewModdingAPI; using StardewValley; using StardewValley.Tools; @@ -20,19 +19,11 @@ namespace TrainerMod.Framework.Commands.Player /// Writes messages to the console and log file. /// The command name. /// The command arguments. - public override void Handle(IMonitor monitor, string command, string[] args) + public override void Handle(IMonitor monitor, string command, ArgumentParser args) { - // validate - if (!args.Any()) - { - this.LogArgumentsInvalid(monitor, command); + // parse arguments + if (!args.TryGetInt(0, "weapon ID", out int weaponID, min: 0)) return; - } - if (!int.TryParse(args[0], out int weaponID)) - { - this.LogUsageError(monitor, "The weapon ID must be an integer.", command); - return; - } // get raw weapon data if (!Game1.content.Load>("Data\\weapons").TryGetValue(weaponID, out string data)) -- cgit