#region Disclaimer / License
// Copyright (C) 2010, Jackie Ng
// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
namespace OSGeo.MapGuide.MaestroAPI
{
///
/// A helper class to parse command-line arguments
///
///
/// Command-line arguments use the following format:
///
/// -name1 -name2[:value2] -name3[:value3]
///
public class ArgumentParser
{
private Dictionary _values;
///
/// Constructs a new instance
///
///
public ArgumentParser(string[] args)
{
_values = new Dictionary();
foreach (var arg in args)
{
if (arg.Length > 0 && arg[0] == '-') //NOXLATE
{
string name = arg.Substring(1);
string value = string.Empty;
var cidx = arg.IndexOf(':'); //NOXLATE
if (cidx >= 0)
{
name = arg.Substring(1, cidx - 1);
value = arg.Substring(cidx + 1);
}
_values[name] = value;
}
}
}
///
/// Gets a collection of name-value pairs of arguments with values
///
///
public NameValueCollection GetAllArgumentsWithValues()
{
var nvc = new NameValueCollection();
foreach (var key in _values.Keys)
{
if (!string.IsNullOrEmpty(_values[key]))
nvc[key] = _values[key];
}
return nvc;
}
///
/// Gets whether the particular switch has been defined
///
///
///
public bool IsDefined(string name)
{
return _values.ContainsKey(name);
}
///
/// Gets the value of the specified switch
///
///
///
public string GetValue(string name)
{
return _values[name];
}
}
///
/// A set of common command-line arguments
///
public static class CommandLineArguments
{
///
/// The name of the API provider
///
public const string Provider = "Provider"; //NOXLATE
///
/// The session id
///
public const string Session = "SessionId"; //NOXLATE
///
/// The username
///
public const string Username = "Username"; //NOXLATE
///
/// The password
///
public const string Password = "Password"; //NOXLATE
}
}