CodeGen
 All Classes Namespaces Files Functions Variables Properties Pages
Program.cs
Go to the documentation of this file.
1 using System;
2 using CodeGen.generators;
3 using CommandLine;
4 
5 namespace CodeGen
6 {
7  internal class Options
8  {
9  public Options(string lang, string file, int? spaces, bool stdout)
10  {
11  Lang = lang;
12  File = file;
13  Spaces = spaces;
14  Stdout = stdout;
15  }
16 
17  [Option('l', "lang", Default = Program.DefaultLang, HelpText = "Languege of output")]
18  public string Lang { get; }
19 
20 // // Omitting long name, defaults to name of property, ie "--verbose"
21 // [Option(Default = false, HelpText = "Prints all messages to standard output.")]
22 // public bool Verbose { get; set; }
23 
24  [Option('f', "file", Default = "", HelpText = "File or url from which to read data")]
25  public string File { get; }
26 
27  [Option('s', "spaces", Default = -1, HelpText = "Spaces offset (if not set or negative - using tabs)")]
28  public int? Spaces { get; }
29 
30  // Set Default to false in production
31  [Option('o', "stdout", Default = true, HelpText = "")]
32  public bool Stdout { get; }
33 
34  public override string ToString()
35  {
36  return $"{{ -l=\"{Lang}\" -f=\"{File}\" -s={Spaces} {(Stdout ? "-o" : "")}}}";
37  }
38  }
39 
40  internal static class Program
41  {
42  public const string DefaultLang = "vb";
43 
44  public static readonly Package DefaultPkg = GeneratorConf.ExamplePkg;
45 
46  public static Options Opts;
47 
48  private static void Main(string[] args)
49  {
50  Parser.Default.ParseArguments<Options>(args)
51  .WithParsed(opts => Opts = opts)
52  .WithNotParsed(Console.WriteLine);
53  try
54  {
55  #if DEBUG
56 // Console.Out.WriteLine("Opts = {0}", Opts);
57  #endif
58  var langName = Opts != null ? Opts.Lang : DefaultLang;
59  ExecuteConf.Execute(langName, Opts?.File, Opts != null && Opts.Stdout);
60  }
61  catch (Exception e)
62  {
63  Console.WriteLine(e);
64  }
65  }
66  }
67 }
The structure that describes package. Contains classes and subpackages
Definition: Models.cs:9