Thread (1 message) 1 message, 1 author, 2016-06-15

Re: What's cooking in git.git (topics)

From: Miles Bader <hidden>
Date: 2016-06-15 22:43:46

Linus Torvalds [off-list ref] writes:
So while you can combine flags for *most* programs, you still won't 
be able to say things like

	git clean -qdx

just because that's still a shellscript, and doing any fancy argument 
parsing in shell is just painful.
Indeed... but for my personal shell scripts I like to use a construct
like the following for parsing args:

   while :; do
     case "$1" in
        ... lots of cases to handle normal args ...

       -[!-]?*)
         # split concatenated single-letter options apart
         FIRST="$1"; shift
         set -- `echo $FIRST | $SED 's/-\(.\)\(.*\)/-\1 -\2/'` "$@"
         ;;

       -*)
         # unrecognized option
         unrec_opt "$1"; exit 1;;
       *)
         # non-option
         break;
     esac
   done

I'm sure there are problems with it, but it generally seems to work
pretty reasonably for short options.

-Miles
-- 
97% of everything is grunge
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help