# -*-Shell-script-*- # # Copyright (C) 2015-2020 SUSE Software Solutions Germany GmbH # # Author: # Frank Sundermeyer # ########################################################################### # # XMLformat # # Prettyfies the XML sources # ########################################################################### function xmlformat { local _BINARY DAPSXMLFORMAT SHORT_OPTS LONG_OPTS SUB_CMD XMLFORMAT_CMD local _XMLFORMAT_FLAGS SUB_CMD=$1 shift SHORT_OPTS="h" LONG_OPTS="file:,help,rootid:" parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" eval set -- "$P_REMAIN_ARGS" # check whether xmlformat is installed: for _BINARY in xmlformat xmlformat.pl xmlformat.rb; do XMLFORMAT_CMD="$(which --skip-alias --skip-functions "$_BINARY" 2>/dev/null)" && break done if [[ -z $XMLFORMAT_CMD ]]; then ccecho "error" "Error: xmlformat is not installed" exit 1 fi #------ Computing the values returned from the parser ----- if [[ 1 -eq $P_HELP ]]; then help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" help_file help_help help_rootid echo -e " NOTES: * Options --file and --rootid exclude one another.\n * If neither file nor rootid is specified, the rootid\n from the DC-file is used\n * $SUB_CMD follows xi:includes\n * MAIN is ignored when --file or when a ROOTID is specified\n * This command will directly alter your source xml files!" exit 0 fi if [[ -z "$P_ROOTID" && -z "$P_FILE" ]]; then if [[ 0 -ne $VERBOSITY ]]; then ccecho "info" "Neither file nor rootid specified, using rootid from DC-file" fi elif [[ -n "$P_ROOTID" && -n "$P_FILE" ]]; then exit_on_error "Options --file (-f) and --rootid exclude one another.\nPlease specify only one of these options" fi # define which dpas-xmlformat to use # if [[ -n "$DAPSROOT" && "$DAPSROOT" != "$DAPSROOT_DEFAULT" ]]; then # use daps-xmlformat from DAPSROOT if the latter is set DAPSXMLFORMAT="${DAPSROOT}/bin/daps-xmlformat" else DAPSXMLFORMAT="$(which --skip-alias --skip-functions daps-xmlformat 2>/dev/null)" || exit_on_error "Cannot find a daps-xmlformat executable" fi # if --file was specified, FILELIST contains just one file # if --rootid was specified, we need to get the list of files if [[ -n "$P_FILE" ]]; then FILELIST[0]="$P_FILE" else [[ -n "$P_ROOTID" ]] && export ROOTID="$P_ROOTID" FILELIST=( $(call_make list-srcfiles silent LIST_NODC=1 LIST_NOENT=1 LIST_NOIMG=1 ) ) if [[ 0 -ne $? ]]; then exit_on_error "Failed to get filelist for ROOTID \"$ROOTID\"" fi fi # Be more verbose in debug or -vv mode # if [[ 1 -eq $DEBUG || 2 -le "$VERBOSITY" ]]; then _XMLFORMAT_FLAGS="-i -v" else _XMLFORMAT_FLAGS="-i" fi # run daps-xmlformat # # ignore $MAIN with --file or --rootid # [[ 0 -ne $VERBOSITY ]] && echo "Prettifying the following files:" for FILE in "${FILELIST[@]}"; do if [[ -n "$P_FILE" || -n "$ROOTID" ]]; then [[ "$FILE" = "$MAIN" ]] && continue fi [[ 0 -ne $VERBOSITY ]] && echo -e " $FILE" $DAPSXMLFORMAT $_XMLFORMAT_FLAGS "$FILE" >/dev/null done }