From d491b047d5f1a7557139d25b033ce9c0f7b6074a Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 11 Mar 2024 23:21:26 -0400 Subject: [PATCH] improved help text and documented utility functions --- src/Info.cs | 11 ++++++++++- src/Util.cs | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Info.cs b/src/Info.cs index f109ac4..9e08061 100644 --- a/src/Info.cs +++ b/src/Info.cs @@ -13,7 +13,16 @@ public static class Usage { Console.WriteLine(@"Valerie Wolfe Shows quotes from a set of files. -usage: fortune-cs"); +usage: fortune-cs [flags] [source] + +args: + [file] Manual file selection + +flags: + -h, --help Shows this help text + -v, --version Shows version information + -l, --list List files in the fortune directory + -m, --merge [files...] Output all distinct lines from a set of files"); } public static void ListText(string[] files) { diff --git a/src/Util.cs b/src/Util.cs index 072d7d5..27f7596 100644 --- a/src/Util.cs +++ b/src/Util.cs @@ -4,9 +4,19 @@ using System.IO; public static class Utilities { + /// + /// returns a `List` of all non-flag arguments + /// + public static List CollectArgs(string[] args) { + var output = new List(); + foreach(string arg in args) + if(!arg.StartsWith("-")) + output.Add(arg); + return output; + } /// - /// Checks if a given flag is set in `args`. + /// checks if a given flag is set in `args` /// public static bool HasFlags(string[] args, params string[] flags) { foreach(string flag in flags) @@ -16,7 +26,11 @@ public static class Utilities { return false; } - public static void Merge(params string[] files) { + /// + /// outputs all unique lines from all files in `args` to stdout + /// + public static void Merge(string[] args) { + var files = CollectArgs(args); // hashset to prevent duplicates var members = new HashSet(); // iterate over all paths given