109 lines
2.3 KiB
Bash
Executable File
109 lines
2.3 KiB
Bash
Executable File
#! /usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
d2_args=( )
|
|
d2_input_file=
|
|
|
|
function print_help() {
|
|
cat <<EOF
|
|
Usage:
|
|
wd2 [--watch] [FLAGS...] file.d2 [file.svg | file.png]
|
|
|
|
A wrapper over d2 which allows to use cli/env configuratios as additional
|
|
specific attributes from d2 file. All these attributes will be passed to the d2
|
|
cli and overwrite cli parameters with the same name.
|
|
|
|
# Supported configurations
|
|
|
|
- port
|
|
- layout
|
|
- theme
|
|
- dark-theme
|
|
- pad
|
|
- sketch
|
|
- force-appendix
|
|
- center
|
|
- animated-interval
|
|
- font-regular
|
|
- font-italic
|
|
- font-bold
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
$(d2 --help | tail -n +6 - | sed -e 's/d2 \(layout\|fmt\)/wd2 \1/')
|
|
EOF
|
|
}
|
|
|
|
|
|
function parse_args() {
|
|
if [ "$#" == "0" ]; then
|
|
print_help
|
|
exit 1
|
|
fi
|
|
|
|
while (( "$#" )); do
|
|
case "$1" in
|
|
--help)
|
|
print_help
|
|
exit 0
|
|
;;
|
|
# extract input file arg
|
|
*.d2)
|
|
d2_input_file="$1"
|
|
d2_args+=( "$1" )
|
|
;;
|
|
# other args
|
|
*)
|
|
d2_args+=( "$1" )
|
|
;;
|
|
esac
|
|
|
|
shift
|
|
done
|
|
}
|
|
|
|
function get_attr_value() {
|
|
grep "^#" "$d2_input_file" \
|
|
| grep "$1" \
|
|
| awk -F"$1: " '{ print $2 }' \
|
|
| cut -d';' -f1
|
|
}
|
|
|
|
parse_args "$@"
|
|
|
|
if [ -z "$d2_input_file" ]; then
|
|
print_help
|
|
exit 1
|
|
fi
|
|
|
|
set +e
|
|
d2_layout=$(get_attr_value "layout")
|
|
d2_theme=$(get_attr_value "theme")
|
|
d2_dark_theme=$(get_attr_value "dark-theme")
|
|
d2_pad=$(get_attr_value "pad")
|
|
d2_sketch=$(get_attr_value "sketch")
|
|
d2_port=$(get_attr_value "port")
|
|
d2_force_appendix=$(get_attr_value "force-appendix")
|
|
d2_center=$(get_attr_value "center")
|
|
d2_animated_interval=$(get_attr_value "animated-interval")
|
|
d2_font_regular=$(get_attr_value "font-regular")
|
|
d2_font_italic=$(get_attr_value "font-italic")
|
|
d2_font_bold=$(get_attr_value "font-bold")
|
|
set -e
|
|
|
|
d2 "${d2_args[@]}" \
|
|
${d2_layout:+--layout=${d2_layout}} \
|
|
${d2_theme:+--theme=${d2_theme}} \
|
|
${d2_dark_theme:+--dark-theme=${d2_dark_theme}} \
|
|
${d2_pad:+--pad=${d2_pad}} \
|
|
${d2_sketch:+--sketch=${d2_sketch}} \
|
|
${d2_port:+--port=${d2_port}} \
|
|
${d2_force_appendix:+--force-appendix=${d2_force_appendix}}
|
|
${d2_center:+--center=${d2_center}} \
|
|
${d2_animated_interval:+--animated-interval=${d2_animated_interval}} \
|
|
${d2_font_regular:+--font-regular=${d2_font_regular}} \
|
|
${d2_font_italic:+--font-italic=${d2_font_italic}} \
|
|
${d2_font_bold:+--font-bold=${d2_font_bold}}
|
|
|