/*
 * Copyright 2014, Armenak Grigoryan, and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */
package com.strider.datadefender;

import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import picocli.CommandLine.Option;

import lombok.Getter;

/**
 * Database configuration options for picocli.
 * 
 * @author Zaahid Bateson
 */
@Getter
public class DbConfig {

    public enum Vendor {
        H2, MYSQL, POSTGRESQL, SQLSERVER, ORACLE;
    }

    private static final Map<String, Vendor> VENDOR_MAP = Map.of(
        "h2", Vendor.H2,
        "mysql", Vendor.MYSQL,
        "mariadb", Vendor.MYSQL,
        "postgresql", Vendor.POSTGRESQL,
        "sqlserver", Vendor.SQLSERVER,
        "mssql", Vendor.SQLSERVER,
        "oracle", Vendor.ORACLE
    );

    private Vendor vendor;

    @Option(names = { "-u", "--user" }, description = "The username to connect with", required = false)
    private String username;
    
    @Option(names = { "-p", "--password" }, description = "The password to connect with", required = false, arity = "0..1", interactive = true)
    private String password;

    @Option(names = { "--schema" }, description = "The schema to connect to", required = false)
    private String schema;

    @Option(names = { "--skip-empty-tables-metadata" }, description = "Skips generating metadata for empty tables", required = false, defaultValue = "true")
    private boolean skipEmptyTables;

    @Option(names = { "--include-table-patterns-metadata" }, description = "List of regex patterns matching table names to include for metadata analysis", required = false)
    private List<Pattern> includeTablePatterns;
    @Option(names = { "--exclude-table-patterns-metadata" }, description = "List of regex patterns matching table names to exclude for metadata analysis", required = false)
    private List<Pattern> excludeTablePatterns;

    private String url;

    @Option(
        names = { "--vendor" },
        description = "Database vendor, available options are: h2, mysql, mariadb, postgresql, sqlserver, oracle. "
            + "If not specified, vendor will attempt to be extracted from the datasource url for a jdbc scheme.",
        required = false
    )
    public void setVendor(String vendor) {
        String c = vendor.trim().toLowerCase();
        if (!VENDOR_MAP.containsKey(c)) {
            throw new IllegalArgumentException(
                "Invalid value for option '--vendor': Valid options are: "
                + "h2, mysql, mariadb, postgresql, sqlserver and oracle."
            );
        }
        this.vendor = VENDOR_MAP.get(c);
    }

    @Option(names = { "--url" }, description = "The datasource URL", required = true)
    public void setUrl(String url) {
        Pattern p = Pattern.compile("\\s*jdbc:([^:]+):.*");
        if (vendor == null) {
            Matcher m = p.matcher(url);
            if (m.find()) {
                setVendor(m.group(1));
            }
        }
        this.url = url;
    }
}

@@ -2117,33 +2117,32 @@
 de-table-pattern
-s
 -metadata%22 %7D, de
@@ -2154,38 +2154,26 @@
 tion = %22
-List of regex p
+P
 attern
-s
+(s)
  matchin
@@ -2333,17 +2333,16 @@
 -pattern
-s
 -metadat
@@ -2366,30 +2366,18 @@
  = %22
-List of regex p
+P
 attern
-s
+(s)
  mat

Change repeatable option name to 'singular'