Skip to content

Commit

Permalink
Added the ability to use directories without explicit specification i…
Browse files Browse the repository at this point in the history
…n the config
  • Loading branch information
alexaandrov committed Oct 17, 2023
1 parent 114a178 commit d86272e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ install() {
set -e

# Set variables

local destination_path="/tmp"
local bin_path="/usr/local/bin"
local stitchocker_stable_release="1.2.2"
local stitchocker_stable_release="1.2.3"
local stitchoker_uri="https://raw.githubusercontent.com/alexaandrov/stitchocker/$stitchocker_stable_release/stitchocker.sh"
local stitchocker_name="stitchocker"
local stitchocker_tmp_path="$destination_path/$stitchocker_name.sh"
Expand Down
31 changes: 21 additions & 10 deletions stitchocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

stitchocker() {
local self="stitchocker"
local version="1.2.2"
local version="1.2.3"
local version_info="Stitchocker version $version"
local help="
Usage:
$self [--verbose|--debug] [-a <env_alias>] [docker-compose COMMAND] [SETS...]
$self -h|--help
$self -v|--version
Options:
-h|--help Shows this help text
-v|--version Shows $self version
Expand All @@ -26,7 +26,7 @@ stitchocker() {
--verbose Runs all commands in verbose mode
-p Path to stitching directory
-a Alias to stitching directory
Examples:
$self up
$self up default backend frontend
Expand Down Expand Up @@ -145,11 +145,10 @@ stitchocker() {

if [[ ! -f $config_path ]]; then
error --no-exit "No config found for: $path"
info "Available config names: ${available_config_names[@]}"
exit 1
info --exit "Available config names: ${available_config_names[@]}"
fi

local default_set=$(env stitchocker_default_set)
local default_set=$(env ${self}_default_set)
if [[ ! -z $default_set && $default_set != "null" ]]; then
default_set="$default_set"
else
Expand All @@ -170,18 +169,23 @@ stitchocker() {
done
exit 1
fi
local set="$first_flag"
local set=$(echo "$first_flag" | tr '-' '_')
local set_info=$first_flag
else
local set="$default_set"
local set_info=$set
fi

local services="$(eval echo \${${sets_field}_${set}[*]})"
local search_mode="set"

if [[ -z $services ]]; then
error "Your config doesn't have \"$set\" value"
search_mode="directory"
warn "Your ${self} config doesn't have \"$set_info\" value. Trying to find an existing directory on path."
services=$flags
fi

info "$(echo "$command" | awk '{print toupper(substr($0,0,1))tolower(substr($0,2))}') $set set:"
info "$(echo "$command" | awk '{print toupper(substr($0,0,1))tolower(substr($0,2))}') $set_info $search_mode:"

for service_alias in ${services}; do
local service_alias_head="$(echo $service_alias | head -c 1)"
Expand Down Expand Up @@ -354,7 +358,7 @@ env_handle() {
info() {
local green=$(tput setaf 2)
local reset=$(tput sgr0)

if [[ $1 != "--exit" ]]; then
echo -e "${green}$@${reset}"
echo
Expand All @@ -364,6 +368,13 @@ info() {
fi
}

warn() {
local grey=$(tput setaf 8)
local reset=$(tput sgr0)
echo -e "${grey}$@${reset}"
echo
}

error() {
local red=$(tput setaf 1)
local reset=$(tput sgr0)
Expand Down

0 comments on commit d86272e

Please sign in to comment.