Separated option parsing function and fixed parsing cmdArgs issue

I separated option parsing into a function to reduce lines of main. It makes easier to write tests.

I found current implementation has an issue for parsing cmdArgs. This pr contains fix for the issue. See `TestParseCmdArg`.