-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vijayshinva
committed
Dec 4, 2020
1 parent
3ffc685
commit 44931b1
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.IO; | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace Kryptos | ||
{ | ||
public static class WireUpRngExtensions | ||
{ | ||
public static RootCommand WireUpRngCommands(this RootCommand rootCommand) | ||
{ | ||
var rngCommand = new Command("rng", "Random Number Generator"); | ||
rngCommand.AddOption(new Option<int>(new string[] { "--max", "-m" }, "Maximum (exclusive)")); | ||
rngCommand.AddOption(new Option<FileInfo>(new string[] { "--output", "-o" }, "Output file path")); | ||
|
||
rngCommand.Handler = CommandHandler.Create<int, FileInfo, IConsole>(async (max, output, console) => | ||
{ | ||
try | ||
{ | ||
if (max <= 0) | ||
{ | ||
max = int.MaxValue; | ||
} | ||
var random = RandomNumberGenerator.GetInt32(max); | ||
|
||
if (output == null) | ||
{ | ||
console.Out.WriteLine(random.ToString()); | ||
} | ||
else | ||
{ | ||
await File.WriteAllTextAsync(output.FullName, random.ToString()).ConfigureAwait(false); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
console.Out.WriteLine(ex.Message); | ||
return 22; | ||
} | ||
return 0; | ||
}); | ||
|
||
rootCommand.AddCommand(rngCommand); | ||
|
||
return rootCommand; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters