xenadmin/xe/Xe.cs
Konstantina Chremmou 2bbebce05f Replaced field thinCliProtocol.dGlobalDebugstatic method Logger.Debug()
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
2022-05-09 15:21:53 +01:00

135 lines
4.8 KiB
C#

/* Copyright (c) Citrix Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
namespace ThinCLI
{
static class MainClass
{
public static void Main(string[] args)
{
var tCliProtocol = new thinCLIProtocol(
Console.Write, Console.WriteLine, Console.ReadLine,
Environment.Exit, i => { }, new Config());
string body = "";
char[] eqsep = {'='};
for (int i = 0; i < args.Length; i++)
{
string s = args[i];
try
{
if (s.StartsWith("server"))
{
tCliProtocol.conf.hostname = s.Split(eqsep)[1];
}
else if (s.Equals("-s"))
{
tCliProtocol.conf.hostname = args[++i];
}
else if (s.Equals("-u"))
{
tCliProtocol.conf.username = args[++i];
}
else if (s.Equals("-pw"))
{
tCliProtocol.conf.password = args[++i];
}
else if (s.Equals("-p"))
{
tCliProtocol.conf.port = Int32.Parse(args[++i]);
}
else if (s.Equals("--nossl"))
{
tCliProtocol.conf.nossl = true;
}
else if (s.Equals("-debug"))
{
tCliProtocol.conf.debug = true;
}
else if (s.Equals("-version"))
{
Console.WriteLine("ThinCLI protocol: " + tCliProtocol.major + "." + tCliProtocol.minor);
Environment.Exit(0);
}
else
{
if (s.Contains("="))
{
tCliProtocol.EnteredParamValues.Add(s.Split(eqsep)[1]);
}
body += s + "\n";
}
}
catch
{
Logger.Error("Failed to parse command-line arguments");
Logger.Usage();
Environment.Exit(1);
}
}
if (tCliProtocol.conf.hostname.Equals(""))
{
Logger.Error("No hostname was specified.");
Logger.Usage();
Environment.Exit(1);
}
Messages.performCommand(body, tCliProtocol);
}
}
internal static class Logger
{
internal static void Usage()
{
Console.WriteLine("Usage:");
Console.WriteLine(" xe -s <server> -u <username> -pw <password> [-p <port>] <command> <arguments>");
Console.WriteLine("For help, use xe -s <server> -u <user> -pw <password> [-p <port>] help");
}
internal static void Debug(string msg, thinCLIProtocol tCliProtocol)
{
if (tCliProtocol.conf.debug)
Console.WriteLine("Debug: " + msg);
}
internal static void Error(string x)
{
Console.WriteLine("Error: " + x);
}
}
}