Skip to content

Commit

Permalink
Defined help command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Nov 29, 2018
1 parent 8a2cd77 commit f23c1ca
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ install: all
install --verbose --compare --mode 644 share/sake.d/*.* $(datadir)/$(PROJECT)/sake.d
install --verbose --compare --mode 644 share/milligram/*.* $(datadir)/$(PROJECT)/milligram
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/jqt
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/sake
sed -i -e "s#JQTLIB='.*'#JQTLIB='$(datadir)/jqt'#" $(bindir)/sake

uninstall:
rm --verbose --force -- $(addprefix $(prefix)/,$(wildcard bin/*))
Expand Down
1 change: 0 additions & 1 deletion bin/jqt
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ function usage
function help
{
cat <<'EOF'
jqt - jq based web template engine [version 0.5.1]
Usage: jqt [-h | --help | -p | -V | --version]
jqt [options] < infile > result
jqt [options] infile > result
Expand Down
100 changes: 59 additions & 41 deletions bin/sake
Original file line number Diff line number Diff line change
@@ -1,83 +1,101 @@
#!/bin/bash

#
# Wraps make
# Wraps GNU Make
#

# Environment
declare -ri NCORES=${NCORES:-2}
########################################################################
# Bash options
########################################################################

# Options
set -o errexit -o noglob -o nounset -o pipefail

shopt -s expand_aliases

# Script name
declare -r SELF=${0##*/}
########################################################################
# Environment
########################################################################

# Imported from environment if defined; otherwise use default value
declare -ri NCORES=${NCORES:-2}

# Exported to use in makefiles and Sakefile
declare -xr JQTLIB='/usr/local/share/jqt'

# GMake call
declare -ra makeflags=(
--jobs=$(( NCORES * 150 / 100 )) # NCORES * 1.5
--makefile=Sakefile
--output-sync=target
)
alias _sake='exec make "${makeflags[@]}"'

########################################################################
# Check project on current directory
########################################################################

# Sakefile must exist
if test ! -e Sakefile; then
echo 1>&2 "${SELF}: no \`Sakefile\` found."
echo 1>&2 "sake: no \`Sakefile\` found."
exit 1
fi

# Configuration file must exist
if test ! -e config.yaml && test ! -e config.json; then
echo 1>&2 "${SELF}: no \`config.yaml\` or \`config.json\` file found."
echo 1>&2 "sake: no \`config.yaml\` or \`config.json\` file found."
exit 1
fi

# Check arguments
########################################################################
# Run
########################################################################

# Options to gmake
declare -ra makeflags=(
--jobs=$(( NCORES * 150 / 100 )) # NCORES * 1.5
--makefile=Sakefile
--output-sync=target
)

# Exec gmake
alias _sake='exec make "${makeflags[@]}"'

# Default command: `build`
[[ $# == 0 ]] && set -- build

# Run _sake
case $1 in
help)
echo 'Usage: sake [command] [[options] [variable=definition] ...]'
echo -e '\nCommands, builtin and user defined:\n'
;& # fall through
list)
make -f Sakefile -np 2>&1 |
grep -v '^[SmM]akefile' |
awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' |
sort --unique |
sed 's/:\+$//' |
pr --omit-pagination --width=50 --columns=4 --across
[[ $1 == help ]] && {
echo -e '\nSee the manpage for full documentation.'
}
;;
clober)
shift
_sake clobber "$@"
;;
config)
shift
_sake configure "$@"
;;
dag)
make -f Sakefile -Bdn \
make -f Sakefile -Bdn build \
| sed -n \
-e "s/'//g" \
-e 's/\.$//' \
-e 's/Considering target file //p'
;;
help)
echo 1>&2 "${SELF}: Target \`help\` not implemented."
exit 1
;;
new)
echo 1>&2 "${SELF}: Target \`new\` not implemented."
echo 1>&2 "sake: Target \`new\` not implemented."
exit 1
;;
list)
echo 'Usage: sake [goal] [[options] [variable=string] ...]'
echo 'Goals:'
make -f Sakefile -dpq 2>&1 \
| grep -v '^[SmM]akefile' \
| awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' \
| sort --unique \
| sed 's/:\+$//' \
| pr --omit-pagination --width=80 --columns=6
;;
touch)
if test -e config.yaml; then touch config.yaml; else touch config.json; fi
shift
_sake build "$@"
;;
config)
shift
_sake configure "$@"
;;
clober)
shift
_sake clobber "$@"
;;
*)
_sake "$@"
;;
Expand Down
5 changes: 2 additions & 3 deletions bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ if [[ -f VERSION ]]; then
cp /tmp/$$-changes CHANGES
rm /tmp/$$-changes
git add CHANGES VERSION
sed -i "s/^declare -r VERSION=$/declare -r VERSION=${NEXT_VERSION}'/" bin/jqt
sed -i "s/\[version .*\]/[version ${NEXT_VERSION}]/" bin/jqt
sed -i "s/^version: *.*/version: ${NEXT_VERSION}/" docs/config.yaml
sed -i "s/^declare -r VERSION=.*$/declare -r VERSION='${NEXT_VERSION}'/" bin/jqt
sed -i "s/^version: *.*/version: ${NEXT_VERSION}/" docs/config.yaml
git commit -am "Version bump to ${NEXT_VERSION}"
git tag -a -m "Tagging version ${NEXT_VERSION}" "v${NEXT_VERSION}"
[[ $PUSH == yes ]] && git push origin --tags
Expand Down
10 changes: 4 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ makefile must contain the following include:

## Current _Sake_ commands

Targets not defined now: `help`, `new`.

```
Targets:
build configure help new
clean h5.lint list touch
clobber h5.valid
Usage: sake [command] [[options] [variable=definition] ...]
Commands:
build clobber dag h5.lint help new
clean configure depend h5.valid list nuke
```

## Autocompletion
Expand Down
6 changes: 2 additions & 4 deletions docs/Sakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ JQTFLAGS += -5 --toc-depth=4
# experimental
########################################################################

print-%: ; @echo $* = $($*)

depend: $(Meta)/phase3d.make
cat $< | egrep -v '^#|^$$' | cut -c -72 - | sed 's/$$/.../'

# TODO: new, help, man page, SITE section on web, taxonomies (flags, series...)
# TODO: new, man page, SITE section on web, taxonomies (flags, series...)
# TODO: enhance `dag` command
# TODO: -t -W -B
# TODO: -t -W -B ???

# TODO: show content pending to render?
#newer: $(Meta)/lastbuild
Expand Down
2 changes: 1 addition & 1 deletion share/sake.d/main.make
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ __build := 1
# Standard targets.
########################################################################

sake_builtin := new help touch list dag
sake_builtin := new help list dag touch
.PHONY: build clean clobber nuke configure $(sake_builtin)

# Filter builtin tools defined in `sake`script.
Expand Down
8 changes: 8 additions & 0 deletions share/sake.d/tools.make
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
# VNU
# Root
# Defined targets:
# print-%
# h5.lint
# h5.valid

########################################################################
# Debug utilities.
########################################################################

# Print any variable value
print-%: ; @echo $* = $($*)

########################################################################
# HTML 5 validation.
########################################################################
Expand Down

0 comments on commit f23c1ca

Please sign in to comment.