This repository has been archived by the owner on Dec 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from amis92/fix/commandline-inlining
Inline System.CommandLine into Tool project, closes #63
- Loading branch information
Showing
19 changed files
with
2,843 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
src/CodeGeneration.Roslyn.Tool/CommandLine/ArgumentCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/CodeGeneration.Roslyn.Tool/CommandLine/ArgumentCommand_1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.