Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 493 additions & 0 deletions src/System.CommandLine/README.md

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/System.CommandLine/System.CommandLine.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.CommandLine", "src\System.CommandLine.csproj", "{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.CommandLine.Tests", "tests\System.CommandLine.Tests.csproj", "{F48BE89B-4F3E-4AB3-B10A-D6AE47869190}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}.Release|Any CPU.Build.0 = Release|Any CPU
{F48BE89B-4F3E-4AB3-B10A-D6AE47869190}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F48BE89B-4F3E-4AB3-B10A-D6AE47869190}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F48BE89B-4F3E-4AB3-B10A-D6AE47869190}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F48BE89B-4F3E-4AB3-B10A-D6AE47869190}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
48 changes: 48 additions & 0 deletions src/System.CommandLine/src/System.CommandLine.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>
</RootNamespace>
<AssemblyName>System.CommandLine</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<ProjectGuid>{0A365F6D-AF33-4DD1-ABF3-BE45A5F8E642}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="System\CommandLine\ArgumentParser.cs" />
<Compile Include="System\CommandLine\InternalsVisibleTo.cs" />
<Compile Include="System\CommandLine\ArgumentSyntax.cs" />
<Compile Include="System\CommandLine\ArgumentSyntax_Definers.cs" />
<Compile Include="System\CommandLine\Argument.cs" />
<Compile Include="System\CommandLine\ArgumentList`1.cs" />
<Compile Include="System\CommandLine\Argument`1.cs" />
<Compile Include="System\CommandLine\ArgumentCommand.cs" />
<Compile Include="System\CommandLine\ArgumentCommand`1.cs" />
<Compile Include="System\CommandLine\ArgumentSyntaxException.cs" />
<Compile Include="System\CommandLine\ArgumentToken.cs" />
<Compile Include="System\CommandLine\ArgumentLexer.cs" />
<Compile Include="System\CommandLine\HelpTextGenerator.cs" />
<Compile Include="System\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="System\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
108 changes: 108 additions & 0 deletions src/System.CommandLine/src/System/CommandLine/Argument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

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

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

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 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();
}
}
}
40 changes: 40 additions & 0 deletions src/System.CommandLine/src/System/CommandLine/ArgumentCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace System.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;
}
}
}
23 changes: 23 additions & 0 deletions src/System.CommandLine/src/System/CommandLine/ArgumentCommand`1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace System.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