<commit_before>#!/bin/bash

# -------------------------------------------------------------------
#
# bashing.sh:
#   This Script collects all source files and builds a single
#   stand-alone Script out of them.
#   (c) 2013 <NAME> (<EMAIL>)
#
# -------------------------------------------------------------------
# USAGE
#
# bashing [<root-directory>] > <output file>
# bashing --lib-only [<root-director>] > <output file>
#
# -------------------------------------------------------------------
# DESCRIPTION
# This script expects a specific directory structure:
#
#   .
#   |- .project
#   |- src
#      |- setup.sh
#      |- shutdown.sh
#      |- cli
#         |- start.sh
#         |- stop.sh
#         |- ...
#      |- lib
#         |- <include files>
#
# It will create an executable shell script that consists of all the
# include files and offers the possiblity to let it be called using
#
#   ./<script> <cli-command> <param> ....
#
# E.g.: in our above case:
#
#   ./<script> start ...
#   ./<script> stop ...
#
# It will also contain logic to have the script installed locally or
# globally, as well as automatic help page and version printing.
#
# -------------------------------------------------------------------
# Global Data
BASHING_ROOT=$(cd "$(dirname "$0")" && pwd)
BASHING_VERSION="0.1.0-SNAPSHOT"

# Parameters
CWD=$(pwd)
PROJECT_ROOT=""
BUILD_HEADER="yes"
BUILD_METADATA="yes"
BUILD_LIBRARY="yes"
BUILD_CLI="yes"
BUILD_HELP="yes"
COMPACT_OUTPUT="no"
OUTPUT_FILE=""

# -------------------------------------------------------------------
# Tools

function print_out() {
    if [ -z "$OUTPUT_FILE" ]; then
        echo "$@";
    else
        echo "$@" >> "$OUTPUT_FILE"
    fi
}

function redirect_out() {
    local line=""
    while IFS='' read -r line; do
        print_out "$line";
    done
}

function sep() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then
        print_out -n "# ";  
        print_out "$(head -c 45 /dev/zero | tr '\0' '-')"; 
    fi
}
function comment() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then print_out "# $@"; fi; 
}

function nl() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then print_out ""; fi; 
}

function includeBashFile() {
    if [ -s "$1" ] && bash -n "$1"; then
        sed '/^\s*#.*$/d' "$1" | sed '/^\s*$/d';
    fi
}

# -------------------------------------------------------------------
# Parse Command Line
while [ $# -gt 0 ]; do
    arg="$1"
    case "$arg" in
        "--out"|"-o") shift; OUTPUT_FILE="$1";;
        "--compact") COMPACT_OUTPUT="yes";;
        "--no-lib") BUILD_LIBRARY="no";;
        "--no-cli") BUILD_CLI="no";;
        "--no-header") BUILD_HEADER="no";;
        "--") shift; export PROJECT_ROOT="$1";;
        --*)
            echo "Invalid command line argument: $arg" 1>&2
            exit 1
            ;;
        *)
            if [ -z "$PROJECT_ROOT" ]; then PROJECT_ROOT="$arg";
            else echo "Invalid command line argument: $arg" 1>&2; exit 1; fi
            ;;
    esac
    shift
done

# Check Parameters
if [ -z "$PROJECT_ROOT" ]; then 
    PROJECT_ROOT=$(pwd);
else if [ ! -d "$PROJECT_ROOT" ]; then
    echo "No such Directory: $PROJECT_ROOT" 1>&2;
    exit 1;
else
    PROJECT_ROOT=$(cd "$PROJECT_ROOT" 2> /dev/null && pwd);
fi; fi

if [ ! -z "$OUTPUT_FILE" ]; then
    OUTPUT_FILE="$(cd $(dirname "$OUTPUT_FILE") && pwd)/$(basename "$OUTPUT_FILE")"
    rm -f "$OUTPUT_FILE"
    if ! touch "$OUTPUT_FILE" 2> /dev/null; then
        echo "Cannot write to given Output File: $OUTPUT_FILE." 1>&2;
        exit 1;
    fi
fi

# Derive Paths
SRC_PATH="$PROJECT_ROOT/src"
CLI_PATH="$SRC_PATH/cli"
LIB_PATH="$SRC_PATH/lib"
CONF="$PROJECT_ROOT/bashing.meta"

# -------------------------------------------------------------------
# Read Configuration
RX_ID='[a-zA-Z_-]\+'
RX_INT='\(0\|[1-9][0-9]*\)'
RX_VERSION="$RX_INT\\.$RX_INT\\.$RX_INT\(-$RX_ID\\)\\?"
RX_ARTIFACT_STRING="^\\s*\\(\\($RX_ID\\)\\/\\)\\?\\($RX_ID\\)\\s\\+\\($RX_VERSION\\)\\s*$"<commit_msg>Another necessary Bugfix.<commit_after>#!/bin/bash

