コード例 #1
0
ファイル: Application.cs プロジェクト: rishit-singh/OpenShell
        /// <summary>
        /// Formats raw paramter strings to ApplicationArgument
        /// </summary>
        /// <param name="parameters"> Parameter string array. </param>
        /// <returns> Generated ApplicationArgument. </returns>
        public ApplicationArgument GetApplicationArgument(string[] parameters)
        {
            ApplicationArgument applicationArgument = new ApplicationArgument();

            Command.Flag FlagTemp = new Command.Flag();

            Stack <Command.Flag> FlagStack       = new Stack <Command.Flag>(),
                                 SingleFlagStack = new Stack <Command.Flag>();

            Stack <string> RawValueStack = new Stack <string>();


            if (parameters.Length == 0)
            {
                return(applicationArgument);
            }

            try
            {
                for (int x = 0; x < parameters.Length; x++)
                {
                    if (parameters[x] != null)
                    {
                        if (parameters[x][0] == '-' || $"{parameters[x][0]}{parameters[x][1]}" == "--")                                                   //	Checks for the flag prefixes.
                        {
                            if (!(FlagTemp = this.GetFlag(StringTools.GetSubString(parameters[x], 1, parameters[x].Length))).IsEqual(new Command.Flag())) //	Flag null check.
                            {
                                if (FlagTemp.IsSingle())
                                {
                                    SingleFlagStack.Push(FlagTemp);
                                }
                                else
                                {
                                    FlagStack.Push(FlagTemp);
                                }
                            }
                            else
                            {
                                throw new UnkownFlagException(FlagTemp.FlagString);
                            }
                        }

                        else
                        {
                            RawValueStack.Push(parameters[x]);
                        }
                    }
                }
            }
            catch (UnkownFlagException e)
            {
                e.Log();

                return(new ApplicationArgument());
            }

            applicationArgument = new ApplicationArgument(ArrayTools.InvertArray <Command.Flag>(FlagStack.ToArray()), ArrayTools.InvertArray <Command.Flag>(SingleFlagStack.ToArray()), ArrayTools.InvertArray <string>(RawValueStack.ToArray()));

            return(applicationArgument);
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: rishit-singh/OpenShell
        public ApplicationArgument GetApplicationArgument(Command.Flag[] flags)
        {
            ApplicationArgument argument;

            Stack <Command.Flag> FlagStack   = new Stack <Command.Flag>(),
                                 SingleFlags = new Stack <Command.Flag>();

            Stack <string> RawValueStack = new Stack <string>();

            Command.Flag FlagTemp;              // = new Command.Flag();

            try
            {
                for (int x = 0; x < flags.Length; x++)
                {
                    if (flags[x].IsNull())                      //	Flag doesnt exist
                    {
                        continue;
                    }
                    else if (flags[x].FlagString != null && flags[x].Value != null)
                    {
                        FlagStack.Push(flags[x]);
                    }
                    else if (flags[x].FlagString != null && flags[x].Value == null)
                    {
                        SingleFlags.Push(flags[x]);
                    }
                    else if (flags[x].FlagString == null && flags[x].Value != null)
                    {
                        RawValueStack.Push(flags[x].Value);
                    }
                    else
                    {
                        Program.Debug.Log($"FlagString: {flags[x].FlagString}\nValue: {flags[x].Value}\n");
                        throw new InvalidFlagException();
                    }
                }
            }
            catch (Exception e)
            {
                Program.Debug.Log(e.Message);

                return(new ApplicationArgument());                      //	returns a null instance
            }

            argument = new ApplicationArgument(FlagStack.ToArray(), SingleFlags.ToArray(), RawValueStack.ToArray());

            return(argument);
        }
コード例 #3
0
ファイル: Application.cs プロジェクト: rishit-singh/OpenShell
        /// <summary>
        /// Creates an array of flags in such an order that flags with values appear first in the array following the ones
        /// without values and the raw values.
        /// </summary>
        /// <returns></returns>
        public ApplicationArgument GetApplicationArgument()
        {
            ApplicationArgument argument;

            Stack <Command.Flag> FlagStack   = new Stack <Command.Flag>(),
                                 SingleFlags = new Stack <Command.Flag>();

            Stack <string> RawValueStack = new Stack <string>();

            Command.Flag FlagTemp;              // = new Command.Flag();

            try
            {
                for (int x = 0; x < this.Configuration.AppCommand.Parameters.Length; x++)
                {
                    if (this.Configuration.AppCommand.Parameters[x][0] == '-')
                    {
                        if ((FlagTemp = this.GetFlag(this.Configuration.AppCommand.Parameters[x])).IsNull())                            //	Flag doesnt exist
                        {
                            continue;
                        }
                        else if (FlagTemp.FlagString != null && FlagTemp.Value == null)
                        {
                            SingleFlags.Push(FlagTemp);
                        }
                        else if (FlagTemp.FlagString != null && FlagTemp.Value != null)
                        {
                            RawValueStack.Push(FlagTemp.Value);
                        }
                        else
                        {
                            throw new InvalidFlagException();
                        }
                    }
                }
            }
            catch (InvalidFlagException e)
            {
                Program.Debug.Log(e.Message);

                return(new ApplicationArgument());                      //	returns a null instance
            }

            argument = new ApplicationArgument(ArrayTools.InvertArray <Command.Flag>(FlagStack.ToArray()), SingleFlags.ToArray(), RawValueStack.ToArray());

            return(argument);
        }
コード例 #4
0
        public static void PrintApplicationArgument(ApplicationArgument applicationArgument)
        {
            Console.WriteLine("Flags:");
            for (int x = 0; x < applicationArgument.Flags.Length; x++)
            {
                Console.WriteLine($"{applicationArgument.Flags[x].FlagString}: {applicationArgument.Flags[x].Value}");
            }

            Console.WriteLine('\n');

            Console.WriteLine("Single Flags:");
            for (int x = 0; x < applicationArgument.SingleFlags.Length; x++)
            {
                Console.WriteLine($"{applicationArgument.SingleFlags[x].FlagString}");
            }

            Console.WriteLine('\n');

            Console.WriteLine("Raw Values:");
            for (int x = 0; x < applicationArgument.RawValues.Length; x++)
            {
                Console.WriteLine($"{applicationArgument.RawValues[x]}");
            }
        }