public static int Main(string[] args)
        {
            string[] parseArgs;
            Executor executor;

            if (args.Length > 0 && args[0].EndsWith(".json"))
            {
                executor  = new Executor(args[0]);
                parseArgs = new string[args.Length - 1];
                Array.Copy(args, 1, parseArgs, 0, args.Length - 1);
            }
            else
            {
                executor  = new Executor();
                parseArgs = args;
            }

            Setup jsonSetup = executor.OpenFile();

            if (jsonSetup == null)
            {
                Console.Error.WriteLine("Error: Could not load Json configuration file.");
                return(1);
            }
            string os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "windows" : "unix";

            if (jsonSetup.PrepareValues(os, executor.SettingParameters, executor.configFilePath) == 0)
            {
                if (executor.DefineParameters(parseArgs, jsonSetup))
                {
                    if (string.IsNullOrEmpty(executor.CommandSelectedByUser))
                    {
                        Console.Error.WriteLine("Error: No command was passed. Use -? for help.");
                        return(1);
                    }

                    List <string> paramSelected = new List <string>();
                    foreach (KeyValuePair <string, string> param in executor.CommandParameters[executor.CommandSelectedByUser])
                    {
                        if (!string.IsNullOrEmpty(param.Value))
                        {
                            paramSelected.Add(param.Key);
                        }
                    }

                    // If aliases exist, and the user's parameters have no match, we'll end up in this state.
                    // If a default alias is provided, we can add that; otherwise we should error out as the
                    // behavior at this point may be unexpected.
                    if (paramSelected.Count == 0 && executor.CommandParameters[executor.CommandSelectedByUser].Count > 0)
                    {
                        string defaultAlias = jsonSetup.Commands[executor.CommandSelectedByUser].DefaultValues.DefaultAlias;
                        if (!string.IsNullOrEmpty(defaultAlias))
                        {
                            Console.WriteLine($"No parameter selected, using default alias '{defaultAlias}'");
                            paramSelected.Add(defaultAlias);
                        }
                        // May want to error out here in the future;  Need to find out if there's ever a reason
                        // to allow aliases, but specify none.
                    }

                    return(jsonSetup.ExecuteCommand(executor.CommandSelectedByUser, paramSelected));
                }
            }
            //There was an error when parsing the user input, Define Parameters is in charge of printing an error message.
            return(1);
        }
Example #2
0
        public static int Main(string[] args)
        {
            string[] parseArgs;
            Executor executor;
            if(args.Length > 0 && args[0].Contains("config.json"))
            {
                executor = new Executor(args[0]);
                parseArgs = new string[args.Length - 1];
                Array.Copy(args, 1, parseArgs, 0, args.Length - 1);
            }
            else
            {
                executor = new Executor();
                parseArgs = args;
            }

            Setup jsonSetup = executor.OpenFile();
            if (jsonSetup == null)
            {
                Console.Error.WriteLine("Error: Could not load Json configuration file.");
                return 1;
            }
            string os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "windows": "unix";

            jsonSetup.prepareValues(os, executor.SettingParameters, executor.configFilePath);
            if (executor.DefineParameters(parseArgs, jsonSetup))
            {
                List<string> paramSelected = new List<string>();
                foreach (KeyValuePair<string, string> param in executor.CommandParameters[executor.CommandSelectedByUser])
                {
                    if (!string.IsNullOrEmpty(param.Value))
                    {
                        paramSelected.Add(param.Key);
                    }
                }
                return jsonSetup.ExecuteCommand(executor.CommandSelectedByUser, paramSelected);
            }
            //There was an error when parsing the user input, Define Parameters is in charge of printing an error message.
            return 1;
        }
Example #3
0
        public static int Main(string[] args)
        {
            string[] parseArgs;
            Executor executor;
            if (args.Length > 0 && args[0].EndsWith(".json"))
            {
                executor = new Executor(args[0]);
                parseArgs = new string[args.Length - 1];
                Array.Copy(args, 1, parseArgs, 0, args.Length - 1);
            }
            else
            {
                executor = new Executor();
                parseArgs = args;
            }

            Setup jsonSetup = executor.OpenFile();
            if (jsonSetup == null)
            {
                Console.Error.WriteLine("Error: Could not load Json configuration file.");
                return 1;
            }
            string os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "windows" : "unix";

            if (jsonSetup.PrepareValues(os, executor.SettingParameters, executor.configFilePath) == 0)
            {
                if (executor.DefineParameters(parseArgs, jsonSetup))
                {
                    if (string.IsNullOrEmpty(executor.CommandSelectedByUser))
                    {
                        Console.Error.WriteLine("Error: No command was passed. Use -? for help.");
                        return 1;
                    }

                    List<string> paramSelected = new List<string>();
                    foreach (KeyValuePair<string, string> param in executor.CommandParameters[executor.CommandSelectedByUser])
                    {
                        if (!string.IsNullOrEmpty(param.Value))
                        {
                            paramSelected.Add(param.Key);
                        }
                    }

                    // If aliases exist, and the user's parameters have no match, we'll end up in this state. 
                    // If a default alias is provided, we can add that; otherwise we should error out as the 
                    // behavior at this point may be unexpected.
                    if (paramSelected.Count == 0 && executor.CommandParameters[executor.CommandSelectedByUser].Count > 0)
                    {
                        string defaultAlias = jsonSetup.Commands[executor.CommandSelectedByUser].DefaultValues.DefaultAlias;
                        if (!string.IsNullOrEmpty(defaultAlias))
                        {
                            Console.WriteLine($"No parameter selected, using default alias '{defaultAlias}'");
                            paramSelected.Add(defaultAlias);
                        }
                        // May want to error out here in the future;  Need to find out if there's ever a reason
                        // to allow aliases, but specify none.
                    }

                    return jsonSetup.ExecuteCommand(executor.CommandSelectedByUser, paramSelected);
                }
            }
            //There was an error when parsing the user input, Define Parameters is in charge of printing an error message.
            return 1;
        }