76 lines
1.7 KiB
C#
76 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.Remoting.Messaging;
|
|
namespace sharp.extensions.commandline
|
|
{
|
|
public class ArgumentReader
|
|
{
|
|
List<string> arguments = new List<string>();
|
|
|
|
public string CurrentElement { get; private set; }
|
|
|
|
public string CurrentOption { get; private set; }
|
|
public bool CurrentIsLong { get; private set; }
|
|
public bool CurrentIsShort { get; private set; }
|
|
|
|
public ArgumentReader(String[] arguments)
|
|
{
|
|
this.arguments.AddRange(arguments);
|
|
this.CurrentElement = null;
|
|
this.CurrentOption = null;
|
|
this.CurrentIsLong = false;
|
|
this.CurrentIsShort = false;
|
|
}
|
|
|
|
public bool Next()
|
|
{
|
|
if (CurrentElement.IsNull() || CurrentElement.Equals(""))
|
|
{
|
|
if (arguments.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
CurrentElement = arguments[0];
|
|
arguments.RemoveAt(0);
|
|
|
|
if (CurrentElement.StartsWith("--"))
|
|
{
|
|
CurrentIsLong = true;
|
|
CurrentIsShort = true;
|
|
CurrentOption = CurrentElement.Substring(2);
|
|
CurrentElement = null;
|
|
return true;
|
|
}
|
|
else if (CurrentElement.StartsWith("-"))
|
|
{
|
|
CurrentIsLong = false;
|
|
CurrentIsShort = true;
|
|
CurrentOption = CurrentElement[1].ToString();
|
|
CurrentElement = CurrentElement.Substring(2);
|
|
return true;
|
|
}
|
|
CurrentOption = CurrentElement;
|
|
CurrentElement = null;
|
|
CurrentIsLong = false;
|
|
CurrentIsShort = false;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
CurrentOption = CurrentElement[0].ToString();
|
|
CurrentElement = CurrentElement.Substring(1);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public string PopArgument()
|
|
{
|
|
string arg = this.arguments[0];
|
|
this.arguments.RemoveAt(0);
|
|
return arg;
|
|
}
|
|
|
|
}
|
|
}
|