Optimage already offers CLI, see here:
/Applications/Optimage.app/Contents/MacOS/
├── Optimage
└── cli
├── gifsicle
├── gs
├── icnsutil
├── icotool
├── node
├── optimage
└── svgo
$ /Applications/Optimage.app/Contents/MacOS/cli/optimage --help
Optimage, image optimization command line tool.
Supported formats: PNG, JPEG.
Usage: optimage [options] file ...
Options:
-h, --help display this usage information
-V, --version display the version number
-v, --verbose run in verbose mode
--lossy perform lossy optimizations
--srgb convert to sRGB
--strip-icc strip ICC profile
--strip-meta [meta] strip metadata, e.g. EXIF, XMP, tEXt, iTXt, zTXt, comments, etc
-d, --dest [path] save output files to directory
--prefix [prefix] add prefix to output filenames, may also contain directory path
--suffix [suffix] add suffix to output filenames, default is -opt
-f, --force overwrite existing output files