Skip to content

Commit 0559799

Browse files
author
Guy Acosta
committed
Solution change to split out CLI and core command functions as separate projects for improved NuGet support.
1 parent 7cf33ec commit 0559799

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+620
-498
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<None Remove="html\partials\_file_listing.liquid" />
10+
<None Remove="html\partials\_report_overview.liquid" />
11+
<None Remove="html\partials\_report_profile.liquid" />
12+
<None Remove="html\partials\_report_summary.liquid" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<EmbeddedResource Include="html\partials\_file_listing.liquid" />
17+
<EmbeddedResource Include="html\partials\_report_overview.liquid" />
18+
<EmbeddedResource Include="html\partials\_report_profile.liquid" />
19+
<EmbeddedResource Include="html\partials\_report_summary.liquid" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="CommandLineParser" Version="2.6.0" />
24+
<PackageReference Include="DotLiquid" Version="2.0.314" />
25+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
26+
<PackageReference Include="NLog" Version="4.6.7" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\AppInspector\AppInspector.Lib.csproj" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<None Update="html\index.html">
35+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
36+
</None>
37+
<None Update="html\resources\css\all.css">
38+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39+
</None>
40+
<None Update="html\resources\css\appinspector.css">
41+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
42+
</None>
43+
<None Update="html\resources\css\bootstrap.min.css">
44+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
45+
</None>
46+
<None Update="html\resources\css\c3.min.css">
47+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
48+
</None>
49+
<None Update="html\resources\images\-guage.png">
50+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
51+
</None>
52+
<None Update="html\resources\images\high-guage.png">
53+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
54+
</None>
55+
<None Update="html\resources\images\low-guage.png">
56+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
57+
</None>
58+
<None Update="html\resources\images\medium-guage.png">
59+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
60+
</None>
61+
<None Update="html\resources\images\Microsoft_logo.svg">
62+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
63+
</None>
64+
<None Update="html\resources\images\toggleBtn-block.png">
65+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
66+
</None>
67+
<None Update="html\resources\images\toggleBtn-none.png">
68+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69+
</None>
70+
<None Update="html\resources\js\ace.js">
71+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
72+
</None>
73+
<None Update="html\resources\js\appinspector.js">
74+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
75+
</None>
76+
<None Update="html\resources\js\bootstrap.min.js">
77+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
78+
</None>
79+
<None Update="html\resources\js\c3.min.js">
80+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
81+
</None>
82+
<None Update="html\resources\js\d3.min.js">
83+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
84+
</None>
85+
<None Update="html\resources\js\ext-beautify.js">
86+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
87+
</None>
88+
<None Update="html\resources\js\ext-modelist.js">
89+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
90+
</None>
91+
<None Update="html\resources\js\ext-settings_menu.js">
92+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
93+
</None>
94+
<None Update="html\resources\js\jquery.min.js">
95+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
96+
</None>
97+
<None Update="html\resources\js\popper.min.js">
98+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
99+
</None>
100+
<None Update="html\resources\webfonts\fa-brands-400.eot">
101+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
102+
</None>
103+
<None Update="html\resources\webfonts\fa-brands-400.svg">
104+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
105+
</None>
106+
<None Update="html\resources\webfonts\fa-brands-400.ttf">
107+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
108+
</None>
109+
<None Update="html\resources\webfonts\fa-brands-400.woff">
110+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111+
</None>
112+
<None Update="html\resources\webfonts\fa-brands-400.woff2">
113+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
114+
</None>
115+
<None Update="html\resources\webfonts\fa-regular-400.eot">
116+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
117+
</None>
118+
<None Update="html\resources\webfonts\fa-regular-400.svg">
119+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
120+
</None>
121+
<None Update="html\resources\webfonts\fa-regular-400.ttf">
122+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
123+
</None>
124+
<None Update="html\resources\webfonts\fa-regular-400.woff">
125+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
126+
</None>
127+
<None Update="html\resources\webfonts\fa-regular-400.woff2">
128+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
129+
</None>
130+
<None Update="html\resources\webfonts\fa-solid-900.eot">
131+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
132+
</None>
133+
<None Update="html\resources\webfonts\fa-solid-900.svg">
134+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
135+
</None>
136+
<None Update="html\resources\webfonts\fa-solid-900.ttf">
137+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
138+
</None>
139+
<None Update="html\resources\webfonts\fa-solid-900.woff">
140+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
141+
</None>
142+
<None Update="html\resources\webfonts\fa-solid-900.woff2">
143+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
144+
</None>
145+
<None Update="preferences\tagcounters.json">
146+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
147+
</None>
148+
<None Update="preferences\tagreportgroups.json">
149+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
150+
</None>
151+
</ItemGroup>
152+
153+
</Project>

