diff --git a/Makefile b/Makefile index 4b26eec..a821941 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,9 @@ VERSION=0.1.0 DIRS=bin INSTALL_DIRS=`find $(DIRS) -type d 2>/dev/null` INSTALL_FILES=`find $(DIRS) -type f 2>/dev/null` -DOC_FILES=*.md *.txt +DOC_FILES=*.md +MAN_DIRS=man/man1 +MAN_FILES=`find $(MAN_DIRS) -type f 2>/dev/null` PKG_DIR=pkg PKG_NAME=$(NAME)-$(VERSION) @@ -12,7 +14,8 @@ PKG=$(PKG_DIR)/$(PKG_NAME).tar.gz SIG=$(PKG_DIR)/$(PKG_NAME).asc PREFIX?=$(HOME)/.local -DOC_DIR=$(PREFIX)/share/doc/$(PKG_NAME) +INSTALL_DOC_DIR=$(PREFIX)/share/doc/$(PKG_NAME) +INSTALL_MAN_DIR=$(PREFIX)/share/man pkg: mkdir -p $(PKG_DIR) @@ -22,6 +25,10 @@ $(PKG): pkg build: $(PKG) +man: + for dir in $(MAN_DIRS); do mkdir -p $$dir; done + for file in $(INSTALL_FILES); do help2man --no-info --no-discard-stderr $$file | nroff -man > $(MAN_DIRS)/$$(basename $$file).1; done + $(SIG): $(PKG) gpg --sign --detach-sign --armor $(PKG) @@ -30,7 +37,7 @@ sign: $(SIG) clean: rm -f $(PKG) $(SIG) -all: $(PKG) $(SIG) +all: man $(PKG) $(SIG) test: @@ -38,16 +45,20 @@ tag: git tag v$(VERSION) git push --tags -release: $(PKG) $(SIG) tag +release: man $(PKG) $(SIG) tag install: for dir in $(INSTALL_DIRS); do mkdir -p $(PREFIX)/$$dir; done for file in $(INSTALL_FILES); do cp $$file $(PREFIX)/$$file; done - mkdir -p $(DOC_DIR) - cp -r $(DOC_FILES) $(DOC_DIR)/ + mkdir -p $(INSTALL_DOC_DIR) + cp -r $(DOC_FILES) $(INSTALL_DOC_DIR)/ + mkdir -p $(INSTALL_MAN_DIR) + cp -r $(MAN_FILES) $(INSTALL_MAN_DIR)/ + for dir in $(MAN_DIRS); do cp -r $$dir $(INSTALL_MAN_DIR)/$$(basename $$dir); done uninstall: for file in $(INSTALL_FILES); do rm -rf $(PREFIX)/$$file; done - rm -rf $(DOC_DIR) + rm -rf $(INSTALL_DOC_DIR) + for dir in $(MAN_DIRS); do rm -rf $(INSTALL_MAN_DIR)/$$(basename $$dir); done -.PHONY: build sign clean test tag release install uninstall all +.PHONY: build sign clean test man tag release install uninstall all diff --git a/README.md b/README.md index b9dea24..d06ee81 100644 --- a/README.md +++ b/README.md @@ -4,46 +4,85 @@ Home for Collateral Engineering Services utility shell scripts. ## Installation +### From Source + +Clone this repo and then run: + +```bash +make +make install +``` + +Commands and documentation will be placed into `$HOME/.local` by default. + +Make sure you have `$HOME/.local/bin` in your `$PATH`. + +If you want to change the installation location, use the `$PREFIX` env var: + +```bash +make +PREFIX=path/to/installation make install +``` + ## Commands ### `json-to-env` ``` -USAGE +JSON‐TO‐ENV(1) User Commands +JSON‐TO‐ENV(1) - json-to-env [-hx] [-f] - json-to-env [-hx] [-f] - - json-to-env [-hx] +NAME + json‐to‐env ‐ manual page for json‐to‐env 0.1.0 -DESCRIPTION +SYNOPSIS + json‐to‐env [‐hvx] [‐f] + json‐to‐env [‐hvx] [‐f] ‐ + json‐to‐env [‐hvx] - Converts a JSON file into environment variables. - Each \`key\`: \`value\` pair will be converted to a \`key=\$value\` statement. - If is not provided or is \`-\`, it will read from stdin. +DESCRIPTION + json‐to‐env ‐ Converts a JSON file into POSIX shell en‐ +vironment vari‐ + able declarations Each ‘key‘: ‘value‘ pair will be +converted to a + ‘key=value‘ statement. If is not provided or is +‘‐‘, it will + read from stdin. OPTIONS - -h, --help - Displays this help text. - -f, --file - The path to the file to read from. - -x, --export - Prepend 'export' to the generated environment variables. -``` + ‐f, ‐‐file + The path to the file to read from. -Examples: + ‐h, ‐‐help + Show this help text. -```bash -# Regular usage -json-to-env /path/to/file.json -cat /path/to/file.json | json-to-env + ‐v, ‐‐version + Show the version. + + ‐x, ‐‐export + Prepend ’export’ to the generated environment vari‐ +ables. + +EXAMPLES + json‐to‐env /path/to/file.json + Regular usage + + cat /path/to/file.json | json‐to‐env + Same as above + + json‐to‐env ‐x /path/to/file.jsoni + Export the variables (‘export VAR=VALUE‘) + + json‐to‐env ‐f /path/to/file.json + Can use the ‐f option + + json‐to‐env /path/to/file.jsoni + Or simply a positional argument -# With `export`: -json-to-env -x /path/to/file.json + json‐to‐env <<< "{"VAR":"VALUE"}" + JSON literal -# -f param is optional: -json-to-env -f /path/to/file.json # is equivalent to -json-to-env /path/to/file.json +json‐to‐env 0.1.0 March 2022 +JSON‐TO‐ENV(1) -# Don't have a file? No problem: -json-to-env <<< "{"VAR":"VALUE"}" # outputs VAR=VALUE ``` diff --git a/bin/json-to-env b/bin/json-to-env old mode 100644 new mode 100755 index e858ebf..a541aea --- a/bin/json-to-env +++ b/bin/json-to-env @@ -1,27 +1,37 @@ #!/usr/bin/env bash +NAME="$(basename $0)" + +version() { + echo '0.1.0' +} + usage() { - cat >&2 << EOF -USAGE + cat << EOF +$NAME - Converts a JSON file into POSIX shell environment variable declarations +Each \`key\`: \`value\` pair will be converted to a \`key=value\` statement. +If is not provided or is \`-\`, it will read from stdin. - $0 [-x] [-f] - $0 [-x] [-f] - - $0 [-x] +Usage: $NAME [-hvx] [-f] + or: $NAME [-hvx] [-f] - + or: $NAME [-hvx] -DESCRIPTION +Options: + -f, --file The path to the file to read from. + -h, --help Show this help text. + -v, --version Show the version. + -x, --export Prepend 'export' to the generated environment variables. - Converts a JSON file into environment variables. - Each \`key\`: \`value\` pair will be converted to a \`key=\$value\` statement. - If is not provided or is \`-\`, it will read from stdin. +Examples: + $NAME /path/to/file.json Regular usage + cat /path/to/file.json | $NAME Same as above -OPTIONS + $NAME -x /path/to/file.jsoni Export the variables (\`export VAR=VALUE\`) - -h, --help - Displays this help text. - -f, --file - The path to the file to read from. - -x, --export - Prepend 'export' to the generated environment variables. + $NAME -f /path/to/file.json Can use the -f option + $NAME /path/to/file.jsoni Or simply a positional argument + + $NAME <<< "{"VAR":"VALUE"}" JSON literal EOF } @@ -30,7 +40,7 @@ json-to-env() { local file local exports=false - options=$(getopt -o hxf: -l help,export,file: --name "$0" -- "$@") + options=$(getopt -o f:hxv -l file:,help,export,version --name "$NAME" -- "$@") eval set -- "$options" while true; do @@ -39,6 +49,10 @@ json-to-env() { usage exit 0 ;; + -v|--version) + version + exit 0 + ;; -x|--export) exports=true ;; diff --git a/man/man1/json-to-env.1 b/man/man1/json-to-env.1 new file mode 100644 index 0000000..ca35d00 --- /dev/null +++ b/man/man1/json-to-env.1 @@ -0,0 +1,53 @@ +JSON-TO-ENV(1) User Commands JSON-TO-ENV(1) + + + +NNAAMMEE + json-to-env - manual page for json-to-env 0.1.0 + +SSYYNNOOPPSSIISS + jjssoonn--ttoo--eennvv [_-_h_v_x] [_-_f] _<_f_i_l_e_> + jjssoonn--ttoo--eennvv [_-_h_v_x] [_-_f] _- + jjssoonn--ttoo--eennvv [_-_h_v_x] + +DDEESSCCRRIIPPTTIIOONN + json-to-env - Converts a JSON file into POSIX shell environment vari‐ + able declarations Each `key`: `value` pair will be converted to a + `key=value` statement. If is not provided or is `-`, it will + read from stdin. + +OOPPTTIIOONNSS + --ff, ----ffiillee + The path to the file to read from. + + --hh, ----hheellpp + Show this help text. + + --vv, ----vveerrssiioonn + Show the version. + + --xx, ----eexxppoorrtt + Prepend 'export' to the generated environment variables. + +EEXXAAMMPPLLEESS + json-to-env /path/to/file.json + Regular usage + + cat /path/to/file.json | json-to-env + Same as above + + json-to-env -x /path/to/file.jsoni + Export the variables (`export VAR=VALUE`) + + json-to-env -f /path/to/file.json + Can use the -f option + + json-to-env /path/to/file.jsoni + Or simply a positional argument + + json-to-env <<< "{"VAR":"VALUE"}" + JSON literal + + + +json-to-env 0.1.0 March 2022 JSON-TO-ENV(1)