package ru.kirillius.pf.sdn.core.Util;

import java.util.Arrays;

/**
 * Utility methods for parsing command-line arguments used by the launcher.
 */
public final class CommandLineUtils {
    private CommandLineUtils() {
    }

    /**
     * Returns the first command-line argument starting with the given flag name.
     */
    public static String getArgument(String argname, String[] args) {
        var first = Arrays.stream(args).filter(arg -> arg.startsWith("-" + argname)).findFirst();
        if (first.isEmpty()) {
            throw new IllegalArgumentException("Missing required argument: -" + argname);
        }
        return first.get().substring(argname.length() + 2);
    }
}
