<p>If you are writing a program that is executable from the command line, you often want to offer the user several options or flags, along with possibly more than one argument. I have stumbled my way through this many times, but is there some sort of design pattern for looping through args and calling the appropriate handler functions?</p>

<p>Consider:</p>

<pre><code>myprogram -f filename -d directory -r regex
</code></pre>

<p>How do you organize the handler functions after you retrieve the arguments using whatever built-ins for your language? (language-specific answers welcomed, if that helps you articulate an answer)</p>

I don't know of any documented "patterns" for processing.
I believe one of the oldest libraries/APIs for handling arguments is getopt.  Googling "getopt" shows lots of man pages and links to implementations.
Generally, I have a preferences or settings service in my application that the argument processor knows how to communicate with.  Arguments are then translated into something in this service that the application than then query.  This could be as simple as a dictionary of settings (like a string setting named "filename").