I think you’ll find this is a feature of the getopt library, and so is part of all your favourite Gnu tools.