Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #70 from amis92/fix/commandline-inlining
Browse files Browse the repository at this point in the history
Inline System.CommandLine into Tool project, closes #63
  • Loading branch information
AArnott authored May 10, 2018
2 parents ed4512d + a0aa828 commit d282404
Show file tree
Hide file tree
Showing 19 changed files with 2,843 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/CodeGeneration.Roslyn.Tool/CodeGeneration.Roslyn.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>dotnet-codegen</AssemblyName>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,9 +16,23 @@

<ItemGroup>
<ProjectReference Include="..\CodeGeneration.Roslyn\CodeGeneration.Roslyn.csproj" />
<PackageReference Include="System.CommandLine" Version="0.1.0-e170407-3" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.4" />
</ItemGroup>

<ItemGroup>
<Compile Update="CommandLine\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="CommandLine\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
109 changes: 109 additions & 0 deletions src/CodeGeneration.Roslyn.Tool/CommandLine/Argument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace CodeGeneration.Roslyn.Tool.CommandLine
{
public abstract class Argument
{
internal Argument(ArgumentCommand command, IEnumerable<string> names, bool isOption, bool isRequired)
{
var nameArray = names.ToArray();
Command = command;
Name = nameArray.First();
Names = new ReadOnlyCollection<string>(nameArray);
IsOption = isOption;
IsRequired = isRequired;
}

public ArgumentCommand Command { get; private set; }

public string Name { get; private set; }

public ReadOnlyCollection<string> Names { get; private set; }

public string Help { get; set; }

public bool IsOption { get; private set; }

public bool IsParameter
{
get { return !IsOption; }
}

public bool IsSpecified { get; private set; }

public bool IsHidden { get; set; }

public bool IsRequired { get; private set; }

public virtual bool IsList
{
get { return false; }
}

public object Value
{
get { return GetValue(); }
}

public object DefaultValue
{
get { return GetDefaultValue(); }
}

public bool IsActive
{
get { return Command == null || Command.IsActive; }
}

public abstract bool IsFlag { get; }

internal abstract object GetValue();

internal abstract object GetDefaultValue();

internal void MarkSpecified()
{
IsSpecified = true;
}

public string GetDisplayName()
{
return GetDisplayName(Name);
}

public IEnumerable<string> GetDisplayNames()
{
return Names.Select(GetDisplayName);
}

private string GetDisplayName(string name)
{
return IsOption ? GetOptionDisplayName(name) : GetParameterDisplayName(name);
}

private static string GetOptionDisplayName(string name)
{
var modifier = name.Length == 1 ? @"-" : @"--";
return modifier + name;
}

private static string GetParameterDisplayName(string name)
{
return @"<" + name + @">";
}

public virtual string GetDisplayValue()
{
return Value == null ? string.Empty : Value.ToString();
}

public override string ToString()
{
return GetDisplayName();
}
}
}
38 changes: 38 additions & 0 deletions src/CodeGeneration.Roslyn.Tool/CommandLine/ArgumentCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace CodeGeneration.Roslyn.Tool.CommandLine
{
public abstract class ArgumentCommand
{
internal ArgumentCommand(string name)
{
Name = name;
}

public string Name { get; private set; }

public string Help { get; set; }

public object Value
{
get { return GetValue(); }
}

public bool IsHidden { get; set; }

public bool IsActive { get; private set; }

internal abstract object GetValue();

internal void MarkActive()
{
IsActive = true;
}

public override string ToString()
{
return Name;
}
}
}
21 changes: 21 additions & 0 deletions src/CodeGeneration.Roslyn.Tool/CommandLine/ArgumentCommand_1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace CodeGeneration.Roslyn.Tool.CommandLine
{
public sealed class ArgumentCommand<T> : ArgumentCommand
{
internal ArgumentCommand(string name, T value)
: base(name)
{
Value = value;
}

public new T Value { get; private set; }

internal override object GetValue()
{
return Value;
}
}
}
Loading

0 comments on commit d282404

Please sign in to comment.