Hermod
A cross-platform, modular and fully GDPR-compliant email archival solution!
Loading...
Searching...
No Matches
Hermod.Program Class Reference

Hermod's entry point. More...

Static Private Member Functions

static async Task< int > Main (string[] args)
 
static void InitialiseConfigs ()
 Initialises the application's config manager.
 
static void InitialiseLogger ()
 Initialises the application's logger.
 
static int ParseArgs (string[] args)
 Parses the command-line arguments passed to the application.
 
static void PrintHelp ()
 Prints the help text for hermod.
 
static string GetApplicationVersion ()
 Gets the application's version string.
 
static void PrintVersion ()
 Prints the application's version.
 
static ? LogEventLevel GetLogLevelFromArg (string? arg)
 Converts an incoming application argument to its respective log level.
 

Static Private Attributes

static string _shortOpts = "c:L:hv%Ui"
 
static Option[] _longOpts
 
static ? FileInfo _overriddenConfigLocation = null
 
static ? ILogger _appLogger = null
 
static ? LogEventLevel _logLevel = null
 
static ConfigManager _cfgManager = ConfigManager.Instance
 
static bool _interactiveMode = false
 

Detailed Description

Hermod's entry point.

Handles all pre-init steps and starts execution of the main business logic.

Definition at line 20 of file Program.cs.

Member Function Documentation

◆ GetApplicationVersion()

static string Hermod.Program.GetApplicationVersion ( )
inlinestaticprivate

Gets the application's version string.

Returns
A string matching v0.0.0.0

Definition at line 170 of file Program.cs.

170 {
171 var version = Assembly.GetExecutingAssembly().GetName().Version;
172
173 return $"v{ version?.Major }.{ version?.MajorRevision }.{ version?.Minor }.{ version?.MinorRevision }";
174 }

Referenced by Hermod.Program.PrintHelp().

◆ GetLogLevelFromArg()

static ? LogEventLevel Hermod.Program.GetLogLevelFromArg ( string?  arg)
inlinestaticprivate

Converts an incoming application argument to its respective log level.

Parameters
argThe argument to parse.
Returns
true
if an appropriate log level was found.
false
otherwise.

Definition at line 186 of file Program.cs.

186 {
187 arg = arg?.ToLowerInvariant() ?? string.Empty;
188
189 switch (arg) {
190 case "debug":
191 return LogEventLevel.Debug;
192 case "trace":
193 return LogEventLevel.Verbose;
194 case "warn":
195 case "warning":
196 return LogEventLevel.Warning;
197 case "error":
198 return LogEventLevel.Error;
199 case "info":
200 case "information":
201 return LogEventLevel.Information;
202 case "fatal":
203 return LogEventLevel.Fatal;
204 default:
205 return null;
206 }
207 }

Referenced by Hermod.Program.InitialiseLogger(), and Hermod.Program.ParseArgs().

◆ InitialiseConfigs()

static void Hermod.Program.InitialiseConfigs ( )
inlinestaticprivate

Initialises the application's config manager.

Definition at line 62 of file Program.cs.

62 {
63 if (_overriddenConfigLocation != null) {
64 _cfgManager.ConfigFile = _overriddenConfigLocation;
65 } else {
66 _cfgManager.LoadConfig();
67 }
68 }
static ? FileInfo _overriddenConfigLocation
Definition: Program.cs:34
static ConfigManager _cfgManager
Definition: Program.cs:37

References Hermod.Program._cfgManager, and Hermod.Program._overriddenConfigLocation.

Referenced by Hermod.Program.Main().

◆ InitialiseLogger()

static void Hermod.Program.InitialiseLogger ( )
inlinestaticprivate

Initialises the application's logger.

Definition at line 73 of file Program.cs.

