NTP Analyzer  0.8.2
Analyze the operation of time servers
HelpCommand.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System.Linq;
23 using System.Text;
24 
25 namespace Ntp.Analyzer.Monitor.Server.TextCommand
26 {
27  internal sealed class HelpCommand : MonitorTextCommand
28  {
29  public HelpCommand(string[] args)
30  : base(args)
31  {
32  }
33 
34  public HelpCommand(bool error)
35  : base(new string[0])
36  {
37  this.error = error;
38  }
39 
40  private readonly bool error;
41 
42  protected override string ExecuteTextCommand()
43  {
44  var builder = new StringBuilder();
45 
46  if (error)
47  {
48  builder.AppendLine("Unknown command.");
49  builder.AppendLine();
50  }
51 
52  var version = new VersionCommand(new string[0]);
53  builder.Append(version.Execute());
54  builder.AppendLine(". the following commands are valid.");
55 
56  int length = CommandFactory.Commands.Max(c => c.Description.Length);
57  length += 15 + 3;
58 
59  builder.AppendLine(string.Empty.PadLeft(length, '-'));
60 
61  foreach (ICommandDescription command in CommandFactory.Commands.OrderBy(c => c.Name))
62  {
63  builder.Append(command.Name.PadRight(15));
64  builder.AppendLine(command.Description);
65  }
66 
67  return builder.ToString();
68  }
69  }
70 }
var c
Definition: bootstrap.min.js:6
static readonly IList< ICommandDescription > Commands
var version
Definition: bootstrap.js:13