Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersign committed Jun 1, 2018
2 parents ec88fcc + e78d527 commit 9bb3fb5
Show file tree
Hide file tree
Showing 70 changed files with 3,197 additions and 1,048 deletions.
14 changes: 10 additions & 4 deletions BenchManager/BenchCLI/BenchCLI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.3.2\build\Microsoft.Net.Compilers.props')" />
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.2.8.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.8.2\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -14,6 +14,7 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<ResolveComReferenceSilent>True</ResolveComReferenceSilent>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
Expand All @@ -27,7 +28,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -38,7 +39,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>logo.ico</ApplicationIcon>
Expand Down Expand Up @@ -80,6 +81,7 @@
<Compile Include="Commands\AppPropertyCommand.cs" />
<Compile Include="Commands\ConfigEditCommand.cs" />
<Compile Include="Commands\ConfigSetCommand.cs" />
<Compile Include="Commands\SearchCommand.cs" />
<Compile Include="Commands\TransferCloneCommand.cs" />
<Compile Include="Commands\TransferCommandBase.cs" />
<Compile Include="Commands\TransferExportCommand.cs" />
Expand Down Expand Up @@ -145,6 +147,10 @@
<None Include="Properties\App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)..\auto\bin\$(TargetFileName)"
copy "$(TargetPath).config" "$(SolutionDir)..\auto\bin\$(TargetFileName).config"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 6 additions & 0 deletions BenchManager/BenchCLI/CliTools/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class ArgumentParser

public Document Description { get; private set; }

public bool AcceptsAdditionalArguments { get; set; }

public Document AdditionalArgumentsDescription { get; private set; }

public ArgumentParser(string name, IEnumerable<Argument> arguments)
{
Name = name;
Expand All @@ -30,6 +34,8 @@ public ArgumentParser(string name, IEnumerable<Argument> arguments)
{
RegisterArgument(arg);
}
AcceptsAdditionalArguments = false;
AdditionalArgumentsDescription = new Document();
}

public ArgumentParser(string name, params Argument[] arguments)
Expand Down
44 changes: 40 additions & 4 deletions BenchManager/BenchCLI/CliTools/ConsoleTableWriter.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace Mastersign.CliTools
{
class ConsoleTableWriter : ITableWriter
{
private string[] columns;
private Alignment[] alignment;
private List<string[]> rows;
private bool isDisposed;

public void Initialize(params string[] columns)
{
this.columns = columns;
this.columns = columns ?? throw new ArgumentNullException(nameof(columns));
this.alignment = new Alignment[columns.Length];
this.rows = new List<string[]>();
}

Expand All @@ -25,6 +28,8 @@ public void Write(params object[] values)
for (int i = 0; i < values.Length; i++)
{
row.Add(Format(values[i]));
var a = GetAlignmentFromValue(values[i]);
if (a != Alignment.Unknown) alignment[i] = a;
}
rows.Add(row.ToArray());
}
Expand All @@ -33,10 +38,40 @@ private string Format(object value)
{
if (value == null) return string.Empty;
if (value is bool) return ((bool)value) ? "TRUE" : "FALSE";
if (value is int) return ((int)value).ToString(CultureInfo.InvariantCulture);
if (value is float) return ((float)value).ToString("0.00", CultureInfo.InvariantCulture);
if (value is string) return (string)value;
return "UNSUPPORTED TYPE";
}

enum Alignment { Unknown = 0, Left = 1, Center = 2, Right = 3 }

private Alignment GetAlignmentFromValue(object value)
{
if (value is bool) return Alignment.Center;
if (value is int) return Alignment.Right;
if (value is float) return Alignment.Right;
if (value is string) return Alignment.Left;
return Alignment.Unknown;
}

private static string Align(string value, int l, Alignment a)
{
switch (a)
{
case Alignment.Center:
var d = l - value.Length;
if (d <= 0) return value;
var left = (int)Math.Floor(d * 0.5);
var right = (int)Math.Ceiling(d * 0.5);
return new string(' ', left) + value + new string(' ', right);
case Alignment.Right:
return value.PadLeft(l);
default:
return value.PadRight(l);
}
}

private void WriteTable()
{
var c = columns.Length;
Expand All @@ -46,10 +81,11 @@ private void WriteTable()
{
for (int i = 0; i < c; i++) lengths[i] = Math.Max(lengths[i], row[i].Length);
}

for (int i = 0; i < c; i++)
{
if (i > 0) Write(" | ");
Write(columns[i].PadRight(lengths[i]));
Write(Align(columns[i], lengths[i], alignment[i]));
}
NewLine();
for (int i = 0; i < c; i++)
Expand All @@ -63,7 +99,7 @@ private void WriteTable()
for (int i = 0; i < c; i++)
{
if (i > 0) Write(" | ");
Write(row[i].PadRight(lengths[i]));
Write(Align(row[i], lengths[i], alignment[i]));
}
NewLine();
}
Expand All @@ -81,7 +117,7 @@ private void Write(string value)
}
else
{
Console.Write(value.Substring(0, w - lineLength));
Console.Write(value.Substring(0, w - lineLength - 1));
lineLength = w;
}
}
Expand Down
13 changes: 13 additions & 0 deletions BenchManager/BenchCLI/CliTools/HelpFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public static void FlagsAndOptionsGeneric(DocumentWriter w, ArgumentParser p)
{
w.Text(" ").Append(FormatPositional, a);
}
if (p.AcceptsAdditionalArguments)
{
w.Text(" ...");
}
}

