Ejemplo n.º 1
0
 public static void TryReadOptionsFile(string filename, OptionsInformation optionsInformation)
 {
     try
     {
         var optionsTxt   = File.ReadAllText(filename);
         var argsFromFile = optionsTxt.Split(
             new[] { '\r', '\n', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
         OptionsInformation.ParseArgs(argsFromFile, optionsInformation);
     }
     catch (Exception ex)
     {
         AasxPackageExplorer.Log.Singleton.Error(ex, "Reading options file: " + filename);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Infers application options based on the command-line arguments.
        /// </summary>
        /// <param name="exePath">path to AasxPackageExplorer.exe</param>
        /// <param name="args">command-line arguments</param>
        /// <returns>inferred options</returns>
        public static OptionsInformation InferOptions(string exePath, string[] args)
        {
            var optionsInformation = new OptionsInformation();

            // Load the default command-line options from a file with a conventional file name

            var pathToDefaultOptions = System.IO.Path.Combine(
                System.IO.Path.GetDirectoryName(exePath),
                System.IO.Path.GetFileNameWithoutExtension(exePath) + ".options.json");

            Log.Singleton.Info(
                "The default options are expected in the JSON file: {0}", pathToDefaultOptions);
            if (File.Exists(pathToDefaultOptions))
            {
                Log.Singleton.Info(
                    "Loading the default options from: {0}", pathToDefaultOptions);
                OptionsInformation.ReadJson(pathToDefaultOptions, optionsInformation);
            }
            else
            {
                Log.Singleton.Info(
                    "The JSON file with the default options does not exist;" +
                    "no default options were loaded: {0}", pathToDefaultOptions);
            }

            // Cover the special case for having a single positional command-line option

            if (args.Length == 1 && !args[0].StartsWith("-"))
            {
                string directAasx = args[0];
                Log.Singleton.Info("Direct request to load AASX {0} ..", directAasx);
                optionsInformation.AasxToLoad = directAasx;
            }

            // Parse options from the command-line and execute the directives on the fly (such as parsing and
            // overruling given in the additional option files, *e.g.*, through "-read-json" and "-options")

            Log.Singleton.Info($"Parsing {args.Length} command-line option(s)...");

            for (var i = 0; i < args.Length; i++)
            {
                Log.Singleton.Info($"Command-line option: {i}: {args[i]}");
            }

            OptionsInformation.ParseArgs(args, optionsInformation);

            return(optionsInformation);
        }