7 Commits

Author SHA1 Message Date
Zane Duffield
994b076174 Simply copyright and author header components when empty
Some checks failed
CI with JUnit Report / build-and-test (push) Has been cancelled
2026-01-18 12:21:50 -05:00
Zane Duffield
7aedd40945 Add .shellcheckrc to silence lints 2026-01-18 12:21:50 -05:00
Zane Duffield
4bff72f4d2 Fix misc shellcheck issues
* make clear that array expansion was not desired in one case
* change `$@` to `$*` in one case
* remove unnecessary `$` in arithmetic context
* fix quoting in complex traceback message
2026-01-18 12:21:49 -05:00
Zane Duffield
5988b10d16 Fix array expansion errors on unknown parameter names
When unexpected parameters are passed to cmdarg, the shell (bash 5.1.8)
spits out some error messages about bad array subscripts, for example

> cmdarg.sh: line 333: CMDARG_FLAGS: bad array subscript
> cmdarg.sh: line 334: CMDARG_FLAGS: bad array subscript
> cmdarg.sh: line 340: CMDARG: bad array subscript

This occurs because the array is being indexed by a null value, so to
prevent it we must guard all such uses with a check.
2026-01-18 12:21:49 -05:00
Zane Duffield
a75144bf94 Quote array expansion when appending to cmdarg_argv
Without this change, excess arguments are split and glob-expanded when
appended to the cmdarg_argv array.
2026-01-18 12:21:49 -05:00
Zane Duffield
35b6965e5d Quote variables to avoid word splitting a glob matching
In all cases here, the contents of the variables are single words and do
not contain special glob characters, so it's mostly a change for
consistency and best practice.
2026-01-18 12:21:48 -05:00
Zane Duffield
489d6d1ee8 Convert tabs to spaces
The script used mixed indentation, meaning that it only made sense to
read when the tab width was set properly (to 8). Using consistent
indentation makes the script easier to read.
2026-01-18 12:21:48 -05:00
4 changed files with 66 additions and 7 deletions

View File

@@ -5,6 +5,18 @@ endif
VERSION:=$(shell if [ -d .git ]; then bash -c '$(PREFIX)/bin/gitversion.sh | grep "^MAJOR=" | cut -d = -f 2'; else source version.sh && echo $$MAJOR ; fi)
RELEASE:=$(shell if [ -d .git ]; then bash -c '$(PREFIX)/bin/gitversion.sh | grep "^BUILD=" | cut -d = -f 2'; else source version.sh && echo $$BUILD ; fi)
DISTFILE=./dist/cmdarg-$(VERSION)-$(RELEASE).tar.gz
SPECFILE=cmdarg.spec
ifndef RHEL_VERSION
RHEL_VERSION=5
endif
ifeq ($(RHEL_VERSION),5)
MOCKFLAGS=--define "_source_filedigest_algorithm md5" --define "_binary_filedigest_algorithm md5"
endif
RHEL_RELEASE:=$(RELEASE).el$(RHEL_VERSION)
SRPM=cmdarg-$(VERSION)-$(RHEL_RELEASE).src.rpm
RPM=cmdarg-$(VERSION)-$(RHEL_RELEASE).noarch.rpm
RHEL_DISTFILE=./dist/cmdarg-$(VERSION)-$(RHEL_RELEASE).tar.gz
ifndef PREFIX
PREFIX=''
@@ -13,7 +25,7 @@ endif
DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)')
JUNIT_DEPS=$(wildcard *.sh) $(wildcard tests/*.sh)
all: $(DISTFILE)
all: ./dist/$(RPM)
# --- PHONY targets
@@ -24,6 +36,10 @@ clean:
dist: $(DISTFILE)
srpm: ./dist/$(SRPM)
rpm: ./dist/$(RPM) ./dist/$(SRPM)
gitclean:
git clean -df
@@ -48,6 +64,19 @@ $(DISTFILE): version.sh
rsync -aWH . --exclude=.git --exclude=dist ./dist/cmdarg-$(VERSION)-$(RELEASE)/
cd dist && tar -czvf ../$@ cmdarg-$(VERSION)-$(RELEASE)
$(RHEL_DISTFILE): $(DISTFILE)
cd dist && \
cp -R cmdarg-$(VERSION)-$(RELEASE) cmdarg-$(VERSION)-$(RHEL_RELEASE) && \
tar -czvf ../$@ cmdarg-$(VERSION)-$(RHEL_RELEASE)
./dist/$(SRPM): $(RHEL_DISTFILE)
rm -fr ./dist/$(SRPM)
mock -r epel-$(RHEL_VERSION)-noarch --buildsrpm --verbose --spec $(SPECFILE) $(MOCKFLAGS) --sources ./dist/ --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
./dist/$(RPM): ./dist/$(SRPM)
rm -fr ./dist/$(RPM)
mock --verbose -r epel-$(RHEL_VERSION)-noarch ./dist/$(SRPM) --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
uninstall:
rm -f $(PREFIX)/usr/lib/cmdarg.sh

View File

@@ -1,6 +1,8 @@
cmdarg
======
[![Build Status](http://jenkins.aklabs.net/buildStatus/icon?job=cmdarg-test)](http://jenkins.aklabs.net/job/cmdarg-test/)
Requires bash >= 4.
source cmdarg.sh
@@ -12,7 +14,13 @@ Installation
From source
cp cmdarg.sh PATH_WHERE_YOU_WANT_IT
cd cmdarg
make install
From RPM
# add http://yum.aklabs.net/el/[5|6]/noarch as a yum repo for your system
yum install cmdarg
Usage
=====

View File

@@ -412,11 +412,6 @@ function cmdarg_dump
echo "${repr} => ${cmdarg_cfg[$key]}"
fi
done
echo "argv =>"
for idx in "${!cmdarg_argv[@]}"
do
echo " ${idx} => ${cmdarg_argv[$idx]}"
done
}
function cmdarg_purge

27
cmdarg.spec Normal file
View File

@@ -0,0 +1,27 @@
%define __os_install_post %{nil}
Summary: Bash Command Line Argument Parsing Library
Name: cmdarg
Version: %{version}
Release: %{release}
License: MIT
Vendor: Andrew Kesterson
Packager: Andrew Kesterson <andrew@aklabs.net>
Group: Development Tools
Provides: %{name}
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
Source: %{name}-%{version}-%{release}.tar.gz
Requires: bash
%description
%install
mkdir -p %{buildroot}/usr/src
tar -zxvf %{_sourcedir}/%{name}-%{version}-%{release}.tar.gz
cd %{name}-%{version}-%{release}
PREFIX=%{buildroot} make install
PREFIX=%{buildroot} make MANIFEST
cp MANIFEST /tmp/
%files -f /tmp/MANIFEST