If I understand correctly, that is not possible in the official mysql command.
But does mycli perhaps have that feature (given that mycli implements many shell-related extensions such as $| and $>)?
What I want is like this though I'm not particular about the actual syntax:
-- The command is executed in shell and its stdout is captured/returned.
-- The entire statement is aborted when the command exits with non-zero status.
SET @my_id = CAPTURE_OUTPUT("my_id_generator --short");
INSERT INTO user (id) VALUES (@my_id);