Skip to content

Instantly share code, notes, and snippets.

@0x414c49
Last active January 2, 2020 13:48
Show Gist options
  • Save 0x414c49/e4380bebaba5d1e3b43e3f3b2e6ac7a2 to your computer and use it in GitHub Desktop.
Save 0x414c49/e4380bebaba5d1e3b43e3f3b2e6ac7a2 to your computer and use it in GitHub Desktop.
CLI 2
#region convert-command
app.Command("convert",
(convert) =>
{
var outputOption = convert.Option("-o|--output", "Output File"
, CommandOptionType.SingleValue);
var firstRowOption = convert.Option("-f|--first-row-header", "First row as header"
, CommandOptionType.NoValue);
convert.HelpOption("-? | -h | --help");
convert.OnExecute(() =>
{
if (verboseOption.HasValue())
Console.WriteLine($"Init process file {inputFileOption.ParsedValue}.");
var inputFile = GetInputFile(inputFileOption);
var outputFile = outputOption.Value()
?? Path.GetFileNameWithoutExtension(inputFile);
if (verboseOption.HasValue() && firstRowOption.HasValue())
Console.WriteLine("Find first row as header.");
if (verboseOption.HasValue())
Console.WriteLine($"Convert to {outputFile}.xlsx");
// do the conversation!
});
}
);
#endregion convert-command
#region print-command
app.Command("print", (print) =>
{
var tailOptions = print.Option<bool>("-t|--tail", "Show n rows from the tail."
, CommandOptionType.NoValue);
var rowOption = print.Option<int>("-r|--rows",
"Number of rows to show", CommandOptionType.SingleValue);
print.HelpOption("-? | -h | --help");
print.OnExecute(() =>
{
var inputFile = GetInputFile(inputFileOption);
// Zero = all rows
var rows = rowOption.HasValue() ? Math.Abs(rowOption.ParsedValue) : 0;
if (verboseOption.HasValue())
Console.WriteLine(tailOptions.HasValue() && rows > 0
? $"Print {rows} records from the tail."
: $"Print {rows} records from the top.");
// print file
Console.WriteLine("print.");
});
});
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment