Repository: microsoft/terminal
File: src/cascadia/TerminalApp/AppCommandlineArgs.cpp (C++)

Code before:
    };

    setupSubcommand(_focusPaneCommand);
    setupSubcommand(_focusPaneShort);
}

void AppCommandlineArgs::_buildSaveParser()
{
    _saveCommand = _app.add_subcommand("x-save", RS_A(L"SaveActionDesc"));

    auto setupSubcommand = [this](auto* subcommand) {
        subcommand->add_option("--name,-n", _saveInputName, RS_A(L"SaveActionArgDesc"));
        subcommand->add_option("--keychord,-k", _keyChordOption, RS_A(L"KeyChordArgDesc"));
        subcommand->add_option("command,", _commandline, RS_A(L"CmdCommandArgDesc"));
        subcommand->positionals_at_end(true);

        // When ParseCommand is called, if this subcommand was provided, this
        // callback function will be triggered on the same thread. We can be sure
        // that `this` will still be safe - this function just lets us know this
        // command was parsed.
        subcommand->callback([&, this]() {
            // Build the NewTab action from the values we've parsed on the commandline.
            ActionAndArgs saveAction{};
            saveAction.Action(ShortcutAction::SaveTask);
            // _getNewTerminalArgs MUST be called before parsing any other options,
            // as it might clear those options while finding the commandline
            SaveTaskArgs args{};

            if (!_commandline.empty())
            {
                std::ostringstream cmdlineBuffer;

                for (const auto& arg : _commandline)
                {
                    if (cmdlineBuffer.tellp() != 0)
                    {
                        // If there's already something in here, prepend a space
                        cmdlineBuffer << ' ';
                    }

                    if (arg.find(" ") != std::string::npos)
                    {
                        cmdlineBuffer << '"' << arg << '"';
                    }
                    else
                    {
                        cmdlineBuffer << arg;
                    }
                }

                args.Commandline(winrt::to_hstring(cmdlineBuffer.str()));

Review comment (suggestion):
```suggestion
            // First, parse out the commandline in the same way that
            // _getNewTerminalArgs does it
```

Code after:
    };

    setupSubcommand(_focusPaneCommand);
    setupSubcommand(_focusPaneShort);
}

void AppCommandlineArgs::_buildSaveSnippetParser()
{
    _saveCommand = _app.add_subcommand("x-save-snippet", RS_A(L"SaveSnippetDesc"));

    auto setupSubcommand = [this](auto* subcommand) {
        subcommand->add_option("--name,-n", _saveInputName, RS_A(L"SaveSnippetArgDesc"));
        subcommand->add_option("--keychord,-k", _keyChordOption, RS_A(L"KeyChordArgDesc"));
        subcommand->add_option("command,", _commandline, RS_A(L"CmdCommandArgDesc"));
        subcommand->positionals_at_end(true);

        // When ParseCommand is called, if this subcommand was provided, this
        // callback function will be triggered on the same thread. We can be sure
        // that `this` will still be safe - this function just lets us know this
        // command was parsed.
        subcommand->callback([&, this]() {
            // Build the action from the values we've parsed on the commandline.
            ActionAndArgs saveSnippet{};
            saveSnippet.Action(ShortcutAction::SaveSnippet);
            // First, parse out the commandline in the same way that
            // _getNewTerminalArgs does it
            SaveSnippetArgs args{};

            if (!_commandline.empty())
            {
                std::ostringstream cmdlineBuffer;

                for (const auto& arg : _commandline)
                {
                    if (cmdlineBuffer.tellp() != 0)
                    {
                        // If there's already something in here, prepend a space
                        cmdlineBuffer << ' ';
                    }

                    if (arg.find(" ") != std::string::npos)
                    {
                        cmdlineBuffer << '"' << arg << '"';
                    }
                    else
                    {
                        cmdlineBuffer << arg;
                    }
                }

                args.Commandline(winrt::to_hstring(cmdlineBuffer.str()));