#!/bin/sh set -o errexit set -o nounset set -o pipefail if [[ -z "${MIXCOL_CLI}" ]]; then echo "No mixcol command defined via the environment variable MIXCOL_CLI" exit 1 fi ISTIO_BASE=$(cd "$(dirname "$0")" ; pwd -P)/.. MIXER_CLI_DIR=$(readlink -f ${ISTIO_BASE}/_docs/reference/mixercli/) WORKING_DIR=$(mktemp -d) function pageHeader() { title=${1} overview=${2} order=${3} cat < ${out} # insert an anchor and remove the last line of the file, which is a note # that its auto generated echo "" >> ${out} head -n -1 ${primaryFile} >> ${out} # this pattern matches only subcommands of ${commandName}, and not # ${commandName}'s output file itself for file in ${WORKING_DIR}/${commandName}_*.md; do fullFileName=$(basename ${file}) noext=${fullFileName%%.*} # synthesize an anchor to replace the generated links to separate pages echo "" >> ${out} head -n -1 ${file} >> ${out} done # We can't rely on ordering, so we need to iterate over the files twice to be sure # we update all links. for file in ${WORKING_DIR}/${commandName}_*.md; do fullFileName=$(basename ${file}) noext=${fullFileName%%.*} # change links to refer to anchors sed -i "s,${fullFileName},#${noext},g" ${out}; done # final pass updating the subcommand's "SEE ALSO" links to the command itself sed "s,${commandName}.md,#${commandName},g;s/SEE ALSO/See Also/g" ${out}; } # Generate markdown files with mixcol. We create a subdirectory so we can grab # all *.md files out of it without having to worry about random *.md files # added to the root of the mixer git repo. mkdir -p ${WORKING_DIR} ${MIXCOL_CLI} -o ${WORKING_DIR} # Clean up the target directory mkdir -p ${MIXER_CLI_DIR} rm -f ${MIXER_CLI_DIR}/* generateIndex > ${MIXER_CLI_DIR}/index.md processPerBinaryFiles "mixc" 1 > ${MIXER_CLI_DIR}/mixc.md processPerBinaryFiles "mixs" 2 > ${MIXER_CLI_DIR}/mixs.md rm -rfd ${WORKING_DIR}