Skip to content

Commit b5fb774

Browse files
committed
Updated core library
1 parent 4ad2d7c commit b5fb774

28 files changed

+166
-117
lines changed

build/CliRunner.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ public CliRunner(string filePath, string arguments)
1616
RedirectStandardOutput = true,
1717
RedirectStandardError = true,
1818
CreateNoWindow = false
19-
};
19+
};
2020
}
2121

2222
public string ReadToEnd()
2323
{
2424
var result = "";
2525
using (var p = new Process())
26-
{
26+
{
2727
p.StartInfo = _psi;
2828
p.Start();
2929
result = p.StandardOutput.ReadToEnd();
30-
p.WaitForExit();
30+
p.WaitForExit();
3131
}
3232
return result;
3333
}
3434

3535
public void Redirect(TextWriter writer)
3636
{
37-
ReadLines(writer.WriteLine);
37+
ReadLines(writer.WriteLine);
3838
}
3939

4040
public void ReadLines(Action<string> callback)
@@ -48,15 +48,15 @@ public void ReadLines(Action<string> callback)
4848
p.Start();
4949
p.BeginOutputReadLine();
5050
p.BeginErrorReadLine();
51-
p.WaitForExit();
51+
p.WaitForExit();
5252
p.OutputDataReceived -= DataReceived;
5353
p.ErrorDataReceived -= DataReceived;
54-
}
54+
}
5555
}
5656

5757
private void DataReceived(object sender, DataReceivedEventArgs e)
5858
{
59-
_readDataCallback(e.Data);
59+
_readDataCallback(e.Data);
6060
}
6161

6262
private Action<string> _readDataCallback;

build/MsBuildVersionChoice.cs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
75

