NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Validate.Cli.Program Class Reference

Static Public Member Functions

static int Main (string[] args)
 

Static Private Member Functions

static Configuration LoadConfig (string configFile)
 
static void SetDecompilerParam (Decompiler decompiler, char indent, string count)
 
static void ShowUsage ()
 

Private Attributes

const int ConfigErrorCode = 1
 
const int ParameterErrorCode = 2
 
const int SuccessCode = 0
 

Static Private Attributes

static bool usage
 

Detailed Description

Definition at line 33 of file Program.cs.

Member Function Documentation

static Configuration Ntp.Analyzer.Validate.Cli.Program.LoadConfig ( string  configFile)
inlinestaticprivate

Definition at line 113 of file Program.cs.

114  {
115  if (!File.Exists(configFile))
116  {
117  Console.WriteLine($"Cannot find configuration file {configFile}");
118  return null;
119  }
120 
121  var reader = new ConfigBuilder(configFile);
122  var config = reader.Execute();
123  if (config != null)
124  return config;
125 
126  foreach (string error in reader.Errors)
127  {
128  Console.WriteLine(error);
129  }
130 
131  return null;
132  }
static int Ntp.Analyzer.Validate.Cli.Program.Main ( string[]  args)
inlinestatic

Definition at line 40 of file Program.cs.

References e.

41  {
42  Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
43  bool validate = false;
44  bool show = false;
45 
46  var dec = new Decompiler();
47  var param = new OptionSet
48  {
49  {"h|?|help", v => { ShowUsage(); }},
50  {"s|show", v => { show = true; }},
51  {"d|default", v => { dec.ShowDefaultValues = true; }},
52  {"v|validate", v => { validate = true; }},
53  {"t=|tabs=", v => SetDecompilerParam(dec, '\t', v)},
54  {"w=|whitespace=", v => SetDecompilerParam(dec, ' ', v)}
55  };
56 
57  string[] rem;
58 
59  try
60  {
61  rem = param.Parse(args).ToArray();
62  }
63  catch (Exception e)
64  {
65  Console.WriteLine(e.Message);
66  return ParameterErrorCode;
67  }
68 
69  if (usage)
70  {
71  return ParameterErrorCode;
72  }
73 
74  if (rem.Length != 1)
75  {
76  Console.WriteLine("Wrong parameters.");
77  return ParameterErrorCode;
78  }
79 
80  if (!show && !validate)
81  {
82  ShowUsage();
83  return ParameterErrorCode;
84  }
85 
86  Configuration config;
87  try
88  {
89  config = LoadConfig(rem[0]);
90  }
91  catch (Exception e)
92  {
93  Console.WriteLine($"Unexpected error while loading configuration file: {e.Message}");
94  return ConfigErrorCode;
95  }
96 
97  if (config == null)
98  return ConfigErrorCode;
99 
100  if (show)
101  {
102  dec.Configuration = config;
103  Console.Write(dec.Execute());
104  }
105  else if (validate)
106  {
107  Console.WriteLine("Configuration is valid.");
108  }
109 
110  return SuccessCode;
111  }
static void SetDecompilerParam(Decompiler decompiler, char indent, string count)
Definition: Program.cs:134
static Configuration LoadConfig(string configFile)
Definition: Program.cs:113
var e
Definition: bootstrap.min.js:6
static void Ntp.Analyzer.Validate.Cli.Program.SetDecompilerParam ( Decompiler  decompiler,
char  indent,
string  count 
)
inlinestaticprivate

Definition at line 134 of file Program.cs.

References Ntp.Analyzer.Config.Compiler.Decompiler.IndentChar, and Ntp.Analyzer.Config.Compiler.Decompiler.IndentSize.

135  {
136  int parsed;
137  decompiler.IndentChar = indent;
138  decompiler.IndentSize = int.TryParse(count, out parsed) ? parsed : 1;
139  }
char IndentChar
Gets or sets the indent char.
Definition: Decompiler.cs:64
int IndentSize
Gets or sets the size of the indent.
Definition: Decompiler.cs:70
static void Ntp.Analyzer.Validate.Cli.Program.ShowUsage ( )
inlinestaticprivate

Definition at line 141 of file Program.cs.

142  {
143  Console.WriteLine("NTP Analyzer validator tool v0.8.2");
144  Console.WriteLine("Usage: ntpav [-s|-v] [-d] [-t n|-w n] configuration");
145  Console.WriteLine(" -s Show parsed configuration");
146  Console.WriteLine(" -v Check if configuration is valid");
147  Console.WriteLine(" -d Show all default value");
148  Console.WriteLine(" -t Indent with n tabulators");
149  Console.WriteLine(" -w Indent with n whitespaces");
150  usage = true;
151  }

Member Data Documentation

const int Ntp.Analyzer.Validate.Cli.Program.ConfigErrorCode = 1
private

Definition at line 36 of file Program.cs.

const int Ntp.Analyzer.Validate.Cli.Program.ParameterErrorCode = 2
private

Definition at line 35 of file Program.cs.

const int Ntp.Analyzer.Validate.Cli.Program.SuccessCode = 0
private

Definition at line 37 of file Program.cs.

bool Ntp.Analyzer.Validate.Cli.Program.usage
staticprivate

Definition at line 38 of file Program.cs.


The documentation for this class was generated from the following file: