Example #1
0
        /// <summary>Process the output file path.</summary>
        /// <param name="parsedOptions">The parsed options.</param>
        /// <param name="processedOptions">The processed options.</param>
        /// <param name="startingDirectory">The starting directory.</param>
        public void ProcesOutputFountainFilePath(ParsedCommandLineOptions parsedOptions, CommandLineToolOptions processedOptions, string startingDirectory)
        {
            // Without a parsed object and a input file path we can't do anything.
            if (parsedOptions == null || processedOptions == null)
            {
                return;
            }

            // Generate an output-path when none is given.
            if (!string.IsNullOrEmpty(parsedOptions.OutputFountainFilePath))
            {
                // if the GIVEN output-path is not rooted we strip of the filename and tag the directory on it.
                processedOptions.RootedOutputFountainFilePath = Path.IsPathRooted(parsedOptions.OutputFountainFilePath)
                    ? parsedOptions.OutputFountainFilePath
                    : Path.Combine(startingDirectory, parsedOptions.OutputFountainFilePath);
            }
            else
            {
                processedOptions.GeneratedOutputFountainFilePath = Path.ChangeExtension(parsedOptions.InputFilePath, ".ink.fountain");

                // if the GENERATED output-path is not rooted we strip of the filename and tag the directory on it.
                processedOptions.RootedOutputFountainFilePath = Path.IsPathRooted(processedOptions.GeneratedOutputFountainFilePath)
                    ? processedOptions.GeneratedOutputFountainFilePath
                    : Path.Combine(startingDirectory, processedOptions.GeneratedOutputFountainFilePath);
            }
        }
Example #2
0
        /// <summary> Read the configuration from the config files, environment and command line. </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>Configuration object</returns>
        private static IConfigurationRoot ReadConfiguration(string[] args, ParsedCommandLineOptions options)
        {
            IConfigurationRoot config = GetConfig(args);

            if (config != null)
            {
                // We do not get a whole object from a config section, config.GetSection("ConfiguredOptions").Get<ConfiguredOptions>()
                // because command line options would then have to be prepended with the region


                options.InputFilePath                    = config.GetValue <string>("InputFile");
                options.OutputFilePath                   = config.GetValue <string>("OutputFile");
                options.OutputFountainFilePath           = config.GetValue <string>("OutputFountainFile");
                options.IsCountAllVisitsNeeded           = config.GetValue <bool>("CountAllVisits");
                options.IsPlayMode                       = config.GetValue <bool>("PlayMode");
                options.IsVerboseMode                    = config.GetValue <bool>("Verbose");
                options.IsOnlyShowJsonStatsActive        = config.GetValue <bool>("OnlyShowJsonStats");
                options.IsKeepOpenAfterStoryFinishNeeded = config.GetValue <bool>("KeepRunningAfterStoryFinished");

                // the config.GetValue<List<string>>("PluginNames") does not work, so we use a bind here
                config.Bind("PluginNames", options.PluginNames);
            }

            return(config);
        }
Example #3
0
        /// <summary>Process the flags by copying them from the parsed options to the processed options so we can always compare them.</summary>
        /// <param name="parsedOptions">The parsed options.</param>
        /// <param name="processedOptions">The processed options.</param>
        public void ProcesFlags(ParsedCommandLineOptions parsedOptions, CommandLineToolOptions processedOptions)
        {
            // Without a parsed object and a input file path we can't do anything.
            if (parsedOptions == null || processedOptions == null)
            {
                return;
            }

            // Most of the flags are not changed while running except for IsPlayMode.
            processedOptions.IsPlayMode                            = parsedOptions.IsPlayMode;
            processedOptions.IsVerboseMode                         = parsedOptions.IsVerboseMode;
            processedOptions.IsCountAllVisitsNeeded                = parsedOptions.IsCountAllVisitsNeeded;
            processedOptions.IsOnlyShowJsonStatsActive             = parsedOptions.IsOnlyShowJsonStatsActive;
            processedOptions.IsJsonOutputNeeded                    = parsedOptions.IsJsonOutputNeeded;
            processedOptions.IsKeepRunningAfterStoryFinishedNeeded = parsedOptions.IsKeepOpenAfterStoryFinishNeeded;
            processedOptions.PluginNames                           = parsedOptions.PluginNames;
        }
Example #4
0
        /// <summary>Process the input file path.</summary>
        /// <param name="parsedOptions">The parsed options.</param>
        /// <param name="processedOptions">The processed options.</param>
        /// <param name="startingDirectory">The starting directory.</param>
        public void ProcesInputFilePath(ParsedCommandLineOptions parsedOptions, CommandLineToolOptions processedOptions, string startingDirectory)
        {
            // Without a parsed object and a input file path we can't do anything.
            if (parsedOptions == null || processedOptions == null)
            {
                return;
            }

            processedOptions.InputFilePath = parsedOptions.InputFilePath;

            // Get the file's actual name, needed for reading after the working directory has changed.
            processedOptions.InputFileName = Path.GetFileName(parsedOptions.InputFilePath);

            processedOptions.RootedInputFilePath = Path.IsPathRooted(parsedOptions.InputFilePath)
                ? parsedOptions.InputFilePath
                : Path.Combine(startingDirectory, parsedOptions.InputFilePath);

            processedOptions.InputFileDirectory = Path.GetDirectoryName(processedOptions.RootedInputFilePath);
        }
Example #5
0
        /// <summary>Creates the command line tool options.</summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        private CommandLineToolOptions CreateCommandLineToolOptions(string[] args)
        {
            toolOptions = new CommandLineToolOptions();

            // Getting the current dir early is better in unstable situations.
            string startingDirectory = Directory.GetCurrentDirectory();

            var parsedOptions = new ParsedCommandLineOptions();

#if USE_NETCORE_CONFIGURATION
            IConfigurationRoot config = ReadConfiguration(args, parsedOptions);

            Logger = new LoggerConfiguration()
                     .ReadFrom.Configuration(config)
                     .CreateLogger();

            Logger.Information("Started on {0}", _startTime);
            Logger.Information("Config read.");
            Logger.Debug("Config {@0}", config);
#else
            Logger        = new LoggerConfiguration().CreateLogger();
            parsedOptions = ParseArguments(args, options);
#endif

            if (parsedOptions == null || !parsedOptions.IsInputPathGiven)
            {
                ExitWithUsageInstructions();
            }

            ProcesOutputFilePath(parsedOptions, toolOptions, startingDirectory);
            ProcesOutputFountainFilePath(parsedOptions, toolOptions, startingDirectory);
            ProcesInputFilePath(parsedOptions, toolOptions, startingDirectory);
            ProcesFlags(parsedOptions, toolOptions);

            return(toolOptions);
        }
Example #6
0
        /// <summary>Parses the command line arguments.</summary>
        /// <param name="args">The command line arguments.</param>
        /// <returns>An options object.</returns>
        public void ParseArguments(string[] args, ParsedCommandLineOptions options)
        {
            if (args == null || args.Length == 0 || options == null)
            {
                return;
            }


            bool expectingOutputFilename = false;
            bool expectingPluginName     = false;

            // Process arguments
            int lastArgumentIndex = args.Length - 1;

            for (int i = 0; i < args.Length; i++)
            {
                string argument = args[i];

                if (i == lastArgumentIndex)
                {
                    // When on the last argument we assume it's the file.
                    options.InputFilePath = argument;
                }
                else if (expectingOutputFilename)
                {
                    // When a output filename flag preceded the current argument we assume it's the output filename.
                    options.OutputFilePath  = argument;
                    expectingOutputFilename = false;
                }
                else if (expectingPluginName)
                {
                    // When a plug-in name flag preceded the current argument we assume it's a plug-in name.
                    options.PluginNames.Add(argument);
                    expectingPluginName = false;
                }
                else if (argument.StartsWith("-"))
                {
                    // Determine options
                    switch (argument)
                    {
                    case "-p": options.IsPlayMode = true; break;

                    case "-v": options.IsVerboseMode = true; break;

                    case "-j": options.IsJsonOutputNeeded = true; break;

                    case "-s": options.IsOnlyShowJsonStatsActive = true; break;

                    case "-o": expectingOutputFilename = true; break;

                    case "-c": options.IsCountAllVisitsNeeded = true; break;

                    case "-x": expectingPluginName = true; break;

                    case "-k": options.IsKeepOpenAfterStoryFinishNeeded = true; break;

                    default: ConsoleInteractor.WriteWarning("Unsupported argument flag: '{0}'", argument); break;
                    }
                }
                else
                {
                    ConsoleInteractor.WriteWarning("Unexpected argument: '{0}'", argument); break;
                }
            }
        }