I'm Trying to compile the following code on a project
...
namespace Buzzbox
{
class Program
{
//Command line options through CommandLine: http://commandline.codeplex.com/
class Options
{
[Option('i', "input",
Required = true,
HelpText = "Path to input file to be Encoded, must be in hearthstonejson format.")]
public string InputFile { get; set; }
[Option('o', "output",
HelpText = "Output file path.",
Default = "output.txt")]
public string OutputFile { get; set; }
[Option('e', "encoding",
HelpText = "Which encoding format to use. Supported formats are scfdivineFormat and MtgEncoderFormat.",
Default = EncodingFormats.MtgEncoderFormat)]
public EncodingFormats EncodingFormat { get; set; }
[Option("shuffle-fields", Default = false,
HelpText = "Shuffles the fields of the output in supported Encoding Formats.")]
public bool ShuffleFields { get; set; }
[Option("shuffle-cards", Default = false,
HelpText = "Shuffles the the cards, randomizing the order of output.")]
public bool ShuffleCards { get; set; }
[Option("flavor-text", Default = false,
HelpText = "Include flavortext field.")]
public bool FlavorText { get; set; }
[Option("verbose", Default = false,
HelpText = "Output additional information. Exclusive with the --silent option.")]
public bool Verbose { get; set; }
[Option("silent", Default = false,
HelpText = "Never output anything but error messages. Exclusive with the --verbose option.")]
public bool Silent { get; set; }
}
private static void Main(string[] args)
{
//Parse Commandline options
var options = new Options();
var encode = new Encode
{
ShuffleFields = options.ShuffleFields,
IncludeFlavorText = options.FlavorText
};
//Only continue if commandline options fullfilled. CommandLine will handle helptext if something was off.
if (CommandLine.Parser.Default.ParseArguments(args,options))
{
//extra things
}
}
}
}
But I just seem to make it work since there's an error on this line
CommandLine.Parser.Default.ParseArguments(args,options)
Exception Thrown
Cannot convert from 'Buzzbox.Program.Options' to 'System.Type'
It doesn't allow me to hardcast it and I'haven't found anything whatsoever on ho to solve this issue although I feel like the solution might be rather simple since I find some other people mentioning it like you can just cast it like this code does without any problem like in here
http://simontimms.com/2014/07/09/parsing-command-line-arguments-in-c/
So I did some digging around apparently in the latest version of the Command Line parser application its required that you do things as follows.
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(opts => options = opts);
I had a ruff time finding the proper way to do this as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With