noot
This commit is contained in:
parent
69392aa7f1
commit
c8f01255ae
8
Makefile
8
Makefile
|
@ -1,10 +1,16 @@
|
|||
.PHONY: all
|
||||
.PHONY: all install
|
||||
|
||||
SOURCES_LIBS:=$(shell find lib -type f)
|
||||
SOURCES_SRC:=$(shell find src -type f )
|
||||
INSTALL_PATH:= $(shell echo ${HOME}/repo/.bin)
|
||||
|
||||
all: repotool
|
||||
|
||||
install: repotool
|
||||
mkdir -p ${INSTALL_PATH}
|
||||
install repotool repotool.zsh ${INSTALL_PATH}
|
||||
|
||||
|
||||
src/lib/repotool/stdlib.sh: $(SOURCES_LIBS)
|
||||
bashly add --source . stdlib -f
|
||||
|
||||
|
|
|
@ -34,5 +34,14 @@ lecho()
|
|||
echo $@ >&2
|
||||
}
|
||||
|
||||
linspect()
|
||||
{
|
||||
if [[ -z "$DEBUG_LOG" || "$DEBUG_LOG" == 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
inspect_args>&2
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
40
repotool
40
repotool
|
@ -53,7 +53,7 @@ repotool_usage() {
|
|||
printf "%s\n" "Environment Variables:"
|
||||
|
||||
# :environment_variable.usage
|
||||
printf " %s\n" "REPOS_PATH"
|
||||
printf " %s\n" "REPOTOOL_PATH"
|
||||
printf " default path to clone to\n"
|
||||
printf " Default: $HOME/repo\n"
|
||||
echo
|
||||
|
@ -247,13 +247,23 @@ lecho()
|
|||
echo $@ >&2
|
||||
}
|
||||
|
||||
linspect()
|
||||
{
|
||||
if [[ -z "$DEBUG_LOG" || "$DEBUG_LOG" == 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
inspect_args>&2
|
||||
}
|
||||
|
||||
# :command.command_functions
|
||||
# :command.function
|
||||
repotool_get_command() {
|
||||
# src/get_command.sh
|
||||
#inspect_args>&2
|
||||
local resp
|
||||
|
||||
linspect
|
||||
|
||||
local resp
|
||||
resp=$(valid_url ${args[repo]})
|
||||
if [[ $resp == -1 ]]; then
|
||||
echo "${args[repo]} is not a valid repo"
|
||||
|
@ -262,6 +272,10 @@ repotool_get_command() {
|
|||
|
||||
local regex="${deps[perl]} -n -l -e"
|
||||
|
||||
local git="${deps[git]}"
|
||||
|
||||
local base_path=$REPOTOOL_PATH
|
||||
|
||||
local ssh_user;
|
||||
# the ssh user to clone with
|
||||
|
||||
|
@ -315,8 +329,7 @@ http_user: $http_user
|
|||
http_pass: $http_pass
|
||||
EOF
|
||||
|
||||
local target_dir="$REPOS_PATH/$domain/$path"
|
||||
#mkdir for our target directory
|
||||
local target_dir="$base_path/$domain/$path"
|
||||
|
||||
if [[ ! -d $target_dir ]]; then
|
||||
mkdir -p $target_dir
|
||||
|
@ -335,23 +348,26 @@ EOF
|
|||
repo_url="$method://$domain/$path.git"
|
||||
;;
|
||||
*)
|
||||
>&2 echo "unrecognized clone method $method"
|
||||
echo "unrecognized clone method $method"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
# we check if we have cloned the repo via the if the .git folder exists
|
||||
if [[ ! -d .git ]]; then
|
||||
# check if the remote actually exists
|
||||
git ls-remote $repo_url > /dev/null && RC=$? || RC=$?
|
||||
$git ls-remote $repo_url > /dev/null && RC=$? || RC=$?
|
||||
if [[ $RC == 0 ]]; then
|
||||
git clone $repo_url $target_dir >&2
|
||||
$git clone $repo_url $target_dir >&2
|
||||
else
|
||||
>&2 echo "Could not find repo: $repo_url"
|
||||
echo "Could not find repo: $repo_url"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo dir=$target_dir domain=$domain path=$path repo_url=$repo_url
|
||||
|
||||
exit 0
|
||||
|
||||
}
|
||||
|
||||
# :command.parse_requirements
|
||||
|
@ -379,10 +395,10 @@ parse_requirements() {
|
|||
|
||||
# :command.environment_variables_filter
|
||||
# :command.environment_variables_default
|
||||
export REPOS_PATH="${REPOS_PATH:-$HOME/repo}"
|
||||
export REPOTOOL_PATH="${REPOTOOL_PATH:-$HOME/repo}"
|
||||
export DEBUG_LOG="${DEBUG_LOG:-0}"
|
||||
|
||||
env_var_names+=("REPOS_PATH")
|
||||
env_var_names+=("REPOTOOL_PATH")
|
||||
env_var_names+=("DEBUG_LOG")
|
||||
|
||||
# :command.command_filter
|
||||
|
@ -579,7 +595,7 @@ initialize() {
|
|||
set -e
|
||||
|
||||
# :command.environment_variables_default
|
||||
export REPOS_PATH="${REPOS_PATH:-$HOME/repo}"
|
||||
export REPOTOOL_PATH="${REPOTOOL_PATH:-$HOME/repo}"
|
||||
export DEBUG_LOG="${DEBUG_LOG:-0}"
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
[[ -z "$REPOTOOL_PATH" ]] && export REPOTOOL_PATH="$HOME/repo"
|
||||
|
||||
alias repo=". $REPOTOOL_PATH/.bin/repotool.zsh"
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
[[ -z "$REPOTOOL_PATH" ]] && export REPOTOOL_PATH="$HOME/repo"
|
||||
|
||||
_activate_hook() {
|
||||
if [[ -f "$REPOTOOL_PATH/.hooks/$1.zsh" ]]; then
|
||||
. "$REPOTOOL_PATH/.hooks/$1.zsh" $2
|
||||
return 0
|
||||
fi
|
||||
if [[ -f "$REPOTOOL_PATH/.hooks/$1.sh" ]]; then
|
||||
. "$REPOTOOL_PATH/.hooks/$1.sh" $2
|
||||
return 0
|
||||
fi
|
||||
if [[ -f "$REPOTOOL_PATH/.hooks/$1" ]]; then
|
||||
. "$REPOTOOL_PATH/.hooks/$1" $2
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
case "$1" in
|
||||
get)
|
||||
shift;
|
||||
response=$($REPOTOOL_PATH/.bin/repotool get $@)
|
||||
if [[ $? != 0 ]] then;
|
||||
exit $?
|
||||
fi
|
||||
declare -A obj
|
||||
for item in ${(z)response}; do
|
||||
parts=(${(s[=])item})
|
||||
# NOTE: zsh is 1 indexed arrays
|
||||
obj[${parts[1]}]=${parts[2]}
|
||||
done
|
||||
_activate_hook "before_cd" $response
|
||||
cd ${obj[dir]}
|
||||
_activate_hook "after_cd" $response
|
||||
;;
|
||||
'help' | "-h"| "-help" | "--help")
|
||||
esac
|
|
@ -3,7 +3,7 @@ help: repo tool
|
|||
version: 0.1.0
|
||||
|
||||
environment_variables:
|
||||
- name: REPOS_PATH
|
||||
- name: REPOTOOL_PATH
|
||||
default: $HOME/repo
|
||||
help: default path to clone to
|
||||
- name: DEBUG_LOG
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#inspect_args>&2
|
||||
local resp
|
||||
|
||||
linspect
|
||||
|
||||
local resp
|
||||
resp=$(valid_url ${args[repo]})
|
||||
if [[ $resp == -1 ]]; then
|
||||
echo "${args[repo]} is not a valid repo"
|
||||
|
@ -9,6 +10,10 @@ fi
|
|||
|
||||
local regex="${deps[perl]} -n -l -e"
|
||||
|
||||
local git="${deps[git]}"
|
||||
|
||||
local base_path=$REPOTOOL_PATH
|
||||
|
||||
|
||||
local ssh_user;
|
||||
# the ssh user to clone with
|
||||
|
@ -65,8 +70,7 @@ http_pass: $http_pass
|
|||
EOF
|
||||
|
||||
|
||||
local target_dir="$REPOS_PATH/$domain/$path"
|
||||
#mkdir for our target directory
|
||||
local target_dir="$base_path/$domain/$path"
|
||||
|
||||
if [[ ! -d $target_dir ]]; then
|
||||
mkdir -p $target_dir
|
||||
|
@ -85,7 +89,7 @@ case $method in
|
|||
repo_url="$method://$domain/$path.git"
|
||||
;;
|
||||
*)
|
||||
>&2 echo "unrecognized clone method $method"
|
||||
echo "unrecognized clone method $method"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
|
@ -94,12 +98,15 @@ esac
|
|||
# we check if we have cloned the repo via the if the .git folder exists
|
||||
if [[ ! -d .git ]]; then
|
||||
# check if the remote actually exists
|
||||
git ls-remote $repo_url > /dev/null && RC=$? || RC=$?
|
||||
$git ls-remote $repo_url > /dev/null && RC=$? || RC=$?
|
||||
if [[ $RC == 0 ]]; then
|
||||
git clone $repo_url $target_dir >&2
|
||||
$git clone $repo_url $target_dir >&2
|
||||
else
|
||||
>&2 echo "Could not find repo: $repo_url"
|
||||
echo "Could not find repo: $repo_url"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo dir=$target_dir domain=$domain path=$path repo_url=$repo_url
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -34,5 +34,14 @@ lecho()
|
|||
echo $@ >&2
|
||||
}
|
||||
|
||||
linspect()
|
||||
{
|
||||
if [[ -z "$DEBUG_LOG" || "$DEBUG_LOG" == 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
inspect_args>&2
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue