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

Commit d282404

Browse files
authoredMay 10, 2018
Merge pull request #70 from amis92/fix/commandline-inlining
Inline System.CommandLine into Tool project, closes #63
2 parents ed4512d + a0aa828 commit d282404

19 files changed

+2843
-6
lines changed
 

‎src/CodeGeneration.Roslyn.Tool/CodeGeneration.Roslyn.Tool.csproj

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<OutputType>Exe</OutputType>
66
<TargetFramework>netcoreapp1.0</TargetFramework>
77
<AssemblyName>dotnet-codegen</AssemblyName>
8+
<LangVersion>7.1</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -15,9 +16,23 @@
1516

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

23+
<ItemGroup>
24+
<Compile Update="CommandLine\Strings.Designer.cs">
25+
<DesignTime>True</DesignTime>
26+
<AutoGen>True</AutoGen>
27+
<DependentUpon>Strings.resx</DependentUpon>
28+
</Compile>
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<EmbeddedResource Update="CommandLine\Strings.resx">
33+
<Generator>ResXFileCodeGenerator</Generator>
34+
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
35+
</EmbeddedResource>
36+
</ItemGroup>
37+
2338
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
using System.Collections.ObjectModel;
6+
7+
namespace CodeGeneration.Roslyn.Tool.CommandLine
8+
{
9+
public abstract class Argument
10+
{
11+
internal Argument(ArgumentCommand command, IEnumerable<string> names, bool isOption, bool isRequired)
12+
{
13+
var nameArray = names.ToArray();
14+
Command = command;
15+
Name = nameArray.First();
16+
Names = new ReadOnlyCollection<string>(nameArray);
17+
IsOption = isOption;
18+
IsRequired = isRequired;
19+
}
20+
21+
public ArgumentCommand Command { get; private set; }
22+
23+
public string Name { get; private set; }
24+
25+
public ReadOnlyCollection<string> Names { get; private set; }
26+
27+
public string Help { get; set; }
28+
29+
public bool IsOption { get; private set; }
30+
31+
public bool IsParameter
32+
{
33+
get { return !IsOption; }
34+
}
35+
36+
public bool IsSpecified { get; private set; }
37+
38+
public bool IsHidden { get; set; }
39+
40+
public bool IsRequired { get; private set; }
41+
42+
public virtual bool IsList
43+
{
44+
get { return false; }
45+
}
46+
47+
public object Value
48+
{
49+
get { return GetValue(); }
50+
}
51+
52+
public object DefaultValue
53+
{
54+
get { return GetDefaultValue(); }
55+
}
56+
57+
public bool IsActive
58+
{
59+
get { return Command == null || Command.IsActive; }
60+
}
61+
62+
public abstract bool IsFlag { get; }
63+
64+
internal abstract object GetValue();
65+
66+
internal abstract object GetDefaultValue();
67+
68+
internal void MarkSpecified()
69+
{
70+
IsSpecified = true;
71+
}
72+
73+
public string GetDisplayName()
74+
{
75+
return GetDisplayName(Name);
76+
}
77+
78+
public IEnumerable<string> GetDisplayNames()
79+
{
80+
return Names.Select(GetDisplayName);
81+
}
82+
83+
private string GetDisplayName(string name)
84+
{
85+
return IsOption ? GetOptionDisplayName(name) : GetParameterDisplayName(name);
86+
}
87+
88+
private static string GetOptionDisplayName(string name)
89+
{
90+
var modifier = name.Length == 1 ? @"-" : @"--";
91+
return modifier + name;
92+
}
93+
94+
private static string GetParameterDisplayName(string name)
95+
{
96+
return @"<" + name + @">";
97+
}
98+
99+
public virtual string GetDisplayValue()
100+
{
101+
return Value == null ? string.Empty : Value.ToString();
102+
}
103+
104+
public override string ToString()
105+
{
106+
return GetDisplayName();
107+
}
108+
}
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace CodeGeneration.Roslyn.Tool.CommandLine
5+
{
6+
public abstract class ArgumentCommand
7+
{
8+
internal ArgumentCommand(string name)
9+
{
10+
Name = name;
11+
}
12+
13+
public string Name { get; private set; }
14+
15+
public string Help { get; set; }
16+
17+
public object Value
18+
{
19+
get { return GetValue(); }
20+
}
21+
22+
public bool IsHidden { get; set; }
23+
24+
public bool IsActive { get; private set; }
25+
26+
internal abstract object GetValue();
27+
28+
internal void MarkActive()
29+
{
30+
IsActive = true;
31+
}
32+
33+
public override string ToString()
34+
{
35+
return Name;
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace CodeGeneration.Roslyn.Tool.CommandLine
5+
{
6+
public sealed class ArgumentCommand<T> : ArgumentCommand
7+
{
8+
internal ArgumentCommand(string name, T value)
9+
: base(name)
10+
{
11+
Value = value;
12+
}
13+
14+
public new T Value { get; private set; }
15+
16+
internal override object GetValue()
17+
{
18+
return Value;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)
Failed to load comments.