source: binary-improvements/AllocsCommands/Commands/ListItems.cs@ 340

Last change on this file since 340 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 1.4 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3
[325]4namespace AllocsFixes.CustomCommands {
5 public class ListItems : ConsoleCmdAbstract {
6 public override string GetDescription () {
[224]7 return "lists all items that contain the given substring";
8 }
9
[325]10 public override string[] GetCommands () {
11 return new[] {"listitems", "li"};
[224]12 }
13
[306]14 public override string GetHelp () {
15 return "List all available item names\n" +
[325]16 "Usage:\n" +
17 " 1. listitems <searchString>\n" +
18 " 2. listitems *\n" +
19 "1. List only names that contain the given string.\n" +
20 "2. List all names.";
[306]21 }
22
[325]23 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[224]24 try {
[230]25 if (_params.Count != 1 || _params [0].Length == 0) {
26 SdtdConsole.Instance.Output ("Usage: listitems <searchString>");
[224]27 return;
28 }
29
[306]30 int count = ItemClass.ItemNames.Count;
[325]31 bool showAll = _params [0].Trim ().Equals ("*");
[306]32
33 int listed = 0;
34 for (int i = 0; i < count; i++) {
35 string s = ItemClass.ItemNames [i];
36 if (showAll || s.IndexOf (_params [0], StringComparison.OrdinalIgnoreCase) >= 0) {
[230]37 SdtdConsole.Instance.Output (" " + s);
[306]38 listed++;
[224]39 }
40 }
41
[306]42 SdtdConsole.Instance.Output ("Listed " + listed + " matching items.");
[224]43 } catch (Exception e) {
44 Log.Out ("Error in ListItems.Run: " + e);
45 }
46 }
47 }
[325]48}
Note: See TracBrowser for help on using the repository browser.