73 {
74 var consoleSettings = _cfgManager.GetConsoleLoggerConfig();
75 var fileSettings = _cfgManager.GetFileLoggerConfig();
76 Core.Logger logger = new Core.Logger() {
77 ConsoleLogLevel = _logLevel ?? GetLogLevelFromArg(consoleSettings.LogLevel) ?? LogEventLevel.Warning,
78 EnableConsoleOutput = consoleSettings.EnableLogging,
79
80 FileLogLevel = GetLogLevelFromArg(fileSettings.LogLevel) ?? LogEventLevel.Information,
81 EnableFileOutput = fileSettings.EnableLogging
82 };
83
84 _appLogger = logger.GetLogger();
85 }
static ? LogEventLevel GetLogLevelFromArg(string? arg)
Converts an incoming application argument to its respective log level.
Definition: Program.cs:186
static ? ILogger _appLogger
Definition: Program.cs:35
static ? LogEventLevel _logLevel
Definition: Program.cs:36

References Hermod.Program._appLogger, Hermod.Program._cfgManager, Hermod.Program._logLevel, Hermod.Core.Logger.GetLogger(), Hermod.Program.GetLogLevelFromArg(), and Hermod.Core.Logger.Logger().

Referenced by Hermod.Program.Main().

◆ Main()

static async Task< int > Hermod.Program.Main ( string[]  args)
inlinestaticprivate

Definition at line 40 of file Program.cs.

40 {
41 var returnCode = ParseArgs(args);
42 if (returnCode != 0) { return returnCode - 1; }
43
45
47
48 _cfgManager.AppLogger = _appLogger;
49
50 var app = new Hermod(_cfgManager, _appLogger ?? Log.Logger) {
51 InteractiveMode = _interactiveMode,
52 m_keepAlive = true
53 };
54 app.StartUp();
55
56 return await app.Execute();
57 }
static int ParseArgs(string[] args)
Parses the command-line arguments passed to the application.
Definition: Program.cs:92
static bool _interactiveMode
Definition: Program.cs:38
static void InitialiseLogger()
Initialises the application's logger.
Definition: Program.cs:73
static void InitialiseConfigs()
Initialises the application's config manager.
Definition: Program.cs:62

References Hermod.Program._appLogger, Hermod.Program._cfgManager, Hermod.Program._interactiveMode, Hermod.Program.InitialiseConfigs(), Hermod.Program.InitialiseLogger(), and Hermod.Program.ParseArgs().

◆ ParseArgs()

static int Hermod.Program.ParseArgs ( string[]  args)
inlinestaticprivate

Parses the command-line arguments passed to the application.

Parameters
argsThe arguments passed.
Returns
0 if program execution shall continue. Non-zero otherwise.

Definition at line 92 of file Program.cs.

92 {
93
94 var getopt = new GetOpt {
95 AppArgs = args,
96 DoubleDashStopsParsing = true,
97 Options = _longOpts,
98 ShortOpts = _shortOpts
99 };
100
101 int optChar = -1;
102 do {
103 optChar = getopt.GetNextOpt(out var optArg);
104
105 switch (optChar) {
106 case -1:
107 case 0:
108 break;
109 case 'h':
110 PrintHelp();
111 return 1;
112 case 'v':
113 PrintVersion();
114 return 1;
115 case 'c':
116 if (string.IsNullOrEmpty(optArg)) {
117 Console.Error.WriteLine("Missing argument for --config!");
118 return 2;
119 }
120 _overriddenConfigLocation = new FileInfo(optArg);
121 break;
122 case 'L':
123 if (string.IsNullOrEmpty(optArg)) {
124 Console.Error.WriteLine("Missing argument for --log-lvl!");
125 return 2;
126 }
128 break;
129 case 'i':
130 _interactiveMode = true;
131 break;
132 default:
133 Console.Error.WriteLine($"The argument { optChar } is not yet implemented!");
134 break;
135 }
136 } while (optChar != -1);
137
138 return 0;
139 }
static void PrintHelp()
Prints the help text for hermod.
Definition: Program.cs:144
static void PrintVersion()
Prints the application's version.
static Option[] _longOpts
Definition: Program.cs:23
static string _shortOpts
Definition: Program.cs:22

