Skip to content

Movement and Internalization Phase 1 #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 10, 2018
80 changes: 16 additions & 64 deletions src/Microsoft.ML.Core/CommandLine/ArgumentAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// This is separated from CmdParser.cs

using System;
using System.Linq;

Expand All @@ -15,7 +13,8 @@ namespace Microsoft.ML.Runtime.CommandLine
/// as the destination of command line argument parsing.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class ArgumentAttribute : Attribute
[BestFriend]
internal class ArgumentAttribute : Attribute
{
public enum VisibilityType
{
Expand All @@ -24,35 +23,23 @@ public enum VisibilityType
EntryPointsOnly
}

private ArgumentType _type;
private string _shortName;
private string _helpText;
private bool _hide;
private double _sortOrder;
private string _nullName;
private bool _isInputFileName;
private string _specialPurpose;
private VisibilityType _visibility;
private string _name;
private Type _signatureType;

/// <summary>
/// Allows control of command line parsing.
/// </summary>
/// <param name="type"> Specifies the error checking to be done on the argument. </param>
public ArgumentAttribute(ArgumentType type)
{
_type = type;
_sortOrder = 150;
Type = type;
SortOrder = 150;
}

/// <summary>
/// The error checking to be done on the argument.
/// </summary>
public ArgumentType Type
{
get { return _type; }
}
public ArgumentType Type { get; }

/// <summary>
/// The short name(s) of the argument.
Expand All @@ -64,7 +51,7 @@ public ArgumentType Type
/// </summary>
public string ShortName
{
get { return _shortName; }
get => _shortName;
set
{
Contracts.Check(value == null || !(this is DefaultArgumentAttribute));
Expand All @@ -75,54 +62,26 @@ public string ShortName
/// <summary>
/// The help text for the argument.
/// </summary>
public string HelpText
{
get { return _helpText; }
set { _helpText = value; }
}
public string HelpText { get; set; }

public bool Hide
{
get { return _hide; }
set { _hide = value; }
}
public bool Hide { get; set; }

public double SortOrder
{
get { return _sortOrder; }
set { _sortOrder = value; }
}
public double SortOrder { get; set; }

public string NullName
{
get { return _nullName; }
set { _nullName = value; }
}
public string NullName { get; set; }

public bool IsInputFileName
{
get { return _isInputFileName; }
set { _isInputFileName = value; }
}
public bool IsInputFileName { get; set; }

/// <summary>
/// Allows the GUI or other tools to inspect the intended purpose of the argument and pick a correct custom control.
/// </summary>
public string Purpose
{
get { return _specialPurpose; }
set { _specialPurpose = value; }
}
public string Purpose { get; set; }

public VisibilityType Visibility
{
get { return _visibility; }
set { _visibility = value; }
}
public VisibilityType Visibility { get; set; }

public string Name
{
get { return _name; }
get => _name;
set { _name = string.IsNullOrWhiteSpace(value) ? null : value; }
}

Expand All @@ -136,15 +95,8 @@ public string[] Aliases
}
}

public bool IsRequired
{
get { return ArgumentType.Required == (_type & ArgumentType.Required); }
}
public bool IsRequired => ArgumentType.Required == (Type & ArgumentType.Required);

public Type SignatureType
{
get { return _signatureType; }
set { _signatureType = value; }
}
public Type SignatureType { get; set; }
}
}
54 changes: 54 additions & 0 deletions src/Microsoft.ML.Core/CommandLine/ArgumentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace Microsoft.ML.Runtime.CommandLine
{
/// <summary>
/// Used to control parsing of command line arguments.
/// </summary>
[Flags]
[BestFriend]
internal enum ArgumentType
{
/// <summary>
/// Indicates that this field is required. An error will be displayed
/// if it is not present when parsing arguments.
/// </summary>
Required = 0x01,

/// <summary>
/// Only valid in conjunction with Multiple.
/// Duplicate values will result in an error.
/// </summary>
Unique = 0x02,

/// <summary>
/// Inidicates that the argument may be specified more than once.
/// Only valid if the argument is a collection
/// </summary>
Multiple = 0x04,

/// <summary>
/// The default type for non-collection arguments.
/// The argument is not required, but an error will be reported if it is specified more than once.
/// </summary>
AtMostOnce = 0x00,

/// <summary>
/// For non-collection arguments, when the argument is specified more than
/// once no error is reported and the value of the argument is the last
/// value which occurs in the argument list.
/// </summary>
LastOccurenceWins = Multiple,

/// <summary>
/// The default type for collection arguments.
/// The argument is permitted to occur multiple times, but duplicate
/// values will cause an error to be reported.
/// </summary>
MultipleUnique = Multiple | Unique,
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/CommandLine/CharCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.ML.Runtime.CommandLine
{
public sealed class CharCursor
internal sealed class CharCursor
{
private readonly string _text;
private readonly int _ichLim;
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.ML.Core/CommandLine/CmdLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Text;
using Microsoft.ML.Runtime.Internal.Utilities;

namespace Microsoft.ML.Runtime.CommandLine
{
public sealed class CmdLexer
[BestFriend]
internal sealed class CmdLexer
{
private CharCursor _curs;

Expand Down
Loading