# -------------------------------------------------------------------
#
# bashing.sh:
#   This Script collects all source files and builds a single
#   stand-alone Script out of them.
#   (c) 2013 <NAME> (<EMAIL>)
#
# -------------------------------------------------------------------
# USAGE
#
# bashing [<root-directory>] > <output file>
# bashing --lib-only [<root-director>] > <output file>
#
# -------------------------------------------------------------------
# DESCRIPTION
# This script expects a specific directory structure:
#
#   .
#   |- .project
#   |- src
#      |- setup.sh
#      |- shutdown.sh
#      |- cli
#         |- start.sh
#         |- stop.sh
#         |- ...
#      |- lib
#         |- <include files>
#
# It will create an executable shell script that consists of all the
# include files and offers the possiblity to let it be called using
#
#   ./<script> <cli-command> <param> ....
#
# E.g.: in our above case:
#
#   ./<script> start ...
#   ./<script> stop ...
#
# It will also contain logic to have the script installed locally or
# globally, as well as automatic help page and version printing.
#
# -------------------------------------------------------------------
# Global Data
BASHING_ROOT=$(cd "$(dirname "$0")" && pwd)
BASHING_VERSION="0.1.0-SNAPSHOT"

# Parameters
CWD=$(pwd)
PROJECT_ROOT=""
BUILD_HEADER="yes"
BUILD_METADATA="yes"
BUILD_LIBRARY="yes"
BUILD_CLI="yes"
BUILD_HELP="yes"
COMPACT_OUTPUT="no"
OUTPUT_FILE=""

# -------------------------------------------------------------------
# Tools

function print_out() {
    if [ -z "$OUTPUT_FILE" ]; then
        echo "$@";
    else
        echo "$@" >> "$OUTPUT_FILE"
    fi
}

function redirect_out() {
    local line=""
    while IFS='' read -r line; do
        print_out "$line";
    done
}

function sep() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then
        print_out -n "# ";  
        print_out "$(head -c 45 /dev/zero | tr '\0' '-')"; 
    fi
}
function comment() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then print_out "# $@"; fi; 
}

function nl() { 
    if [[ "$COMPACT_OUTPUT" != "yes" ]]; then print_out ""; fi; 
}

function includeBashFile() {
    if [ -s "$1" ] && bash -n "$1"; then
        sed '/^\s*#.*$/d' "$1" | sed '/^\s*$/d';
    fi
}

# -------------------------------------------------------------------
# Parse Command Line
while [ $# -gt 0 ]; do
    arg="$1"
    case "$arg" in
        "--out"|"-o") shift; OUTPUT_FILE="$1";;
        "--compact") COMPACT_OUTPUT="yes";;
        "--no-lib") BUILD_LIBRARY="no";;
        "--no-cli") BUILD_CLI="no";;
        "--no-header") BUILD_HEADER="no";;
        "--") shift; export PROJECT_ROOT="$1";;
        --*)
            echo "Invalid command line argument: $arg" 1>&2
            exit 1
            ;;
        *)
            if [ -z "$PROJECT_ROOT" ]; then PROJECT_ROOT="$arg";
            else echo "Invalid command line argument: $arg" 1>&2; exit 1; fi
            ;;
    esac
    shift
done

# Check Parameters
if [ -z "$PROJECT_ROOT" ]; then 
    PROJECT_ROOT=$(pwd);
else if [ ! -d "$PROJECT_ROOT" ]; then
    echo "No such Directory: $PROJECT_ROOT" 1>&2;
    exit 1;
else
    PROJECT_ROOT=$(cd "$PROJECT_ROOT" 2> /dev/null && pwd);
fi; fi

if [ ! -z "$OUTPUT_FILE" ]; then
    OUTPUT_FILE="$(cd $(dirname "$OUTPUT_FILE") && pwd)/$(basename "$OUTPUT_FILE")"
    rm -f "$OUTPUT_FILE"
    if ! touch "$OUTPUT_FILE" 2> /dev/null; then
        echo "Cannot write to given Output File: $OUTPUT_FILE." 1>&2;
        exit 1;
    fi
fi

# Derive Paths
SRC_PATH="$PROJECT_ROOT/src"
CLI_PATH="$SRC_PATH/cli"
LIB_PATH="$SRC_PATH/lib"
CONF="$PROJECT_ROOT/bashing.project"

# -------------------------------------------------------------------
# Read Configuration
RX_ID='[a-zA-Z_-]\+'
RX_INT='\(0\|[1-9][0-9]*\)'
RX_VERSION="$RX_INT\\.$RX_INT\\.$RX_INT\(-$RX_ID\\)\\?"
RX_ARTIFACT_STRING="^\\s*\\(\\($RX_ID\\)\\/\\)\\?\\($RX_ID\\)\\s\\+\\($RX_VERSION\\)\\s*$"
{'fraction_non_alphanumeric': 0.2937618147448015, 'fraction_numerical': 0.009325771896660366, 'mean_word_length': 1.7029972752043596, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4775978', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2559, 'n_words': 643}