|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Easy Wrapper around the docconvert python package |
| 4 | +# https://pypi.org/project/docconvert/ |
| 5 | + |
| 6 | +requires() { |
| 7 | +cat <<EOF |
| 8 | +Before using, please make sure to do the following: |
| 9 | +1. Follow the contributor setup in CONTRIBUTING.md |
| 10 | +2. pip install docconvert |
| 11 | +EOF |
| 12 | +} |
| 13 | + |
| 14 | +if [ -z "$(which docconvert)" ]; then |
| 15 | + echo "ERROR: Couldn't find docconvert!" 1>&2 |
| 16 | + requires 1>&2 |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | + |
| 21 | +Usage() { |
| 22 | +cat <<EOF |
| 23 | +$0 FILE_OR_FILES ... |
| 24 | +
|
| 25 | +An easy wrapper around the Python-based docconvert utility. |
| 26 | +https://pypi.org/project/docconvert/ |
| 27 | +
|
| 28 | +EOF |
| 29 | +requires |
| 30 | +cat <<EOF |
| 31 | +
|
| 32 | +After setup, use as follows: |
| 33 | +
|
| 34 | +1. $0 arcade/name.py |
| 35 | +2. ./make.py serve |
| 36 | +3. look at the pages in browser to make sure they're good |
| 37 | +
|
| 38 | +EOF |
| 39 | +} |
| 40 | + |
| 41 | +if [ "$#" -eq 0 ] || [ "$1" == "--help" ]; then |
| 42 | + Usage |
| 43 | + exit 0 |
| 44 | +fi |
| 45 | + |
| 46 | + |
| 47 | +CONFIG_FILE="docconvert.json" |
| 48 | +ensure_have_config() { |
| 49 | +if [ -f "$CONFIG_FILE" ]; then |
| 50 | + echo "Already have config file $CONFIG_FILE" |
| 51 | + return |
| 52 | +fi |
| 53 | + |
| 54 | +echo "Writing a default config file to $CONFIG_FILE" |
| 55 | +# This is a default file which sort-of does a decent job on |
| 56 | +# current versions of docconvert. You may want use "guess" for |
| 57 | +# the input style in some cases, either via editing the json |
| 58 | +# of the -i flag. See the Usage for docconvert to learn more: |
| 59 | +# https://pypi.org/project/docconvert/ |
| 60 | +cat <<EOF > $CONFIG_FILE |
| 61 | +{ |
| 62 | + "input_style": "rest", |
| 63 | + "output_style": "google", |
| 64 | + "accepted_shebangs": [ |
| 65 | + "python" |
| 66 | + ], |
| 67 | + "output": { |
| 68 | + "first_line": true, |
| 69 | + "remove_type_backticks": "false", |
| 70 | + "use_types": false |
| 71 | + } |
| 72 | +} |
| 73 | +EOF |
| 74 | +} |
| 75 | +ensure_have_config |
| 76 | +echo "Attempting docconvert..." |
| 77 | + |
| 78 | +docconvert --config $CONFIG_FILE --in-place "$@" |
0 commit comments