From dbb0310d5fb85441b67531ea397fa0a713bdb3b0 Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 6 Aug 2018 20:43:31 +0100 Subject: [PATCH] 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) {