Repository: microsoft/terminal
File: src/host/ConsoleArguments.cpp (C++)

Code before:
        }
        else if (arg == HEADLESS_ARG)
        {
            _headless = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == INHERIT_CURSOR_ARG)
        {
            _inheritCursor = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == RESIZE_QUIRK)
        {
            _resizeQuirk = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (std::regex_match(arg, std::wregex(L"--[A-Za-z0-9]+")))
        {
            // Any other alphanumeric sequence starting with -- is likely
            // an unrecognized argument that we need to ignore.
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == CLIENT_COMMANDLINE_ARG)
        {
            // Everything after this is the explicit commandline
            hr = _GetClientCommandline(args, i, true);
            break;
        }
        // TODO: handle the rest of the possible params (MSFT:13271366, MSFT:13631640)
        else
        {
            // If we encounter something that doesn't match one of our other
            //      args, then it's the start of the commandline
            hr = _GetClientCommandline(args, i, false);
            break;
        }

        if (FAILED(hr))
        {
            break;
        }
    }

    // We should have consumed every token at this point.
    // if not, it is some sort of parsing error.
    // If we failed to parse an arg, then no need to assert.
    if (SUCCEEDED(hr))

Review comment (suggestion):
I'm not sure if you'll be happy with using a regex here, if that's going to add bloat to conhost. It looks to me like we're already using regex searches in the `TextBuffer`, but I'm not sure if that actually gets linked into conhost.

Worst case, we could make this only ignore the defunct `--win32input` option, but I thought it would be nice to have it dropping all the unsupported args, since there was already a TODO for that a few lines down from here.

Code after:
        }
        else if (arg == HEADLESS_ARG)
        {
            _headless = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == INHERIT_CURSOR_ARG)
        {
            _inheritCursor = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == RESIZE_QUIRK)
        {
            _resizeQuirk = true;
            s_ConsumeArg(args, i);
            hr = S_OK;
        }
        else if (arg == CLIENT_COMMANDLINE_ARG)
        {
            // Everything after this is the explicit commandline
            hr = _GetClientCommandline(args, i, true);
            break;
        }
        // TODO: handle the rest of the possible params (MSFT:13271366, MSFT:13631640)
        // TODO: handle invalid args
        //  e.g. "conhost --foo bar" should not make the clientCommandline "--foo bar"
        else
        {
            // If we encounter something that doesn't match one of our other
            //      args, then it's the start of the commandline
            hr = _GetClientCommandline(args, i, false);
            break;
        }

        if (FAILED(hr))
        {
            break;
        }
    }

    // We should have consumed every token at this point.
    // if not, it is some sort of parsing error.
    // If we failed to parse an arg, then no need to assert.
    if (SUCCEEDED(hr))
    {
        FAIL_FAST_IF(!args.empty());
    }

    return hr;