• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MeindertN / RoboClerk / 15744196809

18 Jun 2025 05:49PM UTC coverage: 83.445% (+3.5%) from 79.923%
15744196809

push

github

web-flow
Merge pull request #62 from MeindertN/V1.5.0

V1.5.0

1574 of 1915 branches covered (82.19%)

Branch coverage included in aggregate %.

868 of 1110 new or added lines in 27 files covered. (78.2%)

6 existing lines in 2 files now uncovered.

5029 of 5998 relevant lines covered (83.84%)

108.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/RoboClerk/Program.cs
1
using CommandLine;
2
using Microsoft.Extensions.DependencyInjection;
3
using NLog;
4
using RoboClerk.Configuration;
5
using System;
6
using System.Collections.Generic;
7
using System.IO;
8
using System.IO.Abstractions;
9
using System.Reflection;
10
using Tomlyn;
11

12
[assembly: AssemblyVersion("1.5.*")]
13

14
namespace RoboClerk
15
{
16
    class Program
17
    {
18
        private static void ConfigureLogging(string configFile)
19
        {
×
20
            var toml = Toml.Parse(File.ReadAllText(configFile)).ToModel();
×
21
            var logLevel = (string)toml["LogLevel"];
×
22
            var outputDir = (string)toml["OutputDirectory"];
×
23

24
            var config = new NLog.Config.LoggingConfiguration();
×
25

26
            // Targets where to log to
27
            var logFile = new NLog.Targets.FileTarget("logfile")
×
28
            {
×
29
                FileName =
×
30
                $"{outputDir}{Path.DirectorySeparatorChar}RoboClerkLog.txt",
×
31
                DeleteOldFileOnStartup = true
×
32
            };
×
33
            Console.WriteLine(logFile.FileName);
×
34
            if (logLevel.ToUpper() == "DEBUG")
×
35
            {
×
36
                config.AddRule(LogLevel.Debug, LogLevel.Fatal, logFile);
×
37
            }
×
NEW
38
            else if (logLevel.ToUpper() == "WARN")
×
NEW
39
            {
×
NEW
40
                config.AddRule(LogLevel.Warn, LogLevel.Fatal, logFile);
×
NEW
41
            }
×
42
            else 
43
            {
×
44
                config.AddRule(LogLevel.Info, LogLevel.Fatal, logFile);
×
45
            }
×
46
            LogManager.Configuration = config;
×
47
        }
×
48

49
        private static Dictionary<string, string> GetConfigOptions(IEnumerable<string> commandlineOptions, ILogger logger)
50
        {
×
51
            Dictionary<string, string> options = new Dictionary<string, string>();
×
52
            foreach (var commandlineOption in commandlineOptions)
×
53
            {
×
54
                if (commandlineOption != ",")
×
55
                {
×
56
                    var elements = commandlineOption.Split('=');
×
57
                    if (elements.Length != 2)
×
58
                    {
×
59
                        logger.Error($"Commandline option can not be parsed: {commandlineOption}. Please check commandline call, it should be in the form of <IDENTIFIER>=<VALUE>");
×
60
                        Console.WriteLine($"An error occurred parsing commandline option: {commandlineOption}. Expected syntax is <IDENTIFIER>=<VALUE>.");
×
61
                        throw new Exception("Error parsing commandline options.");
×
62
                    }
63
                    options[elements[0]] = elements[1];
×
64
                }
×
65
            }
×
66
            return options;
×
67
        }
×
68

69
        private static void CleanOutputDirectory(string outputDir, ILogger logger)
70
        {
×
71
            logger.Info("Cleaning output directory.");
×
72
            string[] files = Directory.GetFiles(outputDir);
×
73
            foreach (string file in files)
×
74
            {
×
75
                if (!file.Contains("RoboClerkLog.txt") &&
×
76
                    !file.Contains(".gitignore"))
×
77
                {
×
78
                    File.Delete(file);
×
79
                }
×
80
            }
×
81
        }
×
82

83
        static int Main(string[] args)
84
        {
×
85
            try
86
            {
×
87
                Parser.Default.ParseArguments<CommandlineOptions>(args)
×
88
                    .WithParsed<CommandlineOptions>(options =>
×
89
                   {
×
90
                       //set up logging first
×
91
                       var assembly = Assembly.GetExecutingAssembly();
×
92
                       var projectConfigFile = $"{Path.GetDirectoryName(assembly.Location)}/RoboClerk_input/RoboClerkConfig/projectConfig.toml";
×
93
                       var roboClerkConfigFile = $"{Path.GetDirectoryName(assembly.Location)}/RoboClerk_input/RoboClerkConfig/RoboClerk.toml";
×
94
                       if (options.ConfigurationFile != null)
×
95
                       {
×
96
                           roboClerkConfigFile = options.ConfigurationFile;
×
97
                       }
×
98
                       if (options.ProjectConfigurationFile != null)
×
99
                       {
×
100
                           projectConfigFile = options.ProjectConfigurationFile;
×
101
                       }
×
102

×
103
                       try
×
104
                       {
×
105
                           ConfigureLogging(roboClerkConfigFile);
×
106
                       }
×
107
                       catch (Exception e)
×
108
                       {
×
109
                           Console.WriteLine($"An error occurred configuring Roboclerk logging: \n{e.Message}");
×
110
                           throw;
×
111
                       }
×
112
                       var logger = NLog.LogManager.GetCurrentClassLogger();
×
NEW
113
                       logger.Warn($"RoboClerk Version: {Assembly.GetExecutingAssembly().GetName().Version}");
×
114
                       var commandlineOptions = GetConfigOptions(options.ConfigurationOptions, logger);
×
115
                       try
×
116
                       {
×
117
                           var serviceCollection = new ServiceCollection();
×
118
                           serviceCollection.AddTransient<IFileSystem, FileSystem>();
×
119
                           serviceCollection.AddSingleton<IConfiguration>(x => new RoboClerk.Configuration.Configuration(x.GetRequiredService<IFileSystem>(), roboClerkConfigFile, projectConfigFile, commandlineOptions));
×
120
                           serviceCollection.AddTransient<IPluginLoader, PluginLoader>();
×
121
                           serviceCollection.AddSingleton<ITraceabilityAnalysis, TraceabilityAnalysis>();
×
122
                           serviceCollection.AddSingleton<IRoboClerkCore, RoboClerkCore>();
×
123

×
124
                           var serviceProvider = serviceCollection.BuildServiceProvider();
×
125

×
126
                           //clean the output directory before we start working
×
127
                           var config = serviceProvider.GetService<IConfiguration>();
×
128
                           if (config != null && config.ClearOutputDir)
×
129
                           {
×
130
                               CleanOutputDirectory(config.OutputDir, logger);
×
131
                           }
×
132
                           if (config.CheckpointConfig.CheckpointFile == string.Empty) //check if we are not using a checkpoint
×
133
                           {
×
134
                               serviceCollection.AddSingleton<IDataSources, PluginDataSources>();
×
135
                           }
×
136
                           else
×
137
                           {
×
138
                               serviceCollection.AddSingleton<IDataSources>(x => new CheckpointDataSources(x.GetRequiredService<IConfiguration>(), x.GetRequiredService<IPluginLoader>(), x.GetRequiredService<IFileSystem>(), config.CheckpointConfig.CheckpointFile));
×
139
                           }
×
140
                           serviceProvider = serviceCollection.BuildServiceProvider();
×
141

×
142
                           var core = serviceProvider.GetService<IRoboClerkCore>();
×
143
                           core.GenerateDocs();
×
144
                           core.SaveDocumentsToDisk();
×
145
                       }
×
146
                       catch (Exception e)
×
147
                       {
×
148
                           logger.Error("An unhandled exception has occurred. RoboClerk failed to complete:\n\n");
×
149
                           logger.Error(e);
×
150
                           throw;
×
151
                       }
×
152
                   });
×
153
            }
×
154
            catch
×
155
            {
×
156
                return 1;
×
157
            }
158
            return 0;
×
159
        }
×
160
    }
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc