comments_docblocks_functions.bash.bak

#!/usr/bin/env bash


function core(){
    run core help
}

function core_setup_new_project(){
    run core setup
}

function core_scrawl(){
    fPath="$cli_lib_dir/vendor/taeluf/code-scrawl/bin/scrawl"
    if [[ -f  "$fPath" ]];then
        $fPath
    else
        echo "Code Scrawl was not found at '$fPath', so you'll have to run it manually. Check out https://tluf.me/code-scrawl"
    fi
}

##
#
# @arg binDir the absolute path to the bindirectory that should be added to PATH in ~/.bashrc
function core_install(){
    ## just add the current library to the .bashrc

    step "Add '$1' to PATH via ~/.bashrc" bashrc_path_append "$1"
}

##
# @arg binDir an asbolute path to add to ~/.bashrc
#
function bashrc_path_append(){
    echo "export PATH=\"$1:\$PATH\"" >> ~/.bashrc
}

##
#
# Each step is optional
#
# - Move the cli library to ~/.vendor/bash-cli and symlink to it
# - Add `vendor/` to gitignore file
# - Write the 'run' script for the new project into its `bin` dir and append the project's bin dir to PATH in ~/.bashrc
# - Write the 'install' script for the new project into its root dir
# - Create the directory structure used for a library
# - Output sample group.bash files, internal files, and help files, along with alias functions being present
#
function core_setup(){
    pwd="$(pwd)"
    prompt_yes_or_no "Setup new bash cli project at '$pwd'?" || return

    step "Move cli library to ~/.vendor/bash-cli and symlink?" sys_install_and_symlink 

    step "Add 'vendor/' to .gitignore?" add_vendor_to_git_ignore 

    step "Write 'run' script?" write_run_script

    step "Create directory structure?" create_dir_structure
    step "Write Sample scripts?" write_sample_scripts

    step "Copy install script and instructions?" copy_install_files

    step_run
}

function sys_install_and_symlink(){
    mkdir -p ~/.vendor
    cur_path="$(realpath "$cli_lib_dir")"
    path="$(realpath ~/.vendor/bash-cli)"
    if [[ "$cur_path" == "$path" ]];then
        msg
        msg_notice "Cli library already in ~/.vendor"   
        msg
        return
    fi

    if [[ -d ~/.vendor/bash-cli/ ]];then
        if prompt_yes_or_no "Delete existing '$path' directory?" ;then
            rm -rf ~/.vendor/bash-cli 
            mv "$cur_path" ~/.vendor/bash-cli
        else
            rm -rf "$cur_path"
        fi
    else
        mv "$cur_path" ~/.vendor/bash-cli
    fi

    ln -s ~/.vendor/bash-cli "$cur_path"
}

function add_vendor_to_git_ignore(){
    echo "vendor/" >> "$pwd/.gitignore"
}

function write_run_script(){
    scriptName=""
    while [[ -z "$scriptName" ]];do
        prompt "Name of your script? ${cInstruct}(q-quit)" scriptName
        if [[ "$scriptName" == "q" ]];then
            msg_status "quit"
        fi
    done

    mkdir -p "$pwd/bin"
    if [[ -f "$pwd/bin/$scriptName" ]];then
        mv "$pwd/bin/$scriptName" "$pwd/bin/$scriptName.$(uniqid).bak"
    fi
    cp "$cli_lib_dir/setup/bin/run" "$pwd/bin/$scriptName"
    msg "$pwd/bin/$scriptName" written

    if prompt_yes_or_no "Add '$pwd/bin' to PATH via ~/.bashrc?";then
        echo "export PATH=\"$pwd/bin:\$PATH\"" >> ~/.bashrc
    fi
}

function create_dir_structure(){
    mkdir -p "$pwd/code/core"
    mkdir -p "$pwd/code/lib"
    mkdir -p "$pwd/code/help"
}

function copy_install_files(){
    cp "$cli_lib_dir/setup/Install.src.md" "$pwd/Install.src.md"
    cp "$cli_lib_dir/setup/install" "$pwd/install"

    msg_instruct "See '$pwd/Install.src.md' for end-user install instructions"

}

function write_sample_scripts(){
    files=(core/core.bash lib/example.bash "help/core.bash")
    for f in "${files[@]}"; do
        path="$pwd/code/$f"
        if [[ ! -f "$path" ]];then
            cp "$cli_lib_dir/setup/$f" "$path"
        fi
    done
}