@ -20,6 +20,7 @@ namespace WetPancakeCLI
static FSharpOption < TaskCreationOptions > _ taskCreationOptions = FSharpOption < TaskCreationOptions > . None ;
static FSharpOption < CancellationToken > _ cancellationToken = FSharpOption < CancellationToken > . None ;
#region Console Utilities
[ListCommand]
[Description("Prints a test message to the console.")]
[Parameters("None")]
@ -37,17 +38,24 @@ namespace WetPancakeCLI
[Parameters("None")]
[Usage("> Exit")]
public static void Exit ( ) = > Environment . Exit ( ExitCode ) ;
# endregion
#region Wet Pancake Utilities
[ListCommand]
[Description("Generates random text, the number of sentences generated is randomly determined.")]
[Parameters("None")]
[Usage("> GenerateRandomText")]
public static string GenerateRandomText ( )
[ 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 )
{
try
{
if ( sentences < 1 )
throw new ArgumentException ( "Invalid argument. Must be greater than 0" , "sentences" ) ;
return FSharpAsync . StartAsTask
( RequestRandomTextAsync ( ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
( CleanResultAsync ( sentences , text ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
}
catch ( Exception e )
{
@ -57,57 +65,20 @@ namespace WetPancakeCLI
}
[ListCommand]
[ 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 )
[Description("Returns a list of all the available .txt files built-in to Wet Pancake.")]
[Parameters("None")]
[Usage("> RequestAllTemplateFiles")]
public static string RequestAllTemplateFiles ( )
{
try
{
if ( gibberishLevel < 2 | | gibberishLevel > 2 0 )
throw new ArgumentException
( "Invalid argument. Must be between 2 and 20 (inclusive)." , "gibberish-level" ) ;
if ( sentences < 1 )
throw new ArgumentException
( "Invalid argument. Must be greater than 0." , "sentences" ) ;
return FSharpAsync . StartAsTask
( RequestTextAsync ( gibberishLevel , sentences ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
}
catch ( Exception e )
WriteLine ( "Attempting to list out the available template files..." ) ;
var files = FSharpAsync . StartAsTask ( RequestAllTemplateFilesAsync ( ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
foreach ( var item in files )
{
Debug . WriteLine ( e . Message ) ;
throw ;
}
WriteLine ( $"File path: {item}" ) ;
}
[ListCommand]
[ Description ( "Loads the specified .txt file and generates text based on it 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 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 )
{
try
{
if ( gibberishLevel < 2 | | gibberishLevel > 2 0 )
throw new ArgumentException
( "Invalid argument. Must be between 2 and 20 (inclusive)." , "gibberish-level" ) ;
if ( sentences < 1 )
throw new ArgumentException
( "Invalid argument. Must be greater than 0." , "sentences" ) ;
if ( Path . GetExtension ( filePath ) ! = ".txt" )
throw new FileLoadException
( "The file entered is not a plain text (.txt) file." , filePath ) ;
return FSharpAsync . StartAsTask
( RequestTextFromFileAsync ( gibberishLevel , sentences , filePath ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
return "Listing complete." ;
}
catch ( Exception e )
{
@ -117,20 +88,24 @@ namespace WetPancakeCLI
}
[ListCommand]
[Description("Returns a list of all the available .txt files built-in to Wet Pancake. ")]
[Parameters("None ")]
[Usage("> RequestAllTemplateFiles ")]
public static string RequestAllTemplateFiles ( )
[Description("Checks the text in the specified .txt file to see if it ")]
[Parameters("filePath: string ")]
[Usage("> ValidateFile \"C:/your-file.txt\" ")]
public static string ValidateFile ( string filePath )
{
try
{
WriteLine ( "Attempting to list out the available template files ..." ) ;
var files = FSharpAsync . StartAsTask ( RequestAllTemplateFilesAsync ( ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
foreach ( var item in files )
WriteLine ( "Validating file. Please wait ..." ) ;
var extension = Path . GetExtension ( filePath ) ;
if ( string . Equals ( extension , ".txt" ) )
{
WriteLine ( $"File path: {item}" ) ;
var isValid =
FSharpAsync . StartAsTask ( TextInFileIsValidAsync ( filePath ) ,
_ taskCreationOptions , _ cancellationToken ) . Result ;
return $"Is Valid: {isValid}" ;
}
return "Listing complete." ;
else
throw new FileLoadException ( "The file entered is not a plain text (.txt) file." , filePath ) ;
}
catch ( Exception e )
{
@ -138,9 +113,12 @@ namespace WetPancakeCLI
throw ;
}
}
# endregion
#region Text Generation
[ListCommand]
[ Description ( "Generates text using the gibberish-level and number of sentences specified by the user.\n" +
[ 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" +
"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" +
@ -168,7 +146,9 @@ namespace WetPancakeCLI
}
[ListCommand]
[ Description ( "Loads the specified .txt file and generates text based on it, using the gibberish-level and number of specified by the user.\n" +
[ Description (
"Loads the specified .txt file and generates text based on it," +
"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" +
@ -185,7 +165,8 @@ namespace WetPancakeCLI
if ( sentences < 1 )
throw new ArgumentException
( "Invalid argument. Must be greater than 0." , "sentences" ) ;
if ( Path . GetExtension ( filePath ) ! = ".txt" )
var extension = Path . GetExtension ( filePath ) ;
if ( string . Equals ( extension , ".txt" ) ! = true )
throw new FileLoadException
( "The file entered is not a plain text (.txt) file." , filePath ) ;
return FSharpAsync . StartAsTask
@ -199,19 +180,82 @@ namespace WetPancakeCLI
}
[ListCommand]
[ 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 )
[Description("Generates random text, the number of sentences generated is randomly determined.")]
[Parameters("None")]
[Usage("> GenerateRandomText")]
public static string GenerateRandomText ( )
{
try
{
return FSharpAsync . StartAsTask
( RequestRandomTextAsync ( ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
}
catch ( Exception e )
{
Debug . WriteLine ( e . Message ) ;
throw ;
}
}
[ListCommand]
[ 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 )
{
try
{
if ( gibberishLevel < 2 | | gibberishLevel > 2 0 )
throw new ArgumentException
( "Invalid argument. Must be between 2 and 20 (inclusive)." , "gibberish-level" ) ;
if ( sentences < 1 )
throw new ArgumentException ( "Invalid argument. Must be greater than 0" , "sentences" ) ;
throw new ArgumentException
( "Invalid argument. Must be greater than 0." , "sentences" ) ;
return FSharpAsync . StartAsTask
( CleanResultAsync ( sentences , text ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
( RequestTextAsync ( gibberishLevel , sentences ) , _ taskCreationOptions , _ cancellationToken ) . Result ;
}
catch ( Exception e )
{
Debug . WriteLine ( e . Message ) ;
throw ;
}
}
[ListCommand]
[ Description (
"Loads the specified .txt file and generates text based on it 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 )
{
try
{
if ( gibberishLevel < 2 | | gibberishLevel > 2 0 )
throw new ArgumentException
( "Invalid argument. Must be between 2 and 20 (inclusive)." , "gibberish-level" ) ;
if ( sentences < 1 )
throw new ArgumentException
( "Invalid argument. Must be greater than 0." , "sentences" ) ;
var extension = Path . GetExtension ( filePath ) ;
if ( string . Equals ( extension , ".txt" ) ! = true )
throw new FileLoadException
( "The file entered is not a plain text (.txt) file." , filePath ) ;
var fileIsValid =
FSharpAsync . StartAsTask ( TextInFileIsValidAsync ( filePath ) ,
_ 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 ;
}
catch ( Exception e )
{
@ -219,5 +263,6 @@ namespace WetPancakeCLI
throw ;
}
}
# endregion
}
}