If the GPT needs to be extended, then the following command will just fix it, as arguments on the commandline appear to be emulating user input in some way :
parted /dev/whatever print fix
However, somewhat expectedly, issuing this command when there is nothing to fix will result in an error message with full usage text etc.
Side note: testing a grep pattern to just run the fix command when needed, I noticed that surprisingly, the output, which is on a single line, gets split to fit in 80 colums when fed into a pipe. Not sure it is really useful, but confusing for sure...
Thus ending with this hack to get the GPT back on its feet:
if parted $DISK print 2>&1 | grep -q 'Not all of the space available .* appears to be used'; then
parted $DISK print fix
fi