Skip to content

Commit

Permalink
functioning as submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmeaton committed Feb 18, 2021
1 parent 11a0400 commit 8a2b88c
Showing 1 changed file with 114 additions and 18 deletions.
132 changes: 114 additions & 18 deletions autologs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/bin/bash

#------------------------------------------------------------------------------
# Constants

VERSION=0.1.0

# Defaults
FIRST_COMMIT=`git log --reverse | head -n 1 | cut -d " " -f2`
OLD_VER=`echo ${FIRST_COMMIT:0:7}`
NEW_VER="HEAD"
MAX_COMMITS=20
NOTES_DIR="docs/notes"
RUN_FLAG="Commits"
OUT_FILE="/dev/stdout"

#------------------------------------------------------------------------------
# Functions

Expand All @@ -18,22 +30,28 @@ AbsPath()
echo $autologs_dir
}

AUTOLOGS_DIR=`AbsPath`;

Help()
{
# Display Help
# Credits: https://opensource.com/article/19/12/help-bash-program
# Display Help
echo "Automatically create commit history, release notes, and a changelog."
echo
echo "Syntax: autologs [-h|v] OLD_VER NEW_VER MAX_COMMITS NOTES_DIR"
echo "Syntax: autologs [-h|-v|-o|--old-ver|--new-ver|--max-commits|--notes-dir|--commits|--release]"
echo
echo "Options:"
echo -e "\t-h, --help Print this Help."
echo -e "\t-v, --version Print software version and exit."
echo
echo -e "\tOLD_VER An earlier version to compare to (tag or commit hash)."
echo -e "\tNEW_VER An earlier version to compare to (tag or commit hash)."
echo -e "\tMAX_COMMITS The maximum number of commits to print."
echo -e "\t-o, --output Output file. [ default:" $OUT_FILE "]"
echo -e "\t--old-ver An earlier tag/commit hash to compare to. [ default:" $OLD_VER "]"
echo -e "\t--new-ver A newer tag/commit hash to compare to. [ default:" $NEW_VER "]"
echo -e "\t--max-commits The maximum number of commits to print. [ default:" $MAX_COMMITS "]"
echo -e "\t--notes-dir A directory containing manual notees. [ default:" $NOTES_DIR "]"
echo -e "\t--commits Print commit history."
echo -e "\t--release Print release notes."
echo -e "\t--changelog Print changelog."
echo
}

Expand All @@ -45,44 +63,122 @@ Version()

Commits()
{
# Retrieve the autologs directory
autologs_dir=`AbsPath`;
# Execute the commit history script
${autologs_dir}/"scripts/commits.sh"
${AUTOLOGS_DIR}/"scripts/commits.sh"
}

Release()
{
# Execute the release notes script
${AUTOLOGS_DIR}/"scripts/release.sh"
}

Changelog()
{
# Execute the changelog script
${AUTOLOGS_DIR}/"scripts/changelog.sh"
}


# Credits: https://medium.com/@Drew_Stokes/bash-argument-parsing-54f3b81a6a8f
PARAMS=""
while (( "$#" )); do
case "$1" in

# Help
-h|--help)
Help
exit 1
;;

# Version
-v|--version)
Version
exit 1
;;

# Old version
--old-ver)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
OLD_VER=$2
shift
else
shift
fi
;;

# New version
--new-ver)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
NEW_VER=$2
shift
else
shift
fi
;;

# Max commits
--max-commits)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
MAX_COMMITS=$2
shift
else
shift
fi
;;

# Notes Directory
--notes-dir)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
NOTES_DIR=$2
shift
else
shift
fi
;;

# Commit History
--commits)
RUN_FLAG="Commits"
shift
;;
-c|--commits)
Commits
exit 1
;;
-*|--*=) # unsupported flags

# Release Notes
--release)
RUN_FLAG="Release"
shift
;;

# Release Notes
--changelog)
RUN_FLAG="Changelog"
shift
;;

# Unsupported Flags
-*|--*=)
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
# Position Parameters
*)
PARAMS="$PARAMS $1"
shift
;;
esac
done

# set positional arguments in their proper place
eval set -- "$PARAMS"

if [[ $HELP_FLAG ]]; then
echo printing HELP
fi
echo $PARAMS
echo
echo "Creating Auto $RUN_FLAG with the following parameters."
echo -e "\tOld version: $OLD_VER"
echo -e "\tNew version: $NEW_VER"
echo -e "\tMax Commits: $MAX_COMMITS"
echo -e "\tNotes Directory: $NOTES_DIR"
echo -e "\tOutput File: $OUT_FILE"
echo -e "\tRun: $RUN_FLAG"
echo

$RUN_FLAG $OLD_VER $NEW_VER $MAX_COMMITS $NOTES_DIR

0 comments on commit 8a2b88c

Please sign in to comment.