using System; using System.Collections.Generic; using System.Linq; namespace TShockAPI.CLI { /// /// Describes a set of flags that are responsible for one CL argument /// public class FlagSet : IEquatable { private IEnumerable _flags; internal object callback; internal Action continuation; /// /// Whether or not the set of flags represented by this FlagSet is followed by an argument /// public bool NoArgs { get; set; } /// /// Creates a new with the given flags /// /// Flags represented by this FlagSet public FlagSet(params string[] flags) { if (flags == null) { throw new ArgumentNullException(nameof(flags)); } _flags = flags.Select(f => f.ToLowerInvariant()); } /// /// Creates a new with the given flags and arguments option /// /// Flags represented by this FlagSet /// Whether or not the flags specified will be followed by an argument public FlagSet(string[] flags, bool noArgs) : this(flags) { NoArgs = noArgs; } /// /// Determines whether or not this flag set contains the given flag /// /// /// public bool Contains(string flag) { return _flags.Contains(flag); } /// /// Determines whether or not this flag set is equatable to another /// /// /// public bool Equals(FlagSet other) { if (other == null) { return false; } return other._flags == _flags; } } }