Browse Source

Add CopyToClipboard functionality to GenerateText command-method.

Edit the command-method attributes.
master
Craig Oates 6 years ago
parent
commit
dbb0310d5f
  1. 47
      WetPancakeCLI/ConsoleCommands.cs

47
WetPancakeCLI/ConsoleCommands.cs

@ -21,24 +21,24 @@ namespace WetPancakeCLI
static readonly FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None; static readonly FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None;
static readonly FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None; static readonly FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None;
static void CopyToClipBoard(string text) => Clipboard.SetText(text); static void CopyToClipboard(string text) => Clipboard.SetText(text);
#region Console Utilities #region Console Utilities
[ListCommand] [ListCommand]
[Description("Prints a test message to the console.")]
[Parameters("None")] [Parameters("None")]
[Description("Prints a test message to the console.")]
[Usage("> Test")] [Usage("> Test")]
public static string Test() => "SUCCESS: Console.Waterworks is wired into Wet Pancake CLI."; public static string Test() => "SUCCESS: Console.Waterworks is wired into Wet Pancake CLI.";
[ListCommand] [ListCommand]
[Description("Lists out the commands this program offers.")]
[Parameters("None")] [Parameters("None")]
[Description("Lists out the commands this program offers.")]
[Usage("> Help")] [Usage("> Help")]
public static string Help() => new CW_Liaison().RequestHelpDocumentation("WetPancakeCLI"); public static string Help() => new CW_Liaison().RequestHelpDocumentation("WetPancakeCLI");
[ListCommand] [ListCommand]
[Description("Exits out of the program.")]
[Parameters("None")] [Parameters("None")]
[Description("Exits out of the program.")]
[Usage("> Exit")] [Usage("> Exit")]
public static void Exit() => Environment.Exit(ExitCode); public static void Exit() => Environment.Exit(ExitCode);
#endregion #endregion
@ -68,8 +68,8 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Description("Returns a list of all the available .txt files built-in to Wet Pancake.")]
[Parameters("None")] [Parameters("None")]
[Description("Returns a list of all the available .txt files built-in to Wet Pancake.")]
[Usage("> RequestAllTemplateFiles")] [Usage("> RequestAllTemplateFiles")]
public static string RequestAllTemplateFiles() public static string RequestAllTemplateFiles()
{ {
@ -93,10 +93,10 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Parameters("filePath: string")]
[Description( [Description(
"Checks the text in the specified .txt file to see if it is compatible with this program.\n" + "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 '?'.")] "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\"")] [Usage("> ValidateFile \"C:/your-file.txt\"")]
public static string ValidateFile(string filePath) public static string ValidateFile(string filePath)
{ {
@ -124,7 +124,7 @@ namespace WetPancakeCLI
#region Text Generation #region Text Generation
[ListCommand] [ListCommand]
[Parameters("gibberish-level: int, sentences: int, copy-to-clip-board: bool")] [Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")]
[Description( [Description(
"Generates text using the gibberish-level and number of sentences specified by the user.\n" + "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" + "The result goes through an extra \"cleaning\" process to remove any artefact sentences.\n" +
@ -151,7 +151,7 @@ namespace WetPancakeCLI
var result = FSharpAsync.StartAsTask( var result = FSharpAsync.StartAsTask(
RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken) RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken)
.Result; .Result;
if (copyToClipboard == true) CopyToClipBoard(result); if (copyToClipboard == true) CopyToClipboard(result);
return result; return result;
} }
catch (Exception e) catch (Exception e)
@ -162,7 +162,7 @@ namespace WetPancakeCLI
} }
[ListCommand] [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" + [Description("\n" +
"Loads the specified .txt file and generates text based on it,\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" + "using the gibberish-level and number of sentences specified by the user.\n" +
@ -196,7 +196,7 @@ namespace WetPancakeCLI
RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath),
_taskCreationOptions, _cancellationToken) _taskCreationOptions, _cancellationToken)
.Result; .Result;
if (copyToClipboard == true) CopyToClipBoard(result); if (copyToClipboard == true) CopyToClipboard(result);
return result; return result;
} }
catch (Exception e) catch (Exception e)
@ -207,10 +207,11 @@ namespace WetPancakeCLI
} }
[ListCommand] [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")] [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. [Usage("\n" + // Added because Console.Waterworks' rendering makes it look weird.
"> GenerateRandomText true\n" + "> GenerateRandomText true\n" +
"> GenerateRandomText false\n" + "> GenerateRandomText false\n" +
@ -221,7 +222,7 @@ namespace WetPancakeCLI
{ {
var result = FSharpAsync.StartAsTask var result = FSharpAsync.StartAsTask
(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; (RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
if (copyToClipboard == true) CopyToClipBoard(result); if (copyToClipboard == true) CopyToClipboard(result);
return result; return result;
} }
catch (Exception e) catch (Exception e)
@ -232,15 +233,21 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Parameters("gibberish-level: int, sentences: int, copy-to-clipboard: bool")]
[Description( [Description(
"Generates text using the gibberish-level and number of sentences specified by the user.\n" + "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 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" + "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")] "Sentences must be greater than 0.\n" +
[Usage("> GenerateText 5 10")] "Pass in \"true\" to copy the result straight to the clipboard.\n" +
public static string GenerateText(int gibberishLevel, int sentences) "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 try
{ {
@ -250,8 +257,10 @@ namespace WetPancakeCLI
if (sentences < 1) if (sentences < 1)
throw new ArgumentException throw new ArgumentException
("Invalid argument. Must be greater than 0.", "sentences"); ("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask var result = FSharpAsync.StartAsTask
(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; (RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
if (copyToClipboard == true) CopyToClipboard(result);
return result;
} }
catch (Exception e) catch (Exception e)
{ {

Loading…
Cancel
Save