support old getopt if gnu getopt unavailable. better osx support

This commit is contained in:
James Tomasino 2018-03-06 10:03:48 -05:00
parent e454e54c12
commit 4c60852713
2 changed files with 15 additions and 9 deletions

View File

@ -9,14 +9,12 @@ endif
HAS_BREW := $(shell command -v brew 2> /dev/null) HAS_BREW := $(shell command -v brew 2> /dev/null)
ifdef HAS_BREW ifdef HAS_BREW
ifneq ($(wildcard $$(brew --prefix)/etc/bash_completion.d/),)
CPLDIR ?= $$(brew --prefix)/etc/bash_completion.d CPLDIR ?= $$(brew --prefix)/etc/bash_completion.d
endif endif
endif
HAS_PKGCONFIG := $(shell command -v pkg-config 2> /dev/null) HAS_PKGCONFIG := $(shell command -v pkg-config 2> /dev/null)
ifdef HAS_PKGCONFIG ifdef HAS_PKGCONFIG
CPLDIR ?= $$(pkg-config --variable=completionsdir bash-completion) CPLDIR ?= $$(pkg-config --variable=completionsdir bash-completion 2> /dev/null)
endif endif
install: install:
@ -30,6 +28,7 @@ install:
@chmod 644 $(MANDIR)/man1/burrow.1 @chmod 644 $(MANDIR)/man1/burrow.1
ifdef CPLDIR ifdef CPLDIR
@echo Installing the command completion to $(CPLDIR) @echo Installing the command completion to $(CPLDIR)
@mkdir -p $(CPLDIR)
@cp -f burrow.d $(CPLDIR)/burrow @cp -f burrow.d $(CPLDIR)/burrow
@chmod 644 $(CPLDIR)/burrow @chmod 644 $(CPLDIR)/burrow
endif endif
@ -40,7 +39,6 @@ uninstall:
@echo Removing the manual page from $(MANDIR)/man1 @echo Removing the manual page from $(MANDIR)/man1
@rm -f $(BINDIR)/man1/burrow.1 @rm -f $(BINDIR)/man1/burrow.1
ifdef CPLDIR ifdef CPLDIR
@echo Installing the command completion to $(CPLDIR)
@echo Removing the command completion from $(CPLDIR) @echo Removing the command completion from $(CPLDIR)
@rm -f $(CPLDIR)/burrow @rm -f $(CPLDIR)/burrow
endif endif

18
burrow
View File

@ -71,11 +71,19 @@ END
} }
function parse_input { function parse_input {
parsed=$(getopt \ getopt -T > /dev/null
--options=$arg_options \ if [ $? -eq 4 ]; then
--longoptions=$arg_longoptions \ # GNU enhanced getopt is available
--name "$0" \ parsed=$(getopt \
-- "$@") --options=$arg_options \
--longoptions=$arg_longoptions \
--name "$0" \
-- "$@")
else
# Original getopt is available
parsed=$(getopt $arg_options "$@")
fi
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
die "Invalid input" 2 die "Invalid input" 2
fi fi