From 63b6bdc47186951b276f40c2751af3c2e0aba0d3 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 19:47:23 +0100 Subject: [PATCH 1/6] Add CopyToClipboard method in console-commands. Add copy to clipboard functionality to GenerateRandomText command-method. Add STAThread attribute to CLI's Main. --- WetPancakeCLI/ConsoleCommands.cs | 29 ++++++++++++++++++----------- WetPancakeCLI/Program.cs | 2 ++ WetPancakeCLI/WetPancakeCLI.csproj | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/WetPancakeCLI/ConsoleCommands.cs b/WetPancakeCLI/ConsoleCommands.cs index 2d37c3a..22f271e 100644 --- a/WetPancakeCLI/ConsoleCommands.cs +++ b/WetPancakeCLI/ConsoleCommands.cs @@ -1,15 +1,16 @@ using Console.Waterworks; using Console.Waterworks.Attributes; +using Microsoft.FSharp.Control; +using Microsoft.FSharp.Core; using System; -using static WetPancake.Pancake; -using static System.Environment; using System.Diagnostics; +using System.IO; using System.Threading.Tasks; -using Microsoft.FSharp.Control; -using Microsoft.FSharp.Core; using System.Threading; -using System.IO; +using System.Windows.Forms; +using static System.Environment; using static System.Console; +using static WetPancake.Pancake; namespace WetPancakeCLI { @@ -17,8 +18,10 @@ namespace WetPancakeCLI { // Pass these in when running an FSharpAsync task. // Examples are within the command-methods. - static FSharpOption _taskCreationOptions = FSharpOption.None; - static FSharpOption _cancellationToken = FSharpOption.None; + static readonly FSharpOption _taskCreationOptions = FSharpOption.None; + static readonly FSharpOption _cancellationToken = FSharpOption.None; + + static void CopyToClipBoard(string text) => Clipboard.SetText(text); #region Console Utilities [ListCommand] @@ -184,15 +187,19 @@ namespace WetPancakeCLI } [ListCommand] - [Description("Generates random text, the number of sentences generated is randomly determined.")] - [Parameters("None")] + [Description( + "Generates random text, the number of sentences generated is randomly determined\n." + + "Pass in true to copy result straight to clipboard.")] + [Parameters("copy-to-clipbaord: bool")] [Usage("> GenerateRandomText")] - public static string GenerateRandomText() + public static string GenerateRandomText(bool copyToClipboard = false) { try { - return FSharpAsync.StartAsTask + var result = FSharpAsync.StartAsTask (RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; + if (copyToClipboard == true) CopyToClipBoard(result); + return result; } catch (Exception e) { diff --git a/WetPancakeCLI/Program.cs b/WetPancakeCLI/Program.cs index d9c07a3..7f0aa4b 100644 --- a/WetPancakeCLI/Program.cs +++ b/WetPancakeCLI/Program.cs @@ -1,9 +1,11 @@ using Console.Waterworks; +using System; namespace WetPancakeCLI { class Program { + [STAThread] static void Main(string[] args) { var liaison = new CW_Liaison(); diff --git a/WetPancakeCLI/WetPancakeCLI.csproj b/WetPancakeCLI/WetPancakeCLI.csproj index 6d2c114..249747d 100644 --- a/WetPancakeCLI/WetPancakeCLI.csproj +++ b/WetPancakeCLI/WetPancakeCLI.csproj @@ -79,6 +79,7 @@ ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + From f095bc004ef93a582fc0ea2ecd26f256f1a4a1bf Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:02:25 +0100 Subject: [PATCH 2/6] Add Copy ToClipboard functionality to GenerateCleanText command-methods. --- WetPancakeCLI/ConsoleCommands.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/WetPancakeCLI/ConsoleCommands.cs b/WetPancakeCLI/ConsoleCommands.cs index 22f271e..72959d6 100644 --- a/WetPancakeCLI/ConsoleCommands.cs +++ b/WetPancakeCLI/ConsoleCommands.cs @@ -129,10 +129,13 @@ namespace WetPancakeCLI "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 GenerateText counterpart.\n" + - "Gibberish-level must be between 2 and 20.")] - [Parameters("gibberish-level: int, sentences: int")] - [Usage("> GenerateCleanText 5 10")] - public static string GenerateCleanText(int gibberishLevel, int sentences) + "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.")] + [Parameters("gibberish-level: int, sentences: int, copy-to-clip-board: bool")] + [Usage("> GenerateCleanText 5 10 true | > GenerateCleanText 5 4")] + public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false) { try { @@ -142,8 +145,11 @@ namespace WetPancakeCLI if (sentences < 1) throw new ArgumentException ("Invalid argument. Must be greater than 0.", "sentences"); - return FSharpAsync.StartAsTask - (RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; + var result = FSharpAsync.StartAsTask( + RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken) + .Result; + if (copyToClipboard == true) CopyToClipBoard(result); + return result; } catch (Exception e) { @@ -190,7 +196,7 @@ namespace WetPancakeCLI [Description( "Generates random text, the number of sentences generated is randomly determined\n." + "Pass in true to copy result straight to clipboard.")] - [Parameters("copy-to-clipbaord: bool")] + [Parameters("copy-to-clipboard: bool")] [Usage("> GenerateRandomText")] public static string GenerateRandomText(bool copyToClipboard = false) { From 05b7e494079a677e658bae29d5681b665f1dfb8a Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:32:35 +0100 Subject: [PATCH 3/6] Add CopyToClipboard functionality to GenerateCleanTextFromFile command-method. Edit the commmand-method attributes. --- WetPancakeCLI/ConsoleCommands.cs | 41 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/WetPancakeCLI/ConsoleCommands.cs b/WetPancakeCLI/ConsoleCommands.cs index 72959d6..b989ded 100644 --- a/WetPancakeCLI/ConsoleCommands.cs +++ b/WetPancakeCLI/ConsoleCommands.cs @@ -45,11 +45,11 @@ namespace WetPancakeCLI #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 \".\" \"?\" \"!\"")] - [Parameters("sentences: int, text: string")] [Usage("> CleanText 1 \"This is a test sentence. And, this one needs to be removed.\"")] public static string CleanText(int sentences, string text) { @@ -124,6 +124,7 @@ namespace WetPancakeCLI #region Text Generation [ListCommand] + [Parameters("gibberish-level: int, sentences: int, copy-to-clip-board: bool")] [Description( "Generates 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" + @@ -133,8 +134,10 @@ namespace WetPancakeCLI "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.")] - [Parameters("gibberish-level: int, sentences: int, copy-to-clip-board: bool")] - [Usage("> GenerateCleanText 5 10 true | > GenerateCleanText 5 4")] + [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. + "> GenerateCleanText 5 10 true\n" + + "> GenerateCleanText 5 4 false \n" + + "> GenerateCleanText 5 4")] public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false) { try @@ -159,16 +162,23 @@ namespace WetPancakeCLI } [ListCommand] - [Description( - "Loads the specified .txt file and generates text based on it," + + [Parameters("gibberish-level: int, sentences: int, file path: string, copy-to-clip-board: bool")] + [Description("\n" + + "Loads the specified .txt file and generates 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 GenerateTextFromFile counterpart.\n" + - "Gibberish-level must be between 2 and 20.")] - [Parameters("gibberish-level: int, sentences: int, file path: string")] - [Usage("> GenerateCleanTextFromFile 3 6 C:/yourfile.txt")] - public static string GenerateCleanTextFromFile(int gibberishLevel, int sentences, string filePath) + "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. + "> GenerateCleanTextFromFile 3 6 C:/yourfile.txt true \n" + + "> GenerateCleanTextFromFile 5 9 C:/yourfile.txt false\n" + + "> GenerateCleanTextFromFile 5 9 C:/ yourfile.txt")] + public static string GenerateCleanTextFromFile( + int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false) { try { @@ -182,8 +192,12 @@ namespace WetPancakeCLI if (string.Equals(extension, ".txt") != true) throw new FileLoadException ("The file entered is not a plain text (.txt) file.", filePath); - return FSharpAsync.StartAsTask - (RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; + var result = FSharpAsync.StartAsTask( + RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), + _taskCreationOptions, _cancellationToken) + .Result; + if (copyToClipboard == true) CopyToClipBoard(result); + return result; } catch (Exception e) { @@ -197,7 +211,10 @@ namespace WetPancakeCLI "Generates random text, the number of sentences generated is randomly determined\n." + "Pass in true to copy result straight to clipboard.")] [Parameters("copy-to-clipboard: bool")] - [Usage("> GenerateRandomText")] + [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. + "> GenerateRandomText true\n" + + "> GenerateRandomText false\n" + + "> GenerateRandomText")] public static string GenerateRandomText(bool copyToClipboard = false) { try From dbb0310d5fb85441b67531ea397fa0a713bdb3b0 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:43:31 +0100 Subject: [PATCH 4/6] Add CopyToClipboard functionality to GenerateText command-method. Edit the command-method attributes. --- WetPancakeCLI/ConsoleCommands.cs | 47 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/WetPancakeCLI/ConsoleCommands.cs b/WetPancakeCLI/ConsoleCommands.cs index b989ded..569cb40 100644 --- a/WetPancakeCLI/ConsoleCommands.cs +++ b/WetPancakeCLI/ConsoleCommands.cs @@ -21,24 +21,24 @@ namespace WetPancakeCLI static readonly FSharpOption _taskCreationOptions = FSharpOption.None; static readonly FSharpOption _cancellationToken = FSharpOption.None; - static void CopyToClipBoard(string text) => Clipboard.SetText(text); + static void CopyToClipboard(string text) => Clipboard.SetText(text); #region Console Utilities [ListCommand] - [Description("Prints a test message to the console.")] [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] - [Description("Lists out the commands this program offers.")] [Parameters("None")] + [Description("Lists out the commands this program offers.")] [Usage("> Help")] public static string Help() => new CW_Liaison().RequestHelpDocumentation("WetPancakeCLI"); [ListCommand] - [Description("Exits out of the program.")] [Parameters("None")] + [Description("Exits out of the program.")] [Usage("> Exit")] public static void Exit() => Environment.Exit(ExitCode); #endregion @@ -68,8 +68,8 @@ namespace WetPancakeCLI } [ListCommand] - [Description("Returns a list of all the available .txt files built-in to Wet Pancake.")] [Parameters("None")] + [Description("Returns a list of all the available .txt files built-in to Wet Pancake.")] [Usage("> RequestAllTemplateFiles")] public static string RequestAllTemplateFiles() { @@ -93,10 +93,10 @@ namespace WetPancakeCLI } [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 '?'.")] - [Parameters("filePath: string")] [Usage("> ValidateFile \"C:/your-file.txt\"")] public static string ValidateFile(string filePath) { @@ -124,7 +124,7 @@ namespace WetPancakeCLI #region Text Generation [ListCommand] - [Parameters("gibberish-level: int, sentences: int, copy-to-clip-board: bool")] + [Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")] [Description( "Generates 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" + @@ -151,7 +151,7 @@ namespace WetPancakeCLI var result = FSharpAsync.StartAsTask( RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken) .Result; - if (copyToClipboard == true) CopyToClipBoard(result); + if (copyToClipboard == true) CopyToClipboard(result); return result; } catch (Exception e) @@ -162,7 +162,7 @@ namespace WetPancakeCLI } [ListCommand] - [Parameters("gibberish-level: int, sentences: int, file path: string, copy-to-clip-board: bool")] + [Parameters("gibberish-level: int, sentences: int, file path: string, copy-to-clipboard: bool")] [Description("\n" + "Loads the specified .txt file and generates text based on it,\n" + "using the gibberish-level and number of sentences specified by the user.\n" + @@ -196,7 +196,7 @@ namespace WetPancakeCLI RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken) .Result; - if (copyToClipboard == true) CopyToClipBoard(result); + if (copyToClipboard == true) CopyToClipboard(result); return result; } catch (Exception e) @@ -207,10 +207,11 @@ namespace WetPancakeCLI } [ListCommand] - [Description( - "Generates random text, the number of sentences generated is randomly determined\n." + - "Pass in true to copy result straight to clipboard.")] [Parameters("copy-to-clipboard: bool")] + [Description( + "Generates random text, the number of sentences generated 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. "> GenerateRandomText true\n" + "> GenerateRandomText false\n" + @@ -221,7 +222,7 @@ namespace WetPancakeCLI { var result = FSharpAsync.StartAsTask (RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; - if (copyToClipboard == true) CopyToClipBoard(result); + if (copyToClipboard == true) CopyToClipboard(result); return result; } catch (Exception e) @@ -232,15 +233,21 @@ namespace WetPancakeCLI } [ListCommand] + [Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")] [Description( "Generates 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 GenerateCleanText.\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.")] - [Parameters("gibberish-level: int, sentences: int")] - [Usage("> GenerateText 5 10")] - public static string GenerateText(int gibberishLevel, int sentences) + "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. + "> GenerateText 5 10 true\n" + + "> GenerateText 5 10 false\n" + + "> GenerateText 5 10")] + public static string GenerateText(int gibberishLevel, int sentences, bool copyToClipboard = false) { try { @@ -250,8 +257,10 @@ namespace WetPancakeCLI if (sentences < 1) throw new ArgumentException ("Invalid argument. Must be greater than 0.", "sentences"); - return FSharpAsync.StartAsTask + var result = FSharpAsync.StartAsTask (RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; + if (copyToClipboard == true) CopyToClipboard(result); + return result; } catch (Exception e) { From ea32f95c364370329e8565546e6fb574942aecdf Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:54:38 +0100 Subject: [PATCH 5/6] Add CopyToClipboard functionality to GenerateTextFromFile command-method. Edit the command-method's attributes. --- WetPancakeCLI/ConsoleCommands.cs | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/WetPancakeCLI/ConsoleCommands.cs b/WetPancakeCLI/ConsoleCommands.cs index 569cb40..5492dfb 100644 --- a/WetPancakeCLI/ConsoleCommands.cs +++ b/WetPancakeCLI/ConsoleCommands.cs @@ -136,8 +136,8 @@ namespace WetPancakeCLI "Pass in \"false\" or leave blank to not copy the result.")] [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. "> GenerateCleanText 5 10 true\n" + - "> GenerateCleanText 5 4 false \n" + - "> GenerateCleanText 5 4")] + "> GenerateCleanText 3 7 false \n" + + "> GenerateCleanText 9 12")] public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false) { try @@ -176,7 +176,7 @@ namespace WetPancakeCLI [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. "> GenerateCleanTextFromFile 3 6 C:/yourfile.txt true \n" + "> GenerateCleanTextFromFile 5 9 C:/yourfile.txt false\n" + - "> GenerateCleanTextFromFile 5 9 C:/ yourfile.txt")] + "> GenerateCleanTextFromFile 7 15 C:/ yourfile.txt")] public static string GenerateCleanTextFromFile( int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false) { @@ -245,8 +245,8 @@ namespace WetPancakeCLI "Pass in \"false\" or leave blank to not copy the result.")] [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. "> GenerateText 5 10 true\n" + - "> GenerateText 5 10 false\n" + - "> GenerateText 5 10")] + "> GenerateText 7 15 false\n" + + "> GenerateText 10 5")] public static string GenerateText(int gibberishLevel, int sentences, bool copyToClipboard = false) { try @@ -270,15 +270,22 @@ namespace WetPancakeCLI } [ListCommand] + [Parameters("gibberish-level: int, sentences: int, file path: string")] [Description( - "Loads the specified .txt file and generates text based on it using the gibberish-level and number of sentencesspecifiedby the user.\n" + + "Loads the specified .txt file and generates 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 GenerateCleanTextFromFile.\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.")] - [Parameters("gibberish-level: int, sentences: int, file path: string")] - [Usage("> GenerateTextFromFile 3 6 C:/yourfile.txt")] - public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath) + "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. + "> GenerateTextFromFile 3 6 C:/yourfile.txt true\n" + + "> GenerateTextFromFile 6 13 C:/yourfile.txt false \n" + + "> GenerateTextFromFile 12 8 C:/yourfile.txt")] + public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false) { try { @@ -297,8 +304,12 @@ namespace WetPancakeCLI _taskCreationOptions, _cancellationToken).Result; if (fileIsValid == false) throw new Exception("The .txt does not contain a vaild end token ('.', '!' or '?')."); - return FSharpAsync.StartAsTask - (RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; + var result = FSharpAsync.StartAsTask( + RequestTextFromFileAsync(gibberishLevel, sentences, filePath), + _taskCreationOptions, _cancellationToken) + .Result; + if (copyToClipboard == true) CopyToClipboard(result); + return result; } catch (Exception e) { From 6a2d247e57d5d370e590f6a1dd51e5ed79e7e233 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:58:53 +0100 Subject: [PATCH 6/6] Update CLI assembly info. for 0.9 release. --- WetPancakeCLI/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WetPancakeCLI/Properties/AssemblyInfo.cs b/WetPancakeCLI/Properties/AssemblyInfo.cs index 8b754ac..426fa7a 100644 --- a/WetPancakeCLI/Properties/AssemblyInfo.cs +++ b/WetPancakeCLI/Properties/AssemblyInfo.cs @@ -38,7 +38,7 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.8.0.0")] -[assembly: AssemblyFileVersion("0.8.0.0")] +[assembly: AssemblyVersion("0.9.0.0")] +[assembly: AssemblyFileVersion("0.9.0.0")] [assembly: NeutralResourcesLanguage("en-GB")]