Skip to content

Commit

Permalink
Updated core library
Browse files Browse the repository at this point in the history
  • Loading branch information
capjan committed May 22, 2019
1 parent 4ad2d7c commit b5fb774
Show file tree
Hide file tree
Showing 28 changed files with 166 additions and 117 deletions.
14 changes: 7 additions & 7 deletions build/CliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public CliRunner(string filePath, string arguments)
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = false
};
};
}

public string ReadToEnd()
{
var result = "";
using (var p = new Process())
{
{
p.StartInfo = _psi;
p.Start();
result = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.WaitForExit();
}
return result;
}

public void Redirect(TextWriter writer)
{
ReadLines(writer.WriteLine);
ReadLines(writer.WriteLine);
}

public void ReadLines(Action<string> callback)
Expand All @@ -48,15 +48,15 @@ public void ReadLines(Action<string> callback)
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.WaitForExit();
p.OutputDataReceived -= DataReceived;
p.ErrorDataReceived -= DataReceived;
}
}
}

private void DataReceived(object sender, DataReceivedEventArgs e)
{
_readDataCallback(e.Data);
_readDataCallback(e.Data);
}

private Action<string> _readDataCallback;
Expand Down
2 changes: 0 additions & 2 deletions build/MsBuildVersionChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace build
{
Expand Down
13 changes: 13 additions & 0 deletions build/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Core.Parser.Arguments;

namespace build
{
public class Options : CliOptions
{
[Option("debug", "build solution/project in debug configuration")]
public bool DebugBuild { get; set; }

[Option("l|list", "List all MsBuild installations")]
public bool ListInstallations { get; set; }
}
}
31 changes: 11 additions & 20 deletions build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
using System;
using System.Linq;
using System.Reflection;
using Core.Extensions.CollectionRelated;
using Core.Extensions.ReflectionRelated;
using Core.Reflection;
using Core.Parser.Arguments;

namespace build
{
class Program
{
static void Main(string[] args)
{

var options = new CliOptions(args);

if (options.ShowHelp)
{
options.WriteUsage(Console.Out);
var parser = new OptionParser<Options>();
if (!parser.TryParse(args, out var options))
return;
}

if (options.ShowVersion)
{
options.WriteVersion(Console.Out);
return;
}

var versions = new MsBuildVersions();



if (options.ListInstallations)
{
// Print all installed versions to stdout
// print all installed msbuild versions to stdout
foreach (var info in versions.All)
{
var v = info.Version;
Expand All @@ -42,11 +27,17 @@ static void Main(string[] args)
return;
}

if (options.Extra.Count == 0)
{
Console.WriteLine("please specify a .NET solution or project to build");
return;
}

var projectsAndSolutions = options.Extra.Select(i => $"\"{i}\"").ToSeparatedString(" ");
var configuration = options.DebugBuild ? "/p:Configuration=Debug" : "/p:Configuration=Release";
var latest = versions.Latest;
new CliRunner(latest.FilePath, $"{configuration} {projectsAndSolutions}")
.Redirect(Console.Out);
.Redirect(Console.Out);
}
}
}
4 changes: 2 additions & 2 deletions build/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
6 changes: 3 additions & 3 deletions build/build.exe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
Expand All @@ -54,7 +54,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CliOptions.cs" />
<Compile Include="Options.cs" />
<Compile Include="CliRunner.cs" />
<Compile Include="msbuild.cs" />
<Compile Include="MsBuildVersionResolver.cs" />
Expand Down
2 changes: 1 addition & 1 deletion build/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cap.Core" version="1.1.0" targetFramework="net472" />
<package id="Cap.Core" version="1.3.3" targetFramework="net472" />
<package id="Costura.Fody" version="3.3.3" targetFramework="net472" />
<package id="Fody" version="4.2.1" targetFramework="net472" developmentDependency="true" />
</packages>
3 changes: 3 additions & 0 deletions createWinpackage.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ SET me=%~n0
SET parent=%~dp0
IF %parent:~-1%==\ SET parent=%parent:~0,-1%

SET compress="C:\Program Files\7-Zip\7z.exe"

:: set working directory to the directory of this batch file
pushd "%~dp0"

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

"%PROGRAMFILES%\7-Zip\7z.exe" a "%parent%\CoreCli-1.2.0.Windows.7z" "%parent%\WinRelease\*"
:: restore previous working directory
popd
17 changes: 17 additions & 0 deletions datetime/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Globalization;
using Core.Parser.Arguments;

namespace DatetimeExe
{
public class Options : CliOptions
{
[Option("examples", "show usage examples")]
public bool ShowExamples { get; set; }

[Option("c|culture=", "sets the used rules and localization as two letter language code (ISO 639). defaults to current local culture ")]
public string CultureTwoLetterCode { get; set; } = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;

[Option("utc", "prints Coordinated Universal Time (UTC) instead of Local Time (LT)")]
public bool UseUtc { get; set; }
}
}
41 changes: 21 additions & 20 deletions datetime/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Globalization;
using Core.Extensions.CollectionRelated;
using Core.Extensions.TextRelated;
using Core.Parser.Arguments;
using Core.Text.Formatter.Impl;

namespace DatetimeExe
Expand All @@ -8,37 +11,35 @@ internal class Program
{
private static void Main(string[] args)
{
var options = new CliOptions(args);
var formatter = new DefaultDateTimeFormatter();

if (options.ShowHelp)
{
options.WriteHelp(Console.Out);
var parser = new OptionParser<Options>();
if (!parser.TryParse(args, out var options))
return;
}

if (options.ShowVersion)
try
{
options.WriteVersion(Console.Out);
return;
}

if (options.ShowExamples)
{
new ExampleWriter(formatter).WriteExamples();
return;
}
var provider = new CultureInfo(options.CultureTwoLetterCode);

var formatter = new DefaultDateTimeFormatter(formatProvider: provider);

if (options.ShowExamples)
{
new ExampleWriter(formatter).WriteExamples();
return;
}

if (options.Extra.Count > 1) throw new InvalidOperationException($"unexpected count of arguments: {options.Extra.ToSeparatedString()}");

if (options.Extra.Count != 0)
formatter.Format = options.Extra[0];

try
{
formatter.Format = options.Format;
formatter.UniversalTime = options.UseUtc;
formatter.WriteLine(Console.Out);
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
options.WriteHelp(Console.Out);
parser.WriteUsage();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions datetime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
6 changes: 3 additions & 3 deletions datetime/datetime.exe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
Expand All @@ -56,7 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ExampleWriter.cs" />
<Compile Include="CliOptions.cs" />
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion datetime/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cap.Core" version="1.1.0" targetFramework="net472" />
<package id="Cap.Core" version="1.3.3" targetFramework="net472" />
<package id="Costura.Fody" version="3.3.3" targetFramework="net47" />
<package id="Fody" version="4.2.1" targetFramework="net47" developmentDependency="true" />
</packages>
13 changes: 13 additions & 0 deletions ipinfo/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Core.Parser.Arguments;

namespace IpInfoExe
{
public class Options : CliOptions
{
[Option("v6|ipv6", "display also IPv6 results")]
public bool ShowIpv6 { get; set; }

[Option("l|local", "restrict to local ip info")]
public bool LocalOnly { get; set; }
}
}
22 changes: 5 additions & 17 deletions ipinfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using Core.Extensions.NetRelated;
using Core.Extensions.ReflectionRelated;
using Core.Net.Impl;
using Core.Reflection;
using Core.Parser.Arguments;

namespace IpInfoExe
{
internal class Program
{
private static void Main(string[] args)
{
var options = new CliOptions(args);
var parser = new OptionParser<Options>();
if (!parser.TryParse(args, out var options))
return;

try
{
if (options.ShowHelp)
{
options.WriteUsage(Console.Out);
return;
}

if (options.ShowVersion)
{
var asmInfo = new AssemblyInfo(Assembly.GetExecutingAssembly());
Console.WriteLine($" {asmInfo.Product} Version {asmInfo.GetBestMatchingVersion()}");
return;
}

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

Expand Down
4 changes: 2 additions & 2 deletions ipinfo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
6 changes: 3 additions & 3 deletions ipinfo/ipinfo.exe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CoreLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.1.0\lib\net472\CoreLib.dll</HintPath>
<Reference Include="CoreLib, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cap.Core.1.3.3\lib\net472\CoreLib.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
Expand All @@ -53,7 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CliOptions.cs" />
<Compile Include="Options.cs" />
<Compile Include="Entry.cs" />
<Compile Include="LocalExtensions.cs" />
<Compile Include="Program.cs" />
Expand Down
Loading

0 comments on commit b5fb774

Please sign in to comment.