AppInspector.CLI/Program.cs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
//Copyright(c) Microsoft Corporation.All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Diagnostics;
6+
using CommandLine;
7+
using System.Reflection;
8+
using NLog;
9+
using NLog.Targets;
10+
using NLog.Config;
11+
using System.IO;
12+
using Microsoft.AppInspector;
13+
14+
15+
namespace Microsoft.AppInspector.CLI
16+
{
17+
18+
class Program
19+
{
20+
21+
public static string GetVersionString()
22+
{
23+
return String.Format("Microsoft Application Inspector {0}", GetVersion());
24+
}
25+
26+
public static string GetVersion()
27+
{
28+
Assembly assembly = Assembly.GetExecutingAssembly();
29+
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
30+
return fileVersionInfo.ProductVersion;
31+
}
32+
33+
static public Logger Logger { get; set; }
34+
35+
36+
/// <summary>
37+
/// Program entry point which defines command verbs and options to running
38+
/// </summary>
39+
/// <param name="args"></param>
40+
static int Main(string[] args)
41+
{
42+
int finalResult = -1;
43+
44+
WriteOnce.Verbosity = WriteOnce.ConsoleVerbosity.Medium;
45+
46+
try
47+
{
48+
WriteOnce.Info(GetVersionString());
49+
var argsResult = Parser.Default.ParseArguments<AnalyzeCommandOptions,
50+
TagDiffCommandOptions,
51+
TagTestCommandOptions,
52+
ExportTagsCommandOptions,
53+
VerifyRulesCommandOptions>(args)
54+
.MapResult(
55+
(AnalyzeCommandOptions opts) => RunAnalyzeCommand(opts),
56+
(TagDiffCommandOptions opts) => RunTagDiffCommand(opts),
57+
(TagTestCommandOptions opts) => RunTagTestCommand(opts),
58+
(ExportTagsCommandOptions opts) => RunExportTagsCommand(opts),
59+
(VerifyRulesCommandOptions opts) => RunVerifyRulesCommand(opts),
60+
errs => 1
61+
);
62+
63+
finalResult = argsResult;
64+
65+
}
66+
catch (OpException e)
67+
{
68+
if (Logger != null)
69+
{
70+
WriteOnce.Error(ErrMsg.FormatString(ErrMsg.ID.RUNTIME_ERROR_NAMED, e.Message));
71+
Logger.Error($"Runtime error: {e.StackTrace}");
72+
}
73+
else
74+
WriteOnce.Error(ErrMsg.FormatString(ErrMsg.ID.RUNTIME_ERROR_PRELOG, e.Message));
75+
}
76+
catch (Exception e)
77+
{
78+
if (Logger != null)
79+
{
80+
WriteOnce.Error(ErrMsg.FormatString(ErrMsg.ID.RUNTIME_ERROR_UNNAMED));
81+
Logger.Error($"Runtime error: {e.Message} {e.StackTrace}");
82+
}
83+
else
84+
WriteOnce.Error(ErrMsg.FormatString(ErrMsg.ID.RUNTIME_ERROR_PRELOG, e.Message));
85+
}
86+
87+
return finalResult;
88+
}
89+
90+
91+
private static int RunAnalyzeCommand(AnalyzeCommandOptions opts)
92+
{
93+
SetupLogging(opts);
94+
return new AnalyzeCommand(opts).Run();
95+
}
96+
97+
private static int RunTagDiffCommand(TagDiffCommandOptions opts)
98+
{
99+
SetupLogging(opts);
100+
return new TagDiffCommand(opts).Run();
101+
}
102+
103+
private static int RunTagTestCommand(TagTestCommandOptions opts)
104+
{
105+
SetupLogging(opts);
106+
return new TagTestCommand(opts).Run();
107+
}
108+
109+
private static int RunExportTagsCommand(ExportTagsCommandOptions opts)
110+
{
111+
SetupLogging(opts);
112+
return new ExportTagsCommand(opts).Run();
113+
}
114+
115+
private static int RunVerifyRulesCommand(VerifyRulesCommandOptions opts)
116+
{
117+
SetupLogging(opts);
118+
return new VerifyRulesCommand(opts).Run();
119+
}
120+
121+
122+
static void SetupLogging(AllCommandOptions opts)
123+
{
124+
var config = new NLog.Config.LoggingConfiguration();
125+
126+
if (String.IsNullOrEmpty(opts.LogFilePath))
127+
{
128+
opts.LogFilePath = Utils.GetPath(Utils.AppPath.defaultLog);
129+
//if using default app log path clean up previous for convenience in reading
130+
if (File.Exists(opts.LogFilePath))
131+
File.Delete(opts.LogFilePath);
132+
}
133+
134+
LogLevel log_level = LogLevel.Error;//default
135+
try
136+
{
137+
log_level = LogLevel.FromString(opts.LogFileLevel);
138+
}
139+
catch (Exception)
140+
{
141+
throw new OpException(String.Format(ErrMsg.FormatString(ErrMsg.ID.CMD_INVALID_ARG_VALUE, "-v")));
142+
}
143+
144+
using (var fileTarget = new FileTarget()
145+
{
146+
Name = "LogFile",
147+
FileName = opts.LogFilePath,
148+
Layout = @"${date:universalTime=true:format=s} ${threadid} ${level:uppercase=true} - ${message}",
149+
ForceMutexConcurrentWrites = true
150+
151+
})
152+
{
153+
config.AddTarget(fileTarget);
154+
config.LoggingRules.Add(new LoggingRule("*", log_level, fileTarget));
155+
}
156+
157+
LogManager.Configuration = config;
158+
opts.Log = LogManager.GetCurrentClassLogger();
159+
Logger = opts.Log;
160+
Logger.Info("["+ DateTime.Now.ToLocalTime() + "] //////////////////////////////////////////////////////////");
161+
WriteOnce.Log = Logger;//allows log to be written to as well as console or output file
162+
163+
}
164+
165+
}
166+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"AppInspector.CLI": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}
File renamed without changes.

0 commit comments

Comments
 (0)