improved help text and documented utility functions
This commit is contained in:
parent
6c2d327c4b
commit
d491b047d5
2 changed files with 26 additions and 3 deletions
11
src/Info.cs
11
src/Info.cs
|
@ -13,7 +13,16 @@ public static class Usage {
|
||||||
Console.WriteLine(@"Valerie Wolfe <sleeplessval@gmail.com>
|
Console.WriteLine(@"Valerie Wolfe <sleeplessval@gmail.com>
|
||||||
Shows quotes from a set of files.
|
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) {
|
public static void ListText(string[] files) {
|
||||||
|
|
18
src/Util.cs
18
src/Util.cs
|
@ -4,9 +4,19 @@ using System.IO;
|
||||||
|
|
||||||
public static class Utilities {
|
public static class Utilities {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// returns a `List` of all non-flag arguments
|
||||||
|
/// </summary>
|
||||||
|
public static List<string> CollectArgs(string[] args) {
|
||||||
|
var output = new List<string>();
|
||||||
|
foreach(string arg in args)
|
||||||
|
if(!arg.StartsWith("-"))
|
||||||
|
output.Add(arg);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if a given flag is set in `args`.
|
/// checks if a given flag is set in `args`
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool HasFlags(string[] args, params string[] flags) {
|
public static bool HasFlags(string[] args, params string[] flags) {
|
||||||
foreach(string flag in flags)
|
foreach(string flag in flags)
|
||||||
|
@ -16,7 +26,11 @@ public static class Utilities {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Merge(params string[] files) {
|
/// <summary>
|
||||||
|
/// outputs all unique lines from all files in `args` to stdout
|
||||||
|
/// </summary>
|
||||||
|
public static void Merge(string[] args) {
|
||||||
|
var files = CollectArgs(args);
|
||||||
// hashset to prevent duplicates
|
// hashset to prevent duplicates
|
||||||
var members = new HashSet<string>();
|
var members = new HashSet<string>();
|
||||||
// iterate over all paths given
|
// iterate over all paths given
|
||||||
|
|
Loading…
Reference in a new issue