Browse Source

Merge pull request #15 from CraigOates/0.9-p1

0.8.1
master
Craig Oates 6 years ago committed by GitHub
parent
commit
df136d2c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 138
      WetPancakeCLI/ConsoleCommands.cs
  2. 2
      WetPancakeCLI/Program.cs
  3. 4
      WetPancakeCLI/Properties/AssemblyInfo.cs
  4. 1
      WetPancakeCLI/WetPancakeCLI.csproj

138
WetPancakeCLI/ConsoleCommands.cs

@ -1,15 +1,16 @@
using Console.Waterworks; using Console.Waterworks;
using Console.Waterworks.Attributes; using Console.Waterworks.Attributes;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
using System; using System;
using static WetPancake.Pancake;
using static System.Environment;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.FSharp.Control;
using Microsoft.FSharp.Core;
using System.Threading; using System.Threading;
using System.IO; using System.Windows.Forms;
using static System.Environment;
using static System.Console; using static System.Console;
using static WetPancake.Pancake;
namespace WetPancakeCLI namespace WetPancakeCLI
{ {
@ -17,36 +18,38 @@ namespace WetPancakeCLI
{ {
// Pass these in when running an FSharpAsync task. // Pass these in when running an FSharpAsync task.
// Examples are within the command-methods. // Examples are within the command-methods.
static FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None; static readonly FSharpOption<TaskCreationOptions> _taskCreationOptions = FSharpOption<TaskCreationOptions>.None;
static FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None; static readonly FSharpOption<CancellationToken> _cancellationToken = FSharpOption<CancellationToken>.None;
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
#region Wet Pancake Utilities #region Wet Pancake Utilities
[ListCommand] [ListCommand]
[Parameters("sentences: int, text: string")]
[Description( [Description(
"Checks to see if the string matches the desired sentence count and removes any over that limit.\n" + "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" + "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 \".\" \"?\" \"!\"")] "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.\"")] [Usage("> CleanText 1 \"This is a test sentence. And, this one needs to be removed.\"")]
public static string CleanText(int sentences, string text) public static string CleanText(int sentences, string text)
{ {
@ -65,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()
{ {
@ -90,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)
{ {
@ -121,15 +124,21 @@ namespace WetPancakeCLI
#region Text Generation #region Text Generation
[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" +
"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" +
"Use this if you cannot tolerate the odd extra sentence.\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" + "With that said, it does mean it is slower than its GenerateText counterpart.\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("> GenerateCleanText 5 10")] "Pass in \"true\" to copy the result straight to the clipboard.\n" +
public static string GenerateCleanText(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.
"> GenerateCleanText 5 10 true\n" +
"> GenerateCleanText 3 7 false \n" +
"> GenerateCleanText 9 12")]
public static string GenerateCleanText(int gibberishLevel, int sentences, bool copyToClipboard = false)
{ {
try try
{ {
@ -139,8 +148,11 @@ 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(
(RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; RequestCleanTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken)
.Result;
if (copyToClipboard == true) CopyToClipboard(result);
return result;
} }
catch (Exception e) catch (Exception e)
{ {
@ -150,16 +162,23 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Description( [Parameters("gibberish-level: int, sentences: int, file path: string, copy-to-clipboard: bool")]
"Loads the specified .txt file and generates text based on it," + [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" + "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" +
"Use this if you cannot tolerate the odd extra sentence.\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" + "With that said, it does mean it is slower than its GenerateTextFromFile counterpart.\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("> GenerateCleanTextFromFile 3 6 C:/yourfile.txt")] "Pass in \"true\" to copy the result straight to the clipboard.\n" +
public static string GenerateCleanTextFromFile(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.
"> GenerateCleanTextFromFile 3 6 C:/yourfile.txt true \n" +
"> GenerateCleanTextFromFile 5 9 C:/yourfile.txt false\n" +
"> GenerateCleanTextFromFile 7 15 C:/ yourfile.txt")]
public static string GenerateCleanTextFromFile(
int gibberishLevel, int sentences, string filePath, bool copyToClipboard = false)
{ {
try try
{ {
@ -173,8 +192,12 @@ namespace WetPancakeCLI
if (string.Equals(extension, ".txt") != true) if (string.Equals(extension, ".txt") != true)
throw new FileLoadException throw new FileLoadException
("The file entered is not a plain text (.txt) file.", filePath); ("The file entered is not a plain text (.txt) file.", filePath);
return FSharpAsync.StartAsTask var result = FSharpAsync.StartAsTask(
(RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; RequestCleanTextFromFileAsync(gibberishLevel, sentences, filePath),
_taskCreationOptions, _cancellationToken)
.Result;
if (copyToClipboard == true) CopyToClipboard(result);
return result;
} }
catch (Exception e) catch (Exception e)
{ {
@ -184,15 +207,23 @@ namespace WetPancakeCLI
} }
[ListCommand] [ListCommand]
[Description("Generates random text, the number of sentences generated is randomly determined.")] [Parameters("copy-to-clipboard: bool")]
[Parameters("None")] [Description(
[Usage("> GenerateRandomText")] "Generates random text, the number of sentences generated is randomly determined.\n" +
public static string GenerateRandomText() "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" +
"> GenerateRandomText")]
public static string GenerateRandomText(bool copyToClipboard = false)
{ {
try try
{ {
return FSharpAsync.StartAsTask var result = FSharpAsync.StartAsTask
(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; (RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
if (copyToClipboard == true) CopyToClipboard(result);
return result;
} }
catch (Exception e) catch (Exception e)
{ {
@ -202,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 7 15 false\n" +
"> GenerateText 10 5")]
public static string GenerateText(int gibberishLevel, int sentences, bool copyToClipboard = false)
{ {
try try
{ {
@ -220,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)
{ {
@ -231,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
{ {
@ -258,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)
{ {

2
WetPancakeCLI/Program.cs

@ -1,9 +1,11 @@
using Console.Waterworks; using Console.Waterworks;
using System;
namespace WetPancakeCLI namespace WetPancakeCLI
{ {
class Program class Program
{ {
[STAThread]
static void Main(string[] args) static void Main(string[] args)
{ {
var liaison = new CW_Liaison(); var liaison = new CW_Liaison();

4
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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.0.0")] [assembly: AssemblyVersion("0.9.0.0")]
[assembly: AssemblyFileVersion("0.8.0.0")] [assembly: AssemblyFileVersion("0.9.0.0")]
[assembly: NeutralResourcesLanguage("en-GB")] [assembly: NeutralResourcesLanguage("en-GB")]

1
WetPancakeCLI/WetPancakeCLI.csproj

@ -79,6 +79,7 @@
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />

Loading…
Cancel
Save