<commit_before>#!/bin/bash
#
# NAME
#
#   docs
#
# DESCRIPTION
#
#   generate the docs
#

# Parse the command options
[ -r $RERUN_MODULES/stubbs/commands/docs/options.sh ] && {
  source $RERUN_MODULES/stubbs/commands/docs/options.sh
}

# Read module function library
[ -r $RERUN_MODULES/stubbs/lib/functions.sh ] && {
  source $RERUN_MODULES/stubbs/lib/functions.sh
}

rerun_module_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/metadata
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_module_synopsys() {
	local module=$1
	local commands=( $(rerun_commands $RERUN_MODULES $module) )
	local list=$(printf "| %s " "${commands[@]}")
	echo "${module}: [${list:1}]"
}

rerun_command_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/commands/${3}/metadata
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_option_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/commands/${3}/$4.option
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_command_usage() {
	for opt_metadata in $RERUN_MODULES/$1/commands/${2}/*.option; do
		option=$(basename $opt_metadata)
		printf "%s %s\n" "$PAD" "$(rerun_option_summary $1 $2 ${option%*.option} )"
	done
}
rerun_command_summary() {
	declare -a summary=()
	for opt_metadata in $RERUN_MODULES/$1/commands/${2}/*.option; do
		option=$(basename $opt_metadata)
		typeset -a arr=( "$(rerun_option_summary $1 $2 ${option%*.option} )" )
		param="${arr[@]:0:1}"
		summary=( ${summary[@]} ${param%:*} )
	done
	echo ${summary[*]}
}

rerun_option_summary() {
	opt_name=$3
	opt_desc=$(rerun_option_metadata "description" $1 $2 $opt_name)
	opt_arg=$(rerun_option_metadata "arguments" $1 $2 $opt_name)
	opt_req=$(rerun_option_metadata "required" $1 $2 $opt_name)
	opt_def=$(rerun_option_metadata "default" $1 $2 $opt_name)
	# option usage summary
	opt_usage=$(printf " -%s <%s>: %s" "${opt_name}" "${opt_def}" "${opt_desc}")
	[ "true" != "${opt_req}" ] && {
		opt_usage=$(printf "[-%s <%s>]: %s" "${opt_name}" "${opt_def}" "${opt_desc}") 
	}
	printf "%s %s\n" "$PAD" "$opt_usage"
}


[ -z "$DOC" ] && DOC=$RERUN_MODULES/$NAME/${NAME}.1
#
# Document head
(
cat <<EOF
.TH $NAME 1 "$(date)" "Version 1" "Rerun User Manual" 
.SH $NAME
.PP
.SH SYNOPSIS
.PP
\f[CR] 
 ${RERUN} $(rerun_module_synopsys $NAME)
\f[]
.SH DESCRIPTION
.PP
$(rerun_module_metadata "description" $NAME)
EOF
) > $DOC || rerun_die
#
# COMMANDS section
#
echo ".SH COMMANDS" >> $DOC
for command in $(rerun_commands $RERUN_MODULES $NAME)
do
(
cat <<EOF
.SH $NAME:$command \f[]$(rerun_command_summary $NAME $command)
$(rerun_command_metadata description $NAME $command)
.PP
\f[I]Command Options\f[]
$(for option in $(rerun_options $RERUN_MODULES $NAME $command)
do
description=$(rerun_option_metadata "description" $NAME $command $option)
arguments=$(rerun_option_metadata "arguments" $NAME $command $option)
default=$(rerun_option_metadata "default" $NAME $command $option)
required=$(rerun_option_metadata "required" $NAME $command $option)
echo .TP
echo .B \\-$option \\f[]$description\\f[]
echo "required: \\f[I]${required}\\f[]"
echo "arguments: \\f[I]${arguments}\\f[]"
[ -n "$default" ] && echo "default: \\f[I]$default\\f[]"
echo .RS
echo .RE
done)
EOF
) >> $DOC || rerun_die
done || rerun_die
#
# AUTHORS section
(
cat <<EOF
.SH AUTHORS
$USER
EOF
) >> $DOC || rerun_die

echo "Generated unix manual: $DOC"<commit_msg>Finished up initial stubbs:docs command.<commit_after>#!/bin/bash
#
# NAME
#
#   docs
#
# DESCRIPTION
#
#   generate the docs
#

# Parse the command options
[ -r $RERUN_MODULES/stubbs/commands/docs/options.sh ] && {
  source $RERUN_MODULES/stubbs/commands/docs/options.sh
}

# Read module function library
[ -r $RERUN_MODULES/stubbs/lib/functions.sh ] && {
  source $RERUN_MODULES/stubbs/lib/functions.sh
}

rerun_module_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/metadata
	[ -f $metadata ] || return ; # skip weird file expansion
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_module_synopsys() {
	local module=$1
	local commands=( $(rerun_commands $RERUN_MODULES $module) )
	local list=$(printf "| %s " "${commands[@]}")
	echo "${module}: [${list:1}]"
}

rerun_command_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/commands/${3}/metadata
	[ -f $metadata ] || return ; # skip weird file expansion
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_option_metadata() {
	local FIELD=$(echo $1|tr "[:lower:]" "[:upper:]")
	local metadata=$RERUN_MODULES/$2/commands/${3}/$4.option
	[ -f $metadata ] || return ; # skip weird file expansion	
	awk -F= "/^$FIELD/ {print \$2}" $metadata
}

rerun_command_usage() {
	for opt_metadata in $RERUN_MODULES/$1/commands/${2}/*.option; do
		[ -f $opt_metadata ] || continue ; # skip weird file expansion
		option=$(basename $opt_metadata)
		printf "%s %s\n" "$PAD" "$(rerun_option_summary $1 $2 ${option%*.option} )"
	done
}
rerun_command_summary() {
	declare -a summary=()
	for opt_metadata in $RERUN_MODULES/$1/commands/${2}/*.option; do
		[ -f $opt_metadata ] || continue ; # skip weird file expansion
		option=$(basename $opt_metadata)
		typeset -a arr=( "$(rerun_option_summary $1 $2 ${option%*.option} )" )
		param="${arr[@]:0:1}"
		summary=( ${summary[@]} ${param%:*} )
	done
	echo ${summary[*]}
}

rerun_option_summary() {
	opt_name=$3
	opt_desc=$(rerun_option_metadata "description" $1 $2 $opt_name)
	opt_arg=$(rerun_option_metadata "arguments" $1 $2 $opt_name)
	opt_req=$(rerun_option_metadata "required" $1 $2 $opt_name)
	opt_def=$(rerun_option_metadata "default" $1 $2 $opt_name)
	# option usage summary
	opt_usage=$(printf " -%s <%s>: %s" "${opt_name}" "${opt_def}" "${opt_desc}")
	[ "true" != "${opt_req}" ] && {
		opt_usage=$(printf "[-%s <%s>]: %s" "${opt_name}" "${opt_def}" "${opt_desc}") 
	}
	printf "%s %s\n" "$PAD" "$opt_usage"
}


[ -z "$DOC" ] && DOC=$RERUN_MODULES/$NAME/${NAME}.1
#
# Document head
(
cat <<EOF
.TH $NAME 1 "$(date)" "Version 1" "Rerun User Manual" 
.SH NAME
$NAME \- $(rerun_module_metadata "description" $NAME)
.PP
.SH SYNOPSIS
.PP
\f[CR] 
$(basename ${RERUN}) [ARGS] $(rerun_module_synopsys $NAME) [OPTIONS]
\f[]
EOF
) > $DOC || rerun_die
#
# COMMANDS section
#
echo ".SH COMMANDS" >> $DOC
for command in $(rerun_commands $RERUN_MODULES $NAME)
do
(
cat <<EOF
.SH $NAME:$command \f[]$(rerun_command_summary $NAME $command)
$(rerun_command_metadata description $NAME $command)
.PP
\f[I]OPTIONS\f[]
$(for option in $(rerun_options $RERUN_MODULES $NAME $command)
do
description=$(rerun_option_metadata "description" $NAME $command $option)
arguments=$(rerun_option_metadata "arguments" $NAME $command $option)
default=$(rerun_option_metadata "default" $NAME $command $option)
required=$(rerun_option_metadata "required" $NAME $command $option)
echo .TP
echo .B \\-$option \\f[]$description\\f[]
echo "required: \\f[I]${required}\\f[]"
echo "arguments: \\f[I]${arguments}\\f[]"
[ -n "$default" ] && echo "default: \\f[I]$default\\f[]"
echo .RS
echo .RE
done)
EOF
) >> $DOC || rerun_die
done || rerun_die
#
# AUTHORS section
(
cat <<EOF
.SH RETURN VALUES
.PP
Successful completion: 0
.SH AUTHORS
$USER
EOF
) >> $DOC || rerun_die

echo "Generated unix manual: $DOC"
{'fraction_non_alphanumeric': 0.2016691749897387, 'fraction_numerical': 0.009987686414010124, 'mean_word_length': 5.153198653198653, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '5700773', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2821, 'n_words': 647}