86
namespace build
97
{

build/Options.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Core.Parser.Arguments;
2+
3+
namespace build
4+
{
5+
public class Options : CliOptions
6+
{
7+
[Option("debug", "build solution/project in debug configuration")]
8+
public bool DebugBuild { get; set; }
9+
10+
[Option("l|list", "List all MsBuild installations")]
11+
public bool ListInstallations { get; set; }
12+
}
13+
}

build/Program.cs

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
11
using System;
22
using System.Linq;
3-
using System.Reflection;
43
using Core.Extensions.CollectionRelated;
5-
using Core.Extensions.ReflectionRelated;
6-
using Core.Reflection;
4+
using Core.Parser.Arguments;
75

86
namespace build
97
{
108
class Program
119
{
1210
static void Main(string[] args)
1311
{
14-
15-
var options = new CliOptions(args);
16-
17-
if (options.ShowHelp)
18-
{
19-
options.WriteUsage(Console.Out);
12+
var parser = new OptionParser<Options>();
13+
if (!parser.TryParse(args, out var options))
2014
return;
21-
}
22-
23-
if (options.ShowVersion)
24-
{
25-
options.WriteVersion(Console.Out);
26-
return;
27-
}
2815

2916
var versions = new MsBuildVersions();
3017

31-
32-
3318
if (options.ListInstallations)
3419
{
35-
// Print all installed versions to stdout
20+
// print all installed msbuild versions to stdout
3621
foreach (var info in versions.All)
3722
{
3823
var v = info.Version;
@@ -42,11 +27,17 @@ static void Main(string[] args)
4227
return;
4328
}
4429

30+
if (options.Extra.Count == 0)
31+
{
32+
Console.WriteLine("please specify a .NET solution or project to build");
33+
return;
34+
}
35+
4536
var projectsAndSolutions = options.Extra.Select(i => $"\"{i}\"").ToSeparatedString(" ");
4637
var configuration = options.DebugBuild ? "/p:Configuration=Debug" : "/p:Configuration=Release";
4738
var latest = versions.Latest;
4839
new CliRunner(latest.FilePath, $"{configuration} {projectsAndSolutions}")
49-
.Redirect(Console.Out);
40+
.Redirect(Console.Out);
5041
}
5142
}
5243
}

build/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.0")]
36-
[assembly: AssemblyFileVersion("1.1.0.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]

build/build.exe.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<WarningLevel>4</WarningLevel>
3838
</PropertyGroup>
3939
<ItemGroup>
40-
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
40+
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
4242
</Reference>
4343
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
4444
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
@@ -54,7 +54,7 @@
5454
<Reference Include="System.Xml" />
5555
</ItemGroup>
5656
<ItemGroup>
57-
<Compile Include="CliOptions.cs" />
57+
<Compile Include="Options.cs" />
5858
<Compile Include="CliRunner.cs" />
5959
<Compile Include="msbuild.cs" />
6060
<Compile Include="MsBuildVersionResolver.cs" />

build/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Cap.Core" version="1.1.0" targetFramework="net472" />
3+
<package id="Cap.Core" version="1.3.3" targetFramework="net472" />
44
<package id="Costura.Fody" version="3.3.3" targetFramework="net472" />
55
<package id="Fody" version="4.2.1" targetFramework="net472" developmentDependency="true" />
66
</packages>

createWinpackage.bat

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ SET me=%~n0
2424
SET parent=%~dp0
2525
IF %parent:~-1%==\ SET parent=%parent:~0,-1%
2626

27+
SET compress="C:\Program Files\7-Zip\7z.exe"
28+
2729
:: set working directory to the directory of this batch file
2830
pushd "%~dp0"
2931

@@ -37,5 +39,6 @@ copy /Y "%parent%\ipinfo\bin\Release\ipinfo.exe" "%parent%\WinRelease"
3739
copy /Y "%parent%\regex\bin\Release\regex.exe" "%parent%\WinRelease"
3840
copy /Y "%parent%\upinfo\bin\Release\upinfo.exe" "%parent%\WinRelease"
3941

42+
"%PROGRAMFILES%\7-Zip\7z.exe" a "%parent%\CoreCli-1.2.0.Windows.7z" "%parent%\WinRelease\*"
4043
:: restore previous working directory
4144
popd

datetime/Options.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Globalization;
2+
using Core.Parser.Arguments;
3+
4+
namespace DatetimeExe
5+
{
6+
public class Options : CliOptions
7+
{
8+
[Option("examples", "show usage examples")]
9+
public bool ShowExamples { get; set; }
10+
11+
[Option("c|culture=", "sets the used rules and localization as two letter language code (ISO 639). defaults to current local culture ")]
12+
public string CultureTwoLetterCode { get; set; } = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
13+
14+
[Option("utc", "prints Coordinated Universal Time (UTC) instead of Local Time (LT)")]
15+
public bool UseUtc { get; set; }
16+
}
17+
}

datetime/Program.cs

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Globalization;
3+
using Core.Extensions.CollectionRelated;
24
using Core.Extensions.TextRelated;
5+
using Core.Parser.Arguments;
36
using Core.Text.Formatter.Impl;
47

58
namespace DatetimeExe
@@ -8,37 +11,35 @@ internal class Program
811
{
912
private static void Main(string[] args)
1013
{
11-
var options = new CliOptions(args);
12-
var formatter = new DefaultDateTimeFormatter();
13-
14-
if (options.ShowHelp)
15-
{
16-
options.WriteHelp(Console.Out);
14+
var parser = new OptionParser<Options>();
15+
if (!parser.TryParse(args, out var options))
1716
return;
18-
}
1917

20-
if (options.ShowVersion)
18+
try
2119
{
22-
options.WriteVersion(Console.Out);
23-
return;
24-
}
2520

26-
if (options.ShowExamples)
27-
{
28-
new ExampleWriter(formatter).WriteExamples();
29-
return;
30-
}
21+
var provider = new CultureInfo(options.CultureTwoLetterCode);
22+
23+
var formatter = new DefaultDateTimeFormatter(formatProvider: provider);
24+
25+
if (options.ShowExamples)
26+
{
27+
new ExampleWriter(formatter).WriteExamples();
28+
return;
29+
}
30+
31+
if (options.Extra.Count > 1) throw new InvalidOperationException($"unexpected count of arguments: {options.Extra.ToSeparatedString()}");
32+
33+
if (options.Extra.Count != 0)
34+
formatter.Format = options.Extra[0];
3135

32-
try
33-
{
34-
formatter.Format = options.Format;
3536
formatter.UniversalTime = options.UseUtc;
3637
formatter.WriteLine(Console.Out);
3738
}
3839
catch (Exception e)
3940
{
4041
Console.Error.WriteLine(e.Message);
41-
options.WriteHelp(Console.Out);
42+
parser.WriteUsage();
4243
}
4344
}
4445
}

datetime/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.0")]
36-
[assembly: AssemblyFileVersion("1.1.0.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]

datetime/datetime.exe.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<LangVersion>7.3</LangVersion>
4040
</PropertyGroup>
4141
<ItemGroup>
42-
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
42+
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
4444
</Reference>
4545
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
4646
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
@@ -56,7 +56,7 @@
5656
</ItemGroup>
5757
<ItemGroup>
5858
<Compile Include="ExampleWriter.cs" />
59-
<Compile Include="CliOptions.cs" />
59+
<Compile Include="Options.cs" />
6060
<Compile Include="Program.cs" />
6161
<Compile Include="Properties\AssemblyInfo.cs" />
6262
</ItemGroup>

datetime/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Cap.Core" version="1.1.0" targetFramework="net472" />
3+
<package id="Cap.Core" version="1.3.3" targetFramework="net472" />
44
<package id="Costura.Fody" version="3.3.3" targetFramework="net47" />
55
<package id="Fody" version="4.2.1" targetFramework="net47" developmentDependency="true" />
66
</packages>

ipinfo/Options.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Core.Parser.Arguments;
2+
3+
namespace IpInfoExe
4+
{
5+
public class Options : CliOptions
6+
{
7+
[Option("v6|ipv6", "display also IPv6 results")]
8+
public bool ShowIpv6 { get; set; }
9+
10+
[Option("l|local", "restrict to local ip info")]
11+
public bool LocalOnly { get; set; }
12+
}
13+
}

ipinfo/Program.cs

+5-17
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,22 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net.NetworkInformation;
5-
using System.Reflection;
65
using Core.Extensions.NetRelated;
7-
using Core.Extensions.ReflectionRelated;
86
using Core.Net.Impl;
9-
using Core.Reflection;
7+
using Core.Parser.Arguments;
108

119
namespace IpInfoExe
1210
{
1311
internal class Program
1412
{
1513
private static void Main(string[] args)
1614
{
17-
var options = new CliOptions(args);
15+
var parser = new OptionParser<Options>();
16+
if (!parser.TryParse(args, out var options))
17+
return;
1818

1919
try
2020
{
21-
if (options.ShowHelp)
22-
{
23-
options.WriteUsage(Console.Out);
24-
return;
25-
}
26-
27-
if (options.ShowVersion)
28-
{
29-
var asmInfo = new AssemblyInfo(Assembly.GetExecutingAssembly());
30-
Console.WriteLine($" {asmInfo.Product} Version {asmInfo.GetBestMatchingVersion()}");
31-
return;
32-
}
3321

3422
var table = new List<Entry>();
3523
if (!options.LocalOnly && new DefaultPublicIpResolver().TryResolve(out var publicIp))
@@ -50,7 +38,7 @@ private static void Main(string[] args)
5038
catch (Exception e)
5139
{
5240
Console.Error.WriteLine(e.Message);
53-
options.WriteUsage(Console.Out);
41+
parser.WriteUsage();
5442
}
5543
}
5644

ipinfo/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.0.0")]
36-
[assembly: AssemblyFileVersion("1.1.0.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]

ipinfo/ipinfo.exe.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<WarningLevel>4</WarningLevel>
3838
</PropertyGroup>
3939
<ItemGroup>
40-
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
40+
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
4242
</Reference>
4343
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
4444
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
@@ -53,7 +53,7 @@
5353
<Reference Include="System.Xml" />
5454
</ItemGroup>
5555
<ItemGroup>
56-
<Compile Include="CliOptions.cs" />
56+
<Compile Include="Options.cs" />
5757
<Compile Include="Entry.cs" />
5858
<Compile Include="LocalExtensions.cs" />
5959
<Compile Include="Program.cs" />

0 commit comments

Comments
 (0)