Skip to content

Commit

Permalink
chore: update Makefile to generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarcelos committed Mar 17, 2022
1 parent 4ddd642 commit 92b82f1
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 52 deletions.
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ 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)
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)
Expand All @@ -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)

Expand All @@ -30,24 +37,28 @@ sign: $(SIG)
clean:
rm -f $(PKG) $(SIG)

all: $(PKG) $(SIG)
all: man $(PKG) $(SIG)

test:

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
93 changes: 66 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] <file>
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] <file>
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 <file> 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 <file> 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
```
48 changes: 31 additions & 17 deletions bin/json-to-env
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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 <file> is not provided or is \`-\`, it will read from stdin.
$0 [-x] [-f] <file>
$0 [-x] [-f] -
$0 [-x]
Usage: $NAME [-hvx] [-f] <file>
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 <file> 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
}

Expand All @@ -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
Expand All @@ -39,6 +49,10 @@ json-to-env() {
usage
exit 0
;;
-v|--version)
version
exit 0
;;
-x|--export)
exports=true
;;
Expand Down
53 changes: 53 additions & 0 deletions man/man1/json-to-env.1
Original file line number Diff line number Diff line change
@@ -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 <file> 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)

0 comments on commit 92b82f1

Please sign in to comment.