References Hermod.Program._interactiveMode, Hermod.Program._logLevel, Hermod.Program._longOpts, Hermod.Program._overriddenConfigLocation, Hermod.Program._shortOpts, Hermod.Program.GetLogLevelFromArg(), Hermod.Program.PrintHelp(), and Hermod.Program.PrintVersion().

Referenced by Hermod.Program.Main().

◆ PrintHelp()

static void Hermod.Program.PrintHelp ( )
inlinestaticprivate

Prints the help text for hermod.

Definition at line 144 of file Program.cs.

144 {
145 Console.WriteLine(
146"""
147hermod {0} - A high-performance, cross-platform email archival and search engine
148
149Usage: (hermod has full getopt support)
150 hermod # no options = normal execution
151 hermod [options]
152
153Switches:
154 --help, -h Display this entry and exit
155 --version, -v Display the application version and exit
156 --reset-cfg, -% !!! DANGER !!! Resets the configurations to their default values!
157
158Arguments:
159 --config, -c<config> Override the application config file location
160 --log-lvl, -L<lvl> Override the log level: debug, trace, error, warning (default), info, critical
161""",
163 );
164 }
static string GetApplicationVersion()
Gets the application's version string.
Definition: Program.cs:170

References Hermod.Program.GetApplicationVersion().

Referenced by Hermod.Program.ParseArgs().

◆ PrintVersion()

static void Hermod.Program.PrintVersion ( )
staticprivate

Prints the application's version.

Referenced by Hermod.Program.ParseArgs().

Member Data Documentation

◆ _appLogger

? ILogger Hermod.Program._appLogger = null
staticprivate

Definition at line 35 of file Program.cs.

Referenced by Hermod.Program.InitialiseLogger(), and Hermod.Program.Main().

◆ _cfgManager

ConfigManager Hermod.Program._cfgManager = ConfigManager.Instance
staticprivate

◆ _interactiveMode

bool Hermod.Program._interactiveMode = false
staticprivate

Definition at line 38 of file Program.cs.

Referenced by Hermod.Program.Main(), and Hermod.Program.ParseArgs().

◆ _logLevel

? LogEventLevel Hermod.Program._logLevel = null
staticprivate

Definition at line 36 of file Program.cs.

Referenced by Hermod.Program.InitialiseLogger(), and Hermod.Program.ParseArgs().

◆ _longOpts

Option [] Hermod.Program._longOpts
staticprivate
Initial value:
= new[] {
new Option { Name = "config", ArgumentType = ArgumentType.Required, Value = 'c' },
new Option { Name = "log-lvl", ArgumentType = ArgumentType.Required, Value = 'L' },
new Option { Name = "help", ArgumentType = ArgumentType.None, Value = 'h' },
new Option { Name = "version", ArgumentType = ArgumentType.None, Value = 'v' },
new Option { Name = "check-updates", ArgumentType = ArgumentType.None, Value = 'U' },
new Option { Name = "reset-cfg", ArgumentType = ArgumentType.Optional, Value = '%' },
new Option { Name = "interactive", ArgumentType = ArgumentType.None, Value = 'i' }
}

Definition at line 23 of file Program.cs.

Referenced by Hermod.Program.ParseArgs().

◆ _overriddenConfigLocation

? FileInfo Hermod.Program._overriddenConfigLocation = null
staticprivate

Definition at line 34 of file Program.cs.

Referenced by Hermod.Program.InitialiseConfigs(), and Hermod.Program.ParseArgs().

◆ _shortOpts

string Hermod.Program._shortOpts = "c:L:hv%Ui"
staticprivate

Definition at line 22 of file Program.cs.

Referenced by Hermod.Program.ParseArgs().


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