Skip to content

Commit

Permalink
added --all option to 'cluster list' to list all cluster for all envi…
Browse files Browse the repository at this point in the history
…ronments. refs guedes#4
  • Loading branch information
fabriziomello committed Sep 26, 2012
1 parent 744f6b9 commit 2c6c6a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
37 changes: 30 additions & 7 deletions actions/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Usage: pgvm cluster <action> <args>
create Creates a new cluster (PGDATA)
remove Removes a cluster
rename Renames a cluster
list List all clusters
list List all clusters of current environment
list --all List all clusters of all environments
import Import a cluster from tarball
export Export a cluster to tarball
Expand Down Expand Up @@ -87,15 +88,37 @@ list()
cluster_top_dir="$pgvm_home/clusters/${current}"
clusters=$(find ${cluster_top_dir}/* -maxdepth 0 -type d -exec basename {} \; 2> /dev/null)

[[ -z "$clusters" ]] && echo "there is no clusters in current environment (${current})" && exit 1
if [ "$current_version" == "Please, install a PostgreSQL Version!" ]
then
echo $current_version
exit 1
fi

if [ "$1x" == "--allx" ]
then
versions=$(find ${cluster_top_dir}/* -maxdepth 0 -type d)
if [ "$versions" == "" ]
then
echo "there is no created clusters"
exit 1
fi
else
versions="$cluster_top_dir/$(current)"
fi

for top_dir in ${versions}
do
clusters=$(find ${top_dir}/* -maxdepth 0 -type d -exec basename {} \; 2> /dev/null)
cluster_version=$(basename $top_dir)

echo -e "cluster in current enviroment (${current}):\n"
[[ -z "$clusters" ]] && echo "there is no clusters in current environment (${cluster_version})" && exit 1

max_length=$(echo $clusters | awk 'BEGIN { RS = " " } ; { print length() }' | sort -n | tail -1)
max_length=$(echo $clusters | awk 'BEGIN { RS = " " } ; { print length() }' | sort -n | tail -1)

for cluster in ${clusters}
do
printf "%3s %-${max_length}s is %-7s at port %-4s\n" "$is_current" "$cluster" "$(cluster_human_status $cluster)" "$(cluster_port $cluster)"
for cluster in ${clusters}
do
printf "%3s %-6s %-${max_length}s is %-7s at port %-4s\n" "$is_current" "$cluster_version" "$cluster" "$(cluster_human_status $cluster $cluster_version)" "$(cluster_port $cluster $cluster_version)"
done
done
}

Expand Down
11 changes: 4 additions & 7 deletions test/pgvm_comment_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ pgvm cluster start test

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(8.4.12\):$/
#match=/^ test is online at port 5433$/
#match=/^ 8.4.12 test is online at port 5433$/

pgvm cluster create latin1_cluster --encoding=latin1 --locale=en_US
#status=0
Expand All @@ -140,8 +139,7 @@ pgvm cluster start my_cluster

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(9.2.1\):$/
#match=/^ my_cluster is online at port 5435$/
#match=/^ 9.2.1 my_cluster is online at port 5435$/

pgvm cluster create my_another_cluster
#status=0
Expand All @@ -153,9 +151,8 @@ pgvm cluster start my_another_cluster

pgvm cluster list
#status=0
#match=/^cluster in current enviroment \(9.2.1\):$/
#match=/^ my_another_cluster is online at port 5436$/
#match=/^ my_cluster is online at port 5435$/
#match=/^ 9.2.1 my_another_cluster is online at port 5436$/
#match=/^ 9.2.1 my_cluster is online at port 5435$/

## testing stopping cluster

Expand Down

0 comments on commit 2c6c6a5

Please sign in to comment.