summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--man/1/envstore9
-rw-r--r--src/envstore.c35
3 files changed, 46 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 7ae094f..c50e596 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,14 @@
CFLAGS ?= -O2
PREFIX ?= /usr/local
+VERSION ?= 2.0.4-git
+
CFLAGS += -Wall -Wextra -pedantic
sysdir = ${DESTDIR}${PREFIX}
-all: bin/envstore
-
-bin/%: src/%.c
- ${CC} ${CFLAGS} ${LDFLAGS} -o $@ $<
+bin/envstore: src/envstore.c
+ ${CC} -DVERSION=\"${VERSION}\" ${CFLAGS} ${LDFLAGS} -o $@ $<
install: bin/envstore
@echo installing:
diff --git a/man/1/envstore b/man/1/envstore
index 7e65bce..c9a1988 100644
--- a/man/1/envstore
+++ b/man/1/envstore
@@ -29,7 +29,8 @@ either with its current shell value or with
.Ar value
.It Cm rm Ar variable
Remove
-.Ar variable from store
+.Ar variable
+from store
.El
.Pp
Note: Only the first character of
@@ -46,6 +47,12 @@ for
.Nm
.Cm clear ,
etc., are also valid.
+.Pp
+For convenience, the options
+.Cm --version
+and
+.Cm --help
+are also supported.
.Sh ENVIRONMENT
.Bl -tag -width "ENVSTORE_FILE"
.It Ev ENVSTORE_FILE
diff --git a/src/envstore.c b/src/envstore.c
index d7ea263..a65f653 100644
--- a/src/envstore.c
+++ b/src/envstore.c
@@ -171,6 +171,34 @@ static inline void command_clear(char *store_file) {
}
+static inline void print_usage() {
+ puts(
+ "Usage: envstore <command> [arguments]\n\n"
+ "Commands:\n"
+ "clear\n"
+ "\tForget all stored variables\n\n"
+ "eval\n"
+ "\tProduce shell code for evaluation to restore saved variables\n\n"
+ "list\n"
+ "\tList saved variables in a better readable format\n\n"
+ "save <variable> [value]\n"
+ "\tSave <variable> either with its current shell value or with [value]\n\n"
+ "rm <variable>\n"
+ "\tRemove <variable> from store\n\n"
+ "Commands may be abbreviated as their first character\n\n"
+ "Environment:\n"
+ "ENVSTORE_FILE - store file. Default: /tmp/envstore-EUID\n\n"
+ "Limitations:\n"
+ "Newlines are not supported.\n"
+ "Maximum lengths: 255 bytes for each <variable>, 1023 for its content.\n"
+ );
+}
+
+static inline void print_version() {
+ puts("envstore version " VERSION);
+}
+
+
int main(int argc, char **argv) {
char *store_file;
uid_t my_uid = geteuid();
@@ -211,7 +239,12 @@ int main(int argc, char **argv) {
command_rm_save(store_file, argv[2], argv[3], argc, CMD_SAVE);
break;
default:
- errx(EXIT_FAILURE, "Unknown action: %s", argv[1]);
+ if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))
+ print_usage();
+ else if (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))
+ print_version();
+ else
+ errx(EXIT_FAILURE, "Unknown action: %s", argv[1]);
break;
}