sort flags with the same name in a consistent order

Closes #5860