public static void FullCommandChain(DocumentWriter w, CommandBase cmd)
Expand Down Expand Up @@ -172,6 +176,7 @@ public static void WriteHelp(DocumentWriter w, CommandBase cmd,
WriteOptions(w, cmd);
WritePositionals(w, cmd);
WriteCommands(w, cmd, withCommandLinks);
WriteAdditionalArguments(w, cmd);
}

private static void WriteUsage(DocumentWriter w, CommandBase cmd,
Expand Down Expand Up @@ -362,5 +367,13 @@ private static void WriteCommands(DocumentWriter w, CommandBase cmd, bool withLi
w.End(BlockType.DefinitionList);
}
}

private static void WriteAdditionalArguments(DocumentWriter w, CommandBase cmd)
{
if (!cmd.ArgumentParser.AcceptsAdditionalArguments ||
cmd.ArgumentParser.AdditionalArgumentsDescription.IsEmpty) return;
w.Headline2(CommandAnchor(cmd) + "_additional_args", "Additional Arguments");
w.Paragraph(cmd.ArgumentParser.AdditionalArgumentsDescription);
}
}
}
28 changes: 24 additions & 4 deletions BenchManager/BenchCLI/CliTools/MarkdownTableWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;

Expand All @@ -8,6 +9,7 @@ namespace Mastersign.CliTools
class MarkdownTableWriter : ITableWriter
{
private string[] columns;
private Alignment[] alignment;
private List<string[]> rows;

private TextWriter writer;
Expand All @@ -25,7 +27,8 @@ public MarkdownTableWriter(Stream target)

public void Initialize(params string[] columns)
{
this.columns = columns;
this.columns = columns ?? throw new ArgumentNullException(nameof(columns));
this.alignment = new Alignment[columns.Length];
this.rows = new List<string[]>();
}

Expand All @@ -38,6 +41,8 @@ public void Write(params object[] values)
for (int i = 0; i < values.Length; i++)
{
row.Add(Format(values[i]));
var a = GetAlignmentFromValue(values[i]);
if (a != Alignment.Unknown) alignment[i] = a;
}
rows.Add(row.ToArray());
}
Expand All @@ -46,10 +51,23 @@ private string Format(object value)
{
if (value == null) return string.Empty;
if (value is bool) return ((bool)value) ? "`true`" : "`false`";
if (value is int) return ((int)value).ToString(CultureInfo.InvariantCulture);
if (value is float) return ((float)value).ToString(CultureInfo.InvariantCulture);
if (value is string) return (string)value;
return "_UNSUPPORTED TYPE_";
}

enum Alignment { Unknown = 0, Left = 1, Center = 2, Right = 3 }

private Alignment GetAlignmentFromValue(object value)
{
if (value is bool) return Alignment.Center;
if (value is int) return Alignment.Right;
if (value is float) return Alignment.Right;
if (value is string) return Alignment.Left;
return Alignment.Unknown;
}

private void WriteTable()
{
var c = columns.Length;
Expand All @@ -67,13 +85,15 @@ private void WriteTable()
}
Write(" |");
NewLine();
Write("|:");
Write("|");
for (int i = 0; i < c; i++)
{
if (i > 0) Write("-|:");
if (i > 0) Write("|");
Write(alignment[i] != Alignment.Right ? ":" : "-");
Write(new string('-', lengths[i]));
Write(alignment[i] == Alignment.Center || alignment[i] == Alignment.Right ? ":" : "-");
}
Write("-|");
Write("|");
NewLine();
foreach (var row in rows)
{
Expand Down
4 changes: 4 additions & 0 deletions BenchManager/BenchCLI/Commands/AppExecuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ protected override void InitializeArgumentParser(ArgumentParser parser)
.Text("The ").Keyword(Name).Text(" command starts the main executable of the specified app.")
.End(BlockType.Paragraph);

parser.AcceptsAdditionalArguments = true;
parser.AdditionalArgumentsDescription
.Text("All additonal arguments are passed as command line arguments to the executable.");

var flagDetached = new FlagArgument(FLAG_DETACHED, 'd', "async");
flagDetached.Description
.Text("Do not wait for the end of the process.");
Expand Down
2 changes: 2 additions & 0 deletions BenchManager/BenchCLI/Commands/ListAppsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum AppSet
Cached,
NotCached,
DefaultApps,
Groups,
MetaApps,
ManagedPackages,
}
Expand Down Expand Up @@ -196,6 +197,7 @@ private bool IsIncludedInSet(AppFacade app, AppSet set)
case AppSet.Cached: return app.IsResourceCached;
case AppSet.NotCached: return app.HasResource && !app.IsResourceCached;
case AppSet.DefaultApps: return app.Typ == AppTyps.Default;
case AppSet.Groups: return app.Typ == AppTyps.Group;
case AppSet.MetaApps: return app.Typ == AppTyps.Meta;
case AppSet.ManagedPackages: return app.IsManagedPackage;
default: throw new NotSupportedException();
Expand Down
2 changes: 1 addition & 1 deletion BenchManager/BenchCLI/Commands/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DataOutputFormat Format
=> (DataOutputFormat)Enum.Parse(
typeof(DataOutputFormat),
Arguments.GetOptionValue(OPTION_FORMAT, DEF_FORMAT.ToString()),
true);
ignoreCase: true);

public bool OutputAsTable => Arguments.GetFlag(FLAG_TABLE);

Expand Down
7 changes: 7 additions & 0 deletions BenchManager/BenchCLI/Commands/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RootCommand : BenchCommand

private readonly BenchCommand helpCommand = new HelpCommand();
private readonly BenchCommand listCommand = new ListCommand();
private readonly BenchCommand searchCommand = new SearchCommand();
private readonly BenchCommand dashboardCommand = new DashboardCommand();
private readonly BenchCommand manageCommand = new ManageCommand();
private readonly BenchCommand transferCommand = new TransferCommand();
Expand Down Expand Up @@ -55,6 +56,7 @@ public RootCommand()

RegisterSubCommand(helpCommand);
RegisterSubCommand(listCommand);
RegisterSubCommand(searchCommand);
RegisterSubCommand(dashboardCommand);
RegisterSubCommand(manageCommand);
RegisterSubCommand(transferCommand);
Expand Down Expand Up @@ -116,6 +118,10 @@ protected override void InitializeArgumentParser(ArgumentParser parser)
commandList.Description
.Text("List different kinds of objects in the Bench environment.");

var commandSearch = new CommandArgument(searchCommand.Name, 's');
commandSearch.Description
.Text("Searches for apps.");

var commandDashboard = new CommandArgument(dashboardCommand.Name, 'b', "gui");
commandDashboard.Description
.Text("Start the ").Emph("Bench Dashboard").Text(".");
Expand Down Expand Up @@ -150,6 +156,7 @@ protected override void InitializeArgumentParser(ArgumentParser parser)

commandHelp,
commandList,
commandSearch,
commandManage,
commandTransfer,
commandDashboard,
Expand Down
Loading

0 comments on commit 9bb3fb5

Please sign in to comment.