summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md6
-rw-r--r--temp-postgres.129
-rwxr-xr-xtemp-postgres.sh46
4 files changed, 56 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 80fecd8..2cb3874 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,9 +14,11 @@ The format is based on [Keep A Changelog][] and this project adheres to [Semanti
* Added experimental Nix flake
* Added direnv configuration
* Added changelog
+* Added minimal `--help` option
### Changed
+* Turned required arguments `dbname` and `username` into optional flags `--dbname` resp. `--username`
* Ported to Arch Linux
* Ported to FreeBSD
diff --git a/README.md b/README.md
index 3b6051f..3663571 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,11 @@ This project's original source code is hosted [here][home].
Create a temporary database "test" with superuser "alex":
- $ temp-postgres test alex
+ $ temp-postgres --dbname test --username alex
Connect to the "test" database:
- $ psql --host=localhost test alex
+ $ psql --host localhost --dbname test --username alex
See the manual page for details.
@@ -48,5 +48,5 @@ On Arch Linux you can install the dependencies using `pacman(8)`:
Alternatively you can run (or install) the experimental Nix flake.
- $ nix run git+https://git.skreutz.com/temp-postgres.git -- <dbname> <username>
+ $ nix run git+https://git.skreutz.com/temp-postgres.git -- --help
diff --git a/temp-postgres.1 b/temp-postgres.1
index caf4b78..1adb8ed 100644
--- a/temp-postgres.1
+++ b/temp-postgres.1
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2022 Stefan Kreutz <mail@skreutz.com>
+.\" Copyright (c) 2022, 2026 Stefan Kreutz <mail@skreutz.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -11,7 +11,7 @@
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-.Dd $Mdocdate: May 19 2022 $
+.Dd $Mdocdate: April 15 2026 $
.Dt TEMP-POSTGRES 1
.Os
.Sh NAME
@@ -19,28 +19,29 @@
.Nd temporary PostgreSQL server
.Sh SYNOPSIS
.Nm temp-postgres
-.Ar database
-.Ar superuser
+.Op options
.Sh DESCRIPTION
The
.Nm
utility runs the PostgreSQL server off a temporary data directory.
.Pp
-It expects exactly two arguments:
-a
-.Ar database
-name
-and a
-.Ar superuser
-name.
-You may also set the port using PGPORT, see
-.Xr postgres 1 .
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl h , -help
+Print help.
+.It Fl d , -dbname Ar dbname
+The PostgreSQL database name.
+Defaults to the name of the effective user.
+.It Fl u , -username Ar username
+The PostgreSQL user name.
+Defaults to the name of the effective user.
+.El
.Sh EXIT STATUS
.Ex -std temp-postgres
.Sh EXAMPLES
Create a temporary database "test" with superuser "alex":
.Bd -literal -offset indent
-$ temp-postgres test alex
+$ temp-postgres --dbname test --username alex
.Ed
.Pp
Connect to the "test" database:
diff --git a/temp-postgres.sh b/temp-postgres.sh
index 15e169b..6064b66 100755
--- a/temp-postgres.sh
+++ b/temp-postgres.sh
@@ -1,6 +1,6 @@
#! /bin/sh
-# Copyright (c) 2019, 2020, 2022 Stefan Kreutz <mail@skreutz.com>
+# Copyright (c) 2019, 2020, 2022, 2026 Stefan Kreutz <mail@skreutz.com>
#
# Permission to use, copy, modify, and distribute this software for any purpose
# with or without fee is hereby granted, provided that the above copyright
@@ -14,7 +14,7 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
-set -u
+set -o nounset
# Remove the temporary directory before exiting.
trap 'quit' INT
@@ -30,14 +30,40 @@ quit() {
exit "${code}"
}
-# Parse arguments.
-[ $# -eq 2 ] || {
- ( >&2 printf "temp-postgres: invalid arguments\\n" )
- printf "Usage: temp-postgres <dbname> <username>\\n"
- quit 1
-}
-dbname="$1"
-username="$2"
+dbname="$( id -un )"
+username="$( id -un )"
+
+while [ $# -gt 0 ] ; do
+ case "$1" in
+ -h|--help)
+ echo "Usage: temp-postgres [-h|--help] [-d|--dbname <dbname>] [-u|--username <username>]"
+ exit
+ ;;
+ -d|--dbname)
+ dbname="$2"
+ shift 2
+ ;;
+ -u|--username)
+ username="$2"
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ ( >&2 echo "undefined option: $1" )
+ exit 2
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+if [ $# -gt 0 ] ; then
+ ( >&2 echo "too many arguments" )
+ exit 2
+fi
# Create a temporary directory
tmpdir="$( mktemp -d )" || {
Generated by cgit. See skreutz.com for my tech blog and contact information.