Compare commits

..

No commits in common. "54cceabdcefefd75ee09931dcfeb60fb2acb7e79" and "6e31e23001bb405eb50735449ea33f9118428d52" have entirely different histories.

3 changed files with 2 additions and 66 deletions

View file

@ -1,31 +0,0 @@
using System;
using System.IO;
public static class Globals {
public const string VERSION = "0.1.0";
public const string DEFAULT_PATH = "/usr/share/fortune-cs/";
}
public static class Usage {
public static void HelpText() {
VersionText();
Console.WriteLine(@"Valerie Wolfe <sleeplessval@gmail.com>
Shows quotes from a set of files.
usage: fortune-cs");
}
public static void ListText(string[] files) {
foreach(var file in files) {
var fileName = Path.GetFileNameWithoutExtension(file);
Console.WriteLine(fileName);
}
}
public static void VersionText() {
Console.WriteLine("fortune-cs v" + Globals.VERSION);
}
}

View file

@ -2,32 +2,16 @@ using System;
using System.IO; using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
// handle help and version flags
if(Utilities.HasFlags(args, "-h", "--help")) {
Usage.HelpText();
return 0;
}
if(Utilities.HasFlags(args, "-v", "--version")) {
Usage.VersionText();
return 0;
}
// make sure fortune directory exists // make sure fortune directory exists
var resourcePath = Globals.DEFAULT_PATH; var resourcePath = "/usr/share/fortune-cs/";
if(!Directory.Exists(resourcePath)) { if(!Directory.Exists(resourcePath)) {
Console.WriteLine($"fortune-cs: directory '${resourcePath}' does not exist"); Console.WriteLine("fortune-cs: directory '/usr/share/fortune-cs/' does not exist");
return 1; return 1;
} }
// pull file list // pull file list
var files = Directory.GetFiles(resourcePath, "*.txt"); var files = Directory.GetFiles(resourcePath, "*.txt");
// handle list flag
if(Utilities.HasFlags(args, "-l", "--list")) {
Usage.ListText(files);
return 0;
}
// choose a file and line // choose a file and line
var file = files[RandomNumberGenerator.GetInt32(files.Length)]; var file = files[RandomNumberGenerator.GetInt32(files.Length)];
var lines = File.ReadAllLines(file); var lines = File.ReadAllLines(file);

View file

@ -1,17 +0,0 @@
using System;
public static class Utilities {
/// <summary>
/// Checks if a given flag is set in `args`.
/// </summary>
public static bool HasFlags(string[] args, params string[] flags) {
foreach(string flag in flags)
// using `Array.IndexOf` since including Linq for `array.Contains` increases binary size
if(Array.IndexOf(args, flag) != -1)
return true;
return false;
}
}