|
|
|
using Console.Waterworks;
|
|
|
|
using Console.Waterworks.Attributes;
|
|
|
|
using Microsoft.FSharp.Control;
|
|
|
|
using Microsoft.FSharp.Core;
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using static System.Environment;
|
|
|
|
using static System.Console;
|
|
|
|
using static WetPancake.Pancake;
|
|
|
|
|
|
|
|
namespace WetPancakeCLI
|
|
|
|
{
|
|
|
|
public static class ConsoleCommands
|
|
|
|
{
|
|
|
|
// Pass these in when running an FSharpAsync task.
|
|
|
|
// Examples are within the command-methods.
|
|
|
|
static readonly FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None;
|
|
|
|
static readonly FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None;
|
|
|
|
|
|
|
|
static void CopyToClipboard(string text) => Clipboard.SetText(text);
|
|
|
|
|
|
|
|
#region Console Utilities
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("None")]
|
|
|
|
[Description("Prints a test message to the console.")]
|
|
|
|
[Usage("> Test")]
|
|
|
|
public static string Test() => "SUCCESS: Console.Waterworks is wired into Wet Pancake CLI.";
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("None")]
|
|
|
|
[Description("Lists out the commands this program offers.")]
|
|
|
|
[Usage("> Help")]
|
|
|
|
public static string Help() => new CW_Liaison().RequestHelpDocumentation("WetPancakeCLI");
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("filePath: string")]
|
|
|
|
[Description("Writes a quick guide to the specified location or the desktop if no path is specified.")]
|
|
|
|
[Usage("/n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"QuickGuide C:/your/filePath\n" +
|
|
|
|
"QuickGuide")]
|
|
|
|
public static string QuickGuide(string filePath = "")
|
|
|
|
{
|
|
|
|
WriteLine("Attempting to write the Wet Pancake CLI Quick Guide...");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var parentDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
|
|
|
|
var cheatsheetPath = $"{parentDirectory}\\ProductInfo\\quick-guide.pdf";
|
|
|
|
if (!File.Exists(cheatsheetPath)) throw new FileNotFoundException();
|
|
|
|
if (string.IsNullOrWhiteSpace(filePath))
|
|
|
|
{
|
|
|
|
var desktopDirectory = GetFolderPath(SpecialFolder.Desktop);
|
|
|
|
var savePath = $"{desktopDirectory}\\wet-pancake-quick-guide.pdf";
|
|
|
|
File.Copy(cheatsheetPath, savePath, true);
|
|
|
|
return "Quick Guide written to desktop.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var customSavePath = $"{filePath}\\wet-pancake-quick-guide.pdf";
|
|
|
|
File.Copy(cheatsheetPath, customSavePath, true);
|
|
|
|
if (!Directory.Exists(filePath)) throw new DirectoryNotFoundException();
|
|
|
|
return $"Quick Guide written to {filePath}";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("None")]
|
|
|
|
[Description("Exits out of the program.")]
|
|
|
|
[Usage("> Exit")]
|
|
|
|
public static void Exit() => Environment.Exit(ExitCode);
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Wet Pancake Utilities
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("sentences: int, text: string")]
|
|
|
|
[Description(
|
|
|
|
"Checks to see if the string matches the desired sentence count and removes any over that limit.\n" +
|
|
|
|
"If the string has less sentences than the number requested, it will not change.\n" +
|
|
|
|
"Sentences must be greater than 0 and text must contain at least 1 \".\" \"?\" \"!\"")]
|
|
|
|
[Usage("> CleanText 1 \"This is a test sentence. And, this one needs to be removed.\"")]
|
|
|
|
public static string CleanText(int sentences, string text)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (sentences < 1)
|
|
|
|
throw new ArgumentException("Invalid argument. Must be greater than 0", "sentences");
|
|
|
|
return FSharpAsync.StartAsTask
|
|
|
|
(CleanResultAsync(sentences, text), _taskCreationOptions, _cancellationToken).Result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("None")]
|
|
|
|
[Description("Returns a list of all the available .txt files built-in to Wet Pancake.")]
|
|
|
|
[Usage("> RequestAllTemplateFiles")]
|
|
|
|
public static string RequestAllTemplateFiles()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
WriteLine("Attempting to list out the available template files...");
|
|
|
|
foreach (var item in RequestAllTemplateFiles())
|
|
|
|
{
|
|
|
|
WriteLine($"File path: {item}");
|
|
|
|
}
|
|
|
|
return "Listing complete.";
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("filePath: string")]
|
|
|
|
[Description(
|
|
|
|
"Checks the text in the specified .txt file to see if it is compatible with this program.\n" +
|
|
|
|
"For a file to be compatible, it must be a .txt file and contain at least one '.', '!' or '?'.")]
|
|
|
|
[Usage("> ValidateFile \"C:/your-file.txt\"")]
|
|
|
|
public static string ValidateFile(string filePath)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
WriteLine("Validating file. Please wait...");
|
|
|
|
var extension = Path.GetExtension(filePath);
|
|
|
|
if (string.Equals(extension, ".txt"))
|
|
|
|
{
|
|
|
|
var isValid =
|
|
|
|
FSharpAsync.StartAsTask(TextInFileIsValidAsync(filePath),
|
|
|
|
_taskCreationOptions, _cancellationToken).Result;
|
|
|
|
return $"Is Valid: {isValid}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new FileLoadException("The file entered is not a plain text (.txt) file.", filePath);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Text Generation
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")]
|
|
|
|
[Description(
|
|
|
|
"Makes text using the gibberish-level and number of sentences specified by the user.\n" +
|
|
|
|
"The result goes through an extra \"cleaning\" process to remove any artefact sentences.\n" +
|
|
|
|
"Use this if you cannot tolerate the odd extra sentence.\n" +
|
|
|
|
"With that said, it does mean it is slower than its MakeText counterpart.\n" +
|
|
|
|
"Gibberish-level must be between 2 and 20.\n" +
|
|
|
|
"Sentences must be greater than 0.\n" +
|
|
|
|
"Pass in \"true\" to copy the result straight to the clipboard.\n" +
|
|
|
|
"Pass in \"false\" or leave blank to not copy the result.")]
|
|
|
|
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"> MakeCleanText 5 10 true\n" +
|
|
|
|
"> MakeCleanText 3 7 false \n" +
|
|
|
|
"> MakeCleanText 9 12")]
|
|
|
|
public static string MakeCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (gibberishLevel < 2 || gibberishLevel > 20)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-Level");
|
|
|
|
if (sentences < 1)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be greater than 0.", "sentences");
|
|
|
|
var result = FSharpAsync.StartAsTask(
|
|
|
|
RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken)
|
|
|
|
.Result;
|
|
|
|
if (copyToClipboard == true) CopyToClipboard(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("gibberish-level: int, sentences: int, file path: string, copy-to-clipboard: bool")]
|
|
|
|
[Description("\n" +
|
|
|
|
"Loads the specified .txt file and makes text based on it,\n" +
|
|
|
|
"using the gibberish-level and number of sentences specified by the user.\n" +
|
|
|
|
"The result goes through an extra \"cleaning\" process to remove any artefact sentences.\n" +
|
|
|
|
"Use this if you cannot tolerate the odd extra sentence.\n" +
|
|
|
|
"With that said, it does mean it is slower than its MakeTextFromFile counterpart.\n" +
|
|
|
|
"Gibberish-level must be between 2 and 20.\n" +
|
|
|
|
"Sentences must be greater than 0.\n" +
|
|
|
|
"Pass in \"true\" to copy the result straight to the clipboard.\n" +
|
|
|
|
"Pass in \"false\" or leave blank to not copy the result.")]
|
|
|
|
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"> MakeCleanTextFromFile 3 6 C:/yourfile.txt true \n" +
|
|
|
|
"> MakeCleanTextFromFile 5 9 C:/yourfile.txt false\n" +
|
|
|
|
"> MakeCleanTextFromFile 7 15 C:/ yourfile.txt")]
|
|
|
|
public static string MakeCleanTextFromFile(
|
|
|
|
int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (gibberishLevel < 2 || gibberishLevel > 20)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-Level");
|
|
|
|
if (sentences < 1)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be greater than 0.", "sentences");
|
|
|
|
var extension = Path.GetExtension(filePath);
|
|
|
|
if (string.Equals(extension, ".txt") != true)
|
|
|
|
throw new FileLoadException
|
|
|
|
("The file entered is not a plain text (.txt) file.", filePath);
|
|
|
|
var result = FSharpAsync.StartAsTask(
|
|
|
|
RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath),
|
|
|
|
_taskCreationOptions, _cancellationToken)
|
|
|
|
.Result;
|
|
|
|
if (copyToClipboard == true) CopyToClipboard(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("copy-to-clipboard: bool")]
|
|
|
|
[Description(
|
|
|
|
"Makes random text, the number of sentences Maked is randomly determined.\n" +
|
|
|
|
"Pass in true to copy result straight to clipboard.\n" +
|
|
|
|
"Pass in \"false\" or leave blank to not copy the result.")]
|
|
|
|
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"> MakeRandomText true\n" +
|
|
|
|
"> MakeRandomText false\n" +
|
|
|
|
"> MakeRandomText")]
|
|
|
|
public static string MakeRandomText(bool copyToClipboard = false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var result = FSharpAsync.StartAsTask
|
|
|
|
(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
|
|
|
|
if (copyToClipboard == true) CopyToClipboard(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")]
|
|
|
|
[Description(
|
|
|
|
"Makes text using the gibberish-level and number of sentences specified by the user.\n" +
|
|
|
|
"This command does not run the result through the extra \"cleaning\" process like MakeCleanText.\n" +
|
|
|
|
"This means this command is faster but it might produce an extra sentence on the odd occasion.\n" +
|
|
|
|
"Use this if you prefer speed over accuracy.\n" +
|
|
|
|
"Gibberish-level must be between 2 and 20.\n" +
|
|
|
|
"Sentences must be greater than 0.\n" +
|
|
|
|
"Pass in \"true\" to copy the result straight to the clipboard.\n" +
|
|
|
|
"Pass in \"false\" or leave blank to not copy the result.")]
|
|
|
|
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"> MakeText 5 10 true\n" +
|
|
|
|
"> MakeText 7 15 false\n" +
|
|
|
|
"> MakeText 10 5")]
|
|
|
|
public static string MakeText(int gibberishLevel, int sentences, bool copyToClipboard = false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (gibberishLevel < 2 || gibberishLevel > 20)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-level");
|
|
|
|
if (sentences < 1)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be greater than 0.", "sentences");
|
|
|
|
var result = FSharpAsync.StartAsTask
|
|
|
|
(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
|
|
|
|
if (copyToClipboard == true) CopyToClipboard(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ListCommand]
|
|
|
|
[Parameters("gibberish-level: int, sentences: int, file path: string")]
|
|
|
|
[Description(
|
|
|
|
"Loads the specified .txt file and makes text based on it,\n" +
|
|
|
|
"using the gibberish-level and number of sentencesspecifiedby the user.\n" +
|
|
|
|
"This command does not run the result through the extra \"cleaning\" process like MakeCleanTextFromFile.\n" +
|
|
|
|
"This means this command is faster but it might produce an extra sentence on the odd occasion.\n" +
|
|
|
|
"Use this if you prefer speed over accuracy.\n" +
|
|
|
|
"Gibberish-level must be between 2 and 20.\n" +
|
|
|
|
"Sentences must be greater than 0.\n" +
|
|
|
|
"Pass in \"true\" to copy the result straight to the clipboard.\n" +
|
|
|
|
"Pass in \"false\" or leave blank to not copy the result.")]
|
|
|
|
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
|
|
|
|
"> MakeTextFromFile 3 6 C:/yourfile.txt true\n" +
|
|
|
|
"> MakeTextFromFile 6 13 C:/yourfile.txt false \n" +
|
|
|
|
"> MakeTextFromFile 12 8 C:/yourfile.txt")]
|
|
|
|
public static string MakeTextFromFile
|
|
|
|
(int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (gibberishLevel < 2 || gibberishLevel > 20)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberish-level");
|
|
|
|
if (sentences < 1)
|
|
|
|
throw new ArgumentException
|
|
|
|
("Invalid argument. Must be greater than 0.", "sentences");
|
|
|
|
var extension = Path.GetExtension(filePath);
|
|
|
|
if (string.Equals(extension, ".txt") != true)
|
|
|
|
throw new FileLoadException
|
|
|
|
("The file entered is not a plain text (.txt) file.", filePath);
|
|
|
|
var fileIsValid =
|
|
|
|
FSharpAsync.StartAsTask(TextInFileIsValidAsync(filePath),
|
|
|
|
_taskCreationOptions, _cancellationToken).Result;
|
|
|
|
if (fileIsValid == false)
|
|
|
|
throw new Exception("The .txt does not contain a vaild end token ('.', '!' or '?').");
|
|
|
|
var result = FSharpAsync.StartAsTask(
|
|
|
|
RequestTextFromFileAsync(gibberishLevel, sentences, filePath),
|
|
|
|
_taskCreationOptions, _cancellationToken)
|
|
|
|
.Result;
|
|
|
|
if (copyToClipboard == true) CopyToClipboard(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.WriteLine(e.Message);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|