Ejemplo n.º 1
0
 static void EnqueueOperation(ref TabulateOperation operation)
 {
     if (operation == null)
     {
         return;
     }
     operation.Validate(); // Throws exception if validation fails
     s_operations.Add(operation);
     operation = null;
 }
Ejemplo n.º 2
0
        static void ParseCommandLine(string[] args)
        {
            TabulateOperation bankOperation = null;

            for (int i = 0; i < args.Length; ++i)
            {
                string arg = args[i];
                switch (arg)
                {
                case "-a":
                    s_aggregate = true;
                    break;

                case "-h":
                    s_showHelp = true;
                    break;

                case "-j":
                    s_json = true;
                    break;

                case "-bk":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-bk' command-line argument.");
                    }
                    if (!int.TryParse(args[i], out s_bankKey))
                    {
                        throw new ArgumentException($"Value specified for '-bk' argument is not integer. ({args[i]})");
                    }
                    break;

                case "-ids":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-ids' command-line argument.");
                    }
                    if (!File.Exists(args[i]))
                    {
                        throw new ArgumentException($"'-ids' file not found. ({args[i]})");
                    }
                    EnqueueOperation(ref bankOperation);     // Does nothing if there is no bank operation;
                    if (s_operations.Count == 0)
                    {
                        throw new ArgumentException("'-ids' argument must follow a package or bank identification.");
                    }
                    if (s_operations.Last().IdFilename != null)
                    {
                        throw new ArgumentException("Only one '-ids' argument may be specified per package.");
                    }
                    s_operations.Last().IdFilename = args[i];
                    break;

                case "-lid":
                    s_reportIds = true;
                    break;

                case "-lidx":
                    s_reportIds    = true;
                    s_exitAfterIds = true;
                    break;

                case "-rbrk":
                    s_exportRubrics = true;
                    break;

                case "-o":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-o' command-line argument.");
                    }
                    {
                        string path = args[i];
                        if (!ValidateOutputPrefix(ref path))
                        {
                            throw new ArgumentException($"'-o' invalid filename or path not found. ({args[i]})");
                        }
                        EnqueueOperation(ref bankOperation);     // Does nothing if there is no bank operation;
                        if (s_operations.Count == 0)
                        {
                            throw new ArgumentException("'-o' argument must follow a package or bank identification.");
                        }
                        if (s_operations.Last().ReportPrefix != null)
                        {
                            throw new ArgumentException("Only one '-o' argument may be specified per package.");
                        }
                        s_operations.Last().ReportPrefix = path;
                        if (s_aggregateReportPrefix == null)
                        {
                            s_aggregateReportPrefix = path;
                        }
                    }
                    break;

                case "-bank":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-bank' command-line argument.");
                    }
                    {
                        Uri uri;
                        if (!Uri.TryCreate(args[i], UriKind.Absolute, out uri))
                        {
                            throw new ArgumentException($"Invalid bank URL '{args[i]}");
                        }
                        if (bankOperation != null && bankOperation.BankUrl != null)
                        {
                            EnqueueOperation(ref bankOperation);
                        }
                        if (bankOperation == null)
                        {
                            bankOperation = new TabulateOperation();
                        }
                        bankOperation.BankUrl = uri.ToString();
                    }
                    break;

                case "-ns":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-ns' command-line argument.");
                    }
                    if (bankOperation != null && bankOperation.BankNamespace != null)
                    {
                        EnqueueOperation(ref bankOperation);
                    }
                    if (bankOperation == null)
                    {
                        bankOperation = new TabulateOperation();
                    }
                    bankOperation.BankNamespace = args[i];
                    break;

                case "-at":
                    ++i;
                    if (i > args.Length)
                    {
                        throw new ArgumentException("No value specified for '-ns' command-line argument.");
                    }
                    if (bankOperation != null && bankOperation.BankAccessToken != null)
                    {
                        EnqueueOperation(ref bankOperation);
                    }
                    if (bankOperation == null)
                    {
                        bankOperation = new TabulateOperation();
                    }
                    bankOperation.BankAccessToken = args[i];
                    break;

                case "-dedup":
                    s_deDuplicate = true;
                    break;

                case "-w":
                    s_waitBeforeExit = true;
                    break;

                default:
                    if (arg.StartsWith("-v", StringComparison.OrdinalIgnoreCase) && (arg[2] == '-' || arg[2] == '+'))
                    {
                        var key   = arg.Substring(3).ToLowerInvariant();
                        var value = arg[2] == '+';
                        if (key.Equals("all", StringComparison.Ordinal))
                        {
                            if (!value)
                            {
                                throw new ArgumentException(
                                          "Invalid command-line option '-v-all'. Options must be disabled one at a time.");
                            }
                            gValidationOptions.EnableAll();
                        }
                        else
                        {
                            gValidationOptions.SetEnabled(key, value);
                        }
                    }
                    else
                    {
                        EnqueueOperation(ref bankOperation);     // Does nothing if there is no bank operation;
                        string path = arg;
                        if (!ValidatePackagePath(ref path))
                        {
                            throw new ArgumentException("No match for path: " + arg);
                        }
                        TabulateOperation operation = new TabulateOperation();
                        operation.PackagePath = arg;
                        EnqueueOperation(ref operation);
                    }
                    break;
                }
            } // for each argument

            // If there's a pending bank operation enqueue it.
            EnqueueOperation(ref bankOperation);
        }