private static Action ParseArgs()

in code/Tools/Ops/ManageQueues/Program.cs [122:232]


        private static Action ParseArgs(string[] args)
        {
            var action = Action.None;

            int i = 0;
            while (i < args.Length)
            {
                if (args[i].StartsWith("-DeleteMessage", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = Action.DeleteMessage;
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-ListQueues", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = Action.ListQueues;
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-Name=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Name=".Length;
                    environmentName = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-QueueName=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-QueueName=".Length;
                    queueName = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-QueueStats", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = Action.QueueStats;
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-SeqNum=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-SeqNum=".Length;
                    seqNum = long.Parse(args[i].Substring(prefixLen));
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-ShowDeadLetterMessages", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = Action.ShowDeadLetterMessages;
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-ShowMessages", StringComparison.CurrentCultureIgnoreCase))
                {
                    action = Action.ShowMessages;
                    i++;
                    continue;
                }
                else
                {
                    Usage();
                    Environment.Exit(ErrorBadArguments);
                }
            }

            if (string.IsNullOrWhiteSpace(environmentName))
            {
                Console.WriteLine("Usage error: environment name not specified.");
                Usage();
                Environment.Exit(ErrorBadArguments);
            }

            // ensure that a queue name is specified (for all actions other than ListQueues)
            if (action != Action.ListQueues && string.IsNullOrWhiteSpace(queueName))
            {
                Console.WriteLine("Usage error: queue name not specified.");
                Usage();
                Environment.Exit(ErrorBadArguments);
            }

            // check that specified queue name is valid (for all actions other than ListQueues)
            if (action != Action.ListQueues && queueName != null)
            {
                bool found = false;
                foreach (QueueIdentifier queueId in Enum.GetValues(typeof(QueueIdentifier)))
                {
                    if (queueId.ToString().ToLower().Equals(queueName.ToLower()))
                    {
                        selectedQueueId = queueId;
                        found = true;
                    }
                }

                if (found == false)
                {
                    Console.WriteLine($"Specified queue name {queueName} does not exist.");
                    Usage();
                    Environment.Exit(ErrorBadArguments);
                }
            }

            // check that delete specifies a sequence number
            if (action == Action.DeleteMessage && !seqNum.HasValue)
            {
                Console.WriteLine("DeleteMessage action requires a sequence number for the message to delete.");
                Usage();
                Environment.Exit(ErrorBadArguments);
            }

            return action;
        }