コード例 #1
0
        public void CreateFromCommandLine(
            CompilerArguments compilerArguments,
            CliArguments cliArguments,
            string[] args
            )
        {
            int i = 0;

            while (i < args.Length)
            {
                if (TryGetCompilerArgument(args[i], out AbstractCompilerArgument matchedCompilerArgument))
                {
                    i = ProcessArguments(
                        args,
                        i + 1,
                        arguments => matchedCompilerArgument.Parse(arguments, compilerArguments)
                        );
                }
                else if (TryGetCliArgument(args[i], out AbstractCliArgument matchedCliArgument))
                {
                    i = ProcessArguments(
                        args,
                        i + 1,
                        arguments => matchedCliArgument.Parse(arguments, cliArguments)
                        );
                }
                else
                {
                    throw new ArgumentException("Unknown argument: " + args[i]);
                }
            }
        }
コード例 #2
0
        public RandomGraphCommand(CliArguments options)
        {
            Options  = options;
            Log      = new Logger(Options.Debug ? Console.Out : null, Console.Out);
            Filename = FixFilename(options.OutputFilename);
            Random   = Options.RandomSeed.HasValue ? new Random(Options.RandomSeed.Value) : new Random();
            var sizesImmutable = Options.VertexCounts.Zip(Options.EdgeCounts, (v, e) => (v, e)).ToImmutableArray();

            Sizes = sizesImmutable.Any() ? sizesImmutable : new[] { (0, 0) }.ToImmutableArray();
コード例 #3
0
        static async Task <List <TrackDirInfo> > GetWorkingDirectories(CliArguments args)
        {
            var baseDirs = args.Directories
                           .Map(Path.GetFullPath)
                           .Map(x => x.TrimEnd('/'))
                           .Distinct()
                           .ToList();

            IEnumerable <string> SubDirs(string dir) =>
            Directory.GetDirectories(dir, "*", SearchOption.AllDirectories);

            var dirs       = !args.Recursive ? baseDirs : baseDirs.Concat(baseDirs.Bind(SubDirs));
            var inputRoots = await dirs.Map(x => FsReader.GetInputRoot(x)).Apply(Task.WhenAll);

            return(inputRoots.Map(TrackDirInfoExtractor.Extract).ToList());
        }
コード例 #4
0
        public void Start(ServerDatas gameServerDatas, ServerDatas mmServerDatas, Func <Match, ServerGameMaster> createGameMaster, bool debug = false)
        {
            this.debug = debug;
            Server     = new MyUdpServer();
            string udpAddress = CliArguments.GetArgument("--address");
            string udpPort    = CliArguments.GetArgument("--port");

            Server.Start(udpAddress != null ? udpAddress : gameServerDatas.address, udpPort != null ? int.Parse(udpPort) : gameServerDatas.port, debug);
            Client = new MyTcpClient();
            string mmAddress = CliArguments.GetArgument("--mmaddress");
            string mmPort    = CliArguments.GetArgument("--mmport");

            Client.Start(mmAddress != null ? mmAddress : mmServerDatas.address, mmPort != null ? int.Parse(mmPort) : mmServerDatas.port, OnMMReady, OnConnectionFail, debug);
            _createGameMaster = createGameMaster;
            _defaultWorld     = World.DefaultGameObjectInjectionWorld;
        }
コード例 #5
0
        static CliEnvironment CreateCliEnvironment(CliArguments args)
        {
#if DEBUG
            const char ProgressCharacter = '#'; // Rider console does not like long dash
#else
            const char ProgressCharacter = '─';
#endif
            var options = new ProgressBarOptions
            {
                ProgressCharacter   = ProgressCharacter,
                ProgressBarOnBottom = true
            };

            var progressBar = new ProgressBar(100, "", options);

            return(new CliEnvironment(
                       args: args,
                       writeInfoLine: progressBar.WriteLine,
                       updateProgress: p => progressBar.Tick((int)(p * 100))
                       ));
        }
コード例 #6
0
        static int Main(string[] args)
        {
            // Setup the console output stream.
            StreamWriter output = new StreamWriter(Console.OpenStandardOutput())
            {
                AutoFlush = true
            };

            Console.SetOut(output);

            // Parse the sectorfile
            CompilerArguments compilerArguments = CompilerArgumentsFactory.Make();
            CliArguments      cliArguments      = CliArgumentsFactory.Make();

            try
            {
                ArgumentParserFactory.Make().CreateFromCommandLine(compilerArguments, cliArguments, args);
            } catch (ArgumentException exception)
            {
                output.Write(exception.Message);
                return(1);
            }

            int returnCode = SectorFileCompilerFactory.Create(
                compilerArguments,
                new List <IEventObserver>()
            {
                new ConsoleOutput(output)
            }
                ).Compile();

            if (cliArguments.PauseOnFinish)
            {
                output.Write("Press any key to exit");
                Console.ReadKey();
            }
            return(returnCode);
        }
コード例 #7
0
 public BenchmarkCommand(CliArguments options)
 {
     Options = options;
     Log     = new Logger(Options.Debug ? Console.Out : null, Console.Out);
 }
コード例 #8
0
        private static bool TryParseArguments(string[] args, out CliArguments result)
        {
            result.Input    = new[] { Environment.CurrentDirectory };
            result.Output   = "result.csv";
            result.Patterns = new[] { "*.*" };
            result.Sync     = false;

            bool printUsage = args.Select(item => item.ToLowerInvariant()).Intersect(new[] { "-h", "--help", "/help", "/?" }).Any();

            if (printUsage)
            {
                Console.Error.WriteLine("Usage:");
            }

            foreach (var arg in args)
            {
                var match = arg.ToLowerInvariant();

                var knownArgument = TryMatchArray("input", ref result.Input, "Input directories") ||
                                    TryMatchParameter("output", ref result.Output, "Output file (.csv)") ||
                                    TryMatchArray("patterns", ref result.Patterns, "Included file patterns") ||
                                    TryMatchFlag("sync", ref result.Sync, "Synchronized or parallel execution");

                if (printUsage)
                {
                    break;
                }

                if (!knownArgument)
                {
                    Console.Error.WriteLine("Invalid argument: " + arg);
                }

                bool TryMatchFlag(string name, ref bool parameter, string description)
                {
                    if (printUsage && description != null)
                    {
                        Console.Error.WriteLine($"\t--{name}");
                        Console.Error.WriteLine($"\t\t{description}");
                        Console.Error.WriteLine("\t\tDefault: " + parameter);
                        return(false);
                    }

                    if (match == "--" + name)
                    {
                        parameter = true;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                bool TryMatchParameter(string name, ref string parameter, string description)
                {
                    if (printUsage && description != null)
                    {
                        Console.Error.WriteLine($"\t--{name}=<value>");
                        Console.Error.WriteLine($"\t\t{description}");
                        Console.Error.WriteLine("\t\tDefault: " + parameter);
                        return(false);
                    }

                    var prefix = "--" + name + "=";

                    if (match.StartsWith(prefix))
                    {
                        parameter = arg.Substring(prefix.Length);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                bool TryMatchArray(string name, ref string[] array, string description)
                {
                    if (printUsage && description != null)
                    {
                        Console.Error.WriteLine($"\t--{name}=<value1,value2,...>");
                        Console.Error.WriteLine($"\t\t{description}");
                        Console.Error.WriteLine("\t\tDefault: " + string.Join(",", array));
                        return(false);
                    }

                    string parameter = null;

                    if (!TryMatchParameter(name, ref parameter, null))
                    {
                        return(false);
                    }

                    array = parameter
                            .Split(new[] { ',' })
                            .Select(item => item.Trim())
                            .Where(item => !string.IsNullOrEmpty(item))
                            .ToArray();

                    return(true);
                }
            }

            return(!printUsage);
        }
コード例 #9
0
 public ColoringCommand(CliArguments options)
 {
     Options = options;
     Log     = new Logger(Options.Debug ? Console.Out : null, Console.Out);
 }
コード例 #10
0
 public ArgumentParserTest()
 {
     parser            = ArgumentParserFactory.Make();
     compilerArguments = CompilerArgumentsFactory.Make();
     cliArguments      = CliArgumentsFactory.Make();
 }
コード例 #11
0
 public NoWaitCliArgumentTest()
 {
     arguments           = new CliArguments();
     commandLineArgument = new NoWaitCliArgument();
 }