10 Commits

Author SHA1 Message Date
2a9cdd82fa Remove RPM spec stuff from README and Makefile, simplify install instructions
Some checks failed
CI with JUnit Report / build-and-test (push) Has been cancelled
2026-01-19 17:49:16 -05:00
7342a05822 Make cmdarg_dump print out cmdarg_argv as well
Some checks failed
CI with JUnit Report / build-and-test (push) Has been cancelled
2026-01-19 15:55:44 -05:00
cd9594264a Merge remote-tracking branch 'zaneduffield/master'
Some checks failed
CI with JUnit Report / build-and-test (push) Has been cancelled
2026-01-18 12:26:25 -05:00
Zane Duffield
94f11c6f01 Simply copyright and author header components when empty 2026-01-14 12:27:32 +11:00
Zane Duffield
66563ad58a Add .shellcheckrc to silence lints 2026-01-14 11:54:19 +11:00
Zane Duffield
9772c9378d 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-14 11:54:19 +11:00
Zane Duffield
f649a18a75 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-14 11:54:19 +11:00
Zane Duffield
1e31ed1998 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-14 11:54:19 +11:00
Zane Duffield
ad35f698ea 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-14 11:54:18 +11:00
Zane Duffield
8862ba1999 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-14 11:13:40 +11:00
4 changed files with 7 additions and 66 deletions

View File

@@ -5,18 +5,6 @@ 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) 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) 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 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 ifndef PREFIX
PREFIX='' PREFIX=''
@@ -25,7 +13,7 @@ endif
DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)') DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)')
JUNIT_DEPS=$(wildcard *.sh) $(wildcard tests/*.sh) JUNIT_DEPS=$(wildcard *.sh) $(wildcard tests/*.sh)
all: ./dist/$(RPM) all: $(DISTFILE)
# --- PHONY targets # --- PHONY targets
@@ -36,10 +24,6 @@ clean:
dist: $(DISTFILE) dist: $(DISTFILE)
srpm: ./dist/$(SRPM)
rpm: ./dist/$(RPM) ./dist/$(SRPM)
gitclean: gitclean:
git clean -df git clean -df
@@ -64,19 +48,6 @@ $(DISTFILE): version.sh
rsync -aWH . --exclude=.git --exclude=dist ./dist/cmdarg-$(VERSION)-$(RELEASE)/ rsync -aWH . --exclude=.git --exclude=dist ./dist/cmdarg-$(VERSION)-$(RELEASE)/
cd dist && tar -czvf ../$@ 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: uninstall:
rm -f $(PREFIX)/usr/lib/cmdarg.sh rm -f $(PREFIX)/usr/lib/cmdarg.sh

View File

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

View File

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

View File

@@ -1,27 +0,0 @@
%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