Feat: add help, improve CLI experience

This commit is contained in:
kayos@tcp.direct 2023-08-06 23:20:08 -07:00
parent f433baafb7
commit 3ce0431d2d
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
5 changed files with 78 additions and 12 deletions

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
LPLUS="\e[0;33m[\e[0;32m+\e[0;33m]\e[0m"
LFAIL="\e[0;33m[\e[1;31mx\e[0;33m]\e[0m"

@ -1,22 +1,86 @@
#!/usr/bin/env bash
#!/bin/bash
function reqs() {
if ! command -v git &>/dev/null; then
fatal "please install git to use this tool"
fi
}
function usage() {
echo -e "\n\t\tclone-all\neasily clone/update a target's github repos\n"
echo -e "usage: $(echo $0 | awk -F '/' '{print $NF}') [OPTION...] TARGET\n"
echo -e "OPTION\n"
echo -e " -v \e[90m--verbose\e[0m\n\tenable debug output"
echo -e " -d \e[90m--destination\e[0m\n\tset clone output folder"
echo -e " -s \e[90m--ssh\e[0m\n\tuse ssh instead of https"
echo -e " -h \e[90m--help\e[0m\n\tshow this help message"
echo -e " -t \e[90m--target\e[0m\n\talternative way to set TARGET explicitly"
}
function setup() {
reqs
shopt -s extglob
_DESTINATION=${CLONEALL_DESTINATION:-"$HOME/Workshop"}
_DESTINATION="${_DESTINATION%%+(/)}"
_SSH=${CLONEALL_SSH:-false}
_APIKEY=${GITHUB_TOKEN:-""}
_CONTEXT="users"
if [ "$_DESTINATION" == "." ]; then
_DESTINATION=$(pwd)
fi
if [ "$1" == "--ssh" ]; then
_SSH=true
shift 1
_HASTARG=false
while [[ $# -gt 0 ]]; do
case $1 in
"-v" | "--verbose")
_DEBUG=true
debug "debug mode enabled"
shift
;;
"-d" | "--destination")
_DESTINATION="$1"
debug "_DESTINATION set to: $_DESTINATION"
shift
;;
"-s" | "--ssh")
_SSH=true
debug "using ssh instead of https"
shift
;;
"-h" | "--help")
usage
exit 0
;;
"-t" | "--target")
_USERNAME="$1"
debug "target set to: $_USERNAME"
shift
;;
*)
if [[ "$1" == "-"* ]]; then
err "unknown argument: $1"
usage
exit 1
fi
_USERNAME="$1"
debug "target set to: $_USERNAME"
shift
;;
esac
done
if [[ "$_USERNAME" == "" ]]; then
fatal "need target github user"
usage
exit 1
fi
_CONTEXT="users"
_USERNAME="$1"
_DESTINATION="${_DESTINATION%%+(/)}"
export _CONTEXT
export _DESTINATION
export _SSH
export _USERNAME
shift 1
debug "$(mkdir -vp "${_DESTINATION}/${_USERNAME}")" || return 1
}

@ -1,9 +1,11 @@
#!/usr/bin/env bash
#!/bin/bash
function get() {
_PAGE=1
while :; do
_APIRES=$(curl -s "https://api.github.com/$_CONTEXT/$_USERNAME/repos?page=$_PAGE&per_page=100")
_MYURL="https://api.github.com/$_CONTEXT/$_USERNAME/repos?page=$_PAGE&per_page=100"
debug "GET $_MYURL"
_APIRES=$(curl -s "$_MYURL")
if ! [[ "$_APIRES" =~ "clone_url" ]]; then
if [[ "$_APIRES" =~ [a-zA-Z] ]]; then
echo "$_APIRES"

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
function update() {
#debug "Update input: $1"

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
if ! setup "$@"; then
fatal "Failed to setup directory structure!"