7/6/2023 0 Comments App iconsoleCheck out the Wiki and Repository for more and perhaps get involved in this open source project! If you want less magic and more power, you can use the same APIs DragonFruit uses to make very sophisticated behaviors. So DragonFruit has swapped your Main for its smarter Main and the magic happens! You'll even get free auto-generated help! DragonFruit: Return await CommandLine.ExecuteAssemblyAsync(typeof(AutoGeneratedProgram).Assembly, args, "") public static async Task Main(string args) It's then replaced with a Main like this, but you'll never see it as it's in the compiled/generated artifact. During the build process, DragonFruit changes this public strongly typed Main to a private (so it's not seen from the outside. The way DragonFruit does this is super clever. I can run it like this: > dotnet run -flavor Vanilla -count 3 NET do the boring stuff for you in an easy and idiomatic way?įrom their docs, what if you could declare a strongly-typed Main method? This was the question that led to the creation of the experimental app model called "DragonFruit", which allows you to create an entry point with multiple parameters of various types and using default values, like this: static void Main(int intOption = 42, bool boolOption = false, FileInfo fileOption = null)Ĭonsole.WriteLine($"The value of intOption is: ") The larger question - one that DragonFruit tries to answer - is why doesn't. In my experience, a simple console app with real proper command line arg validation can end up with half the code parsing crap and half doing stuff. If you want to make an app that does a bunch of different stuff, you've got a lot of string parsing before you get to DO the actual stuff you're app is supposed to do. Argc is gone because you can just args.Length. It's a pretty straight conceptual port from C to C#, right? It's an array of strings. The actual parsing of the command line arguments and the semantic meaning of the args you've decided on are totally on you.Ĭ# has done it this way, since always. That first argument argc is the count of the number of arguments you've passed in, and argv is an array of pointers to 'strings,' essentially. Historically Console apps in classic C look like this: #include The one I am the most infatuated with is DragonFruit. These are interesting experiments and directions that are exploring how to make Console apps easier to write, more compelling, and more useful. Within the repository are three packages: There's some interesting stuff quietly happening in the "Console App" world within open source.
0 Comments
Leave a Reply. |