Browse Source

Add CopyToClipboard functionality to GenerateTextFromFile command-method.

Edit the command-method's attributes.
master
Craig Oates 6 years ago
parent
commit
ea32f95c36
  1. 35
      WetPancakeCLI/ConsoleCommands.cs

35
WetPancakeCLI/ConsoleCommands.cs

@ -136,8 +136,8 @@ namespace WetPancakeCLI
"Pass in \"false\" or leave blank to not copy the result.")] "Pass in \"false\" or leave blank to not copy the result.")]
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
"> GenerateCleanText 5 10 true\n" + "> GenerateCleanText 5 10 true\n" +
"> GenerateCleanText 5 4 false \n" + "> GenerateCleanText 3 7 false \n" +
"> GenerateCleanText 5 4")] "> GenerateCleanText 9 12")]
public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false) public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false)
{ {
try try
@ -176,7 +176,7 @@ namespace WetPancakeCLI
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
"> GenerateCleanTextFromFile 3 6 C:/yourfile.txt true \n" + "> GenerateCleanTextFromFile 3 6 C:/yourfile.txt true \n" +
"> GenerateCleanTextFromFile 5 9 C:/yourfile.txt false\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( public static string GenerateCleanTextFromFile(
int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false) 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.")] "Pass in \"false\" or leave blank to not copy the result.")]
[Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird. [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
"> GenerateText 5 10 true\n" + "> GenerateText 5 10 true\n" +
"> GenerateText 5 10 false\n" + "> GenerateText 7 15 false\n" +
"> GenerateText 5 10")] "> GenerateText 10 5")]
public static string GenerateText(int gibberishLevel, int sentences, bool copyToClipboard = false) public static string GenerateText(int gibberishLevel, int sentences, bool copyToClipboard = false)
{ {
try try
@ -270,15 +270,22 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Parameters("gibberish-level: int, sentences: int, file path: string")]
[Description( [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 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" + "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" + "Use this if you prefer speed over accuracy.\n" +
"Gibberish-level must be between 2 and 20.")] "Gibberish-level must be between 2 and 20.\n" +
[Parameters("gibberish-level: int, sentences: int, file path: string")] "Sentences must be greater than 0.\n" +
[Usage("> GenerateTextFromFile 3 6 C:/yourfile.txt")] "Pass in \"true\" to copy the result straight to the clipboard.\n" +
public static string GenerateTextFromFile(int gibberishLevel, int sentences, string filePath) "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 try
{ {
@ -297,8 +304,12 @@ namespace WetPancakeCLI
_taskCreationOptions, _cancellationToken).Result; _taskCreationOptions, _cancellationToken).Result;
if (fileIsValid == false) if (fileIsValid == false)
throw new Exception("The .txt does not contain a vaild end token ('.', '!' or '?')."); throw new Exception("The .txt does not contain a vaild end token ('.', '!' or '?').");
return FSharpAsync.StartAsTask var result = FSharpAsync.StartAsTask(
(RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; RequestTextFromFileAsync(gibberishLevel, sentences, filePath),
_taskCreationOptions, _cancellationToken)
.Result;
if (copyToClipboard == true) CopyToClipboard(result);
return result;
} }
catch (Exception e) catch (Exception e)
{ {

Loading…
Cancel
Save