using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommandLine;
using CommandLine.Text;
using log4net;
using log4net.Config;
using System.IO;
namespace P4NetContentTrigger
{
class CmdLineOptions
{
[Option('p', "port", DefaultValue = "", HelpText = "Perforce server to connect to.")]
public string Port { get; set; }
[Option('u', "user", DefaultValue = "", HelpText = "Perforce user to connect as.")]
public string User { get; set; }
[Option('c', "change",Required = true, HelpText = "Changelist number to process.")]
public int Change { get; set; }
[Option('t', "testing", DefaultValue = false, HelpText = "Trigger testing: reads contents of files if first line contains 'fail' will fail.")]
public bool Testing { get; set; }
[Option('v', "verbose", DefaultValue = false, HelpText = "Verbose output to log file.")]
public bool Verbose { get; set; }
[ParserState]
public IParserState LastParserState { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this,
(HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
class P4NetContentTrigger
{
static void Main(string[] args)
{
// Configure logging
XmlConfigurator.Configure(new System.IO.FileInfo(Path.Combine(
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
"log4net.properties")));
ILog _log = LogManager.GetLogger(typeof(P4NetContentTrigger));
_log.Debug("log4net initialize");
_log.DebugFormat("Args: {0}", string.Join("|", args));
var options = new CmdLineOptions();
var parser = new CommandLine.Parser();
if (!parser.ParseArguments(args, options))
{
_log.ErrorFormat("Failed to parse args: {0}", string.Join("|", args));
_log.Error(options.GetUsage());
Console.WriteLine(options.GetUsage());
Environment.Exit(1);
}
if (options.Verbose) // Ensure logging at Debug level if specified
{
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = log4net.Core.Level.Debug;
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty);
}
var trig = new P4SubmitContentTrigger();
Environment.Exit(trig.Validate(options));
}
}
}