But the environment variable [NEEDRESTART_MODE](https://github.com/liske/needrestart/commit/6269672b99ea0f58453ae125dfe11e9e5e174156) allows to specify a mode. And by choosing "(a)utomatically", you can benefit from needrestart without being blocked by the prompt:
sudo NEEDRESTART_MODE=a apt-get dist-upgrade --yes
The following environment variables can be used to override the config file options.
Command line parameters do always supersede them.
NEEDRESTART_MODE
Change the configured restart mode (see also the -r parameter): (l)ist only,
(i)nteractive or (a)utomatically
https://manpages.ubuntu.com/manpages/jammy/man1/needrestart.1.html
https://manpages.ubuntu.com/manpages/jammy/man1/needrestart.1.html