Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

WEEK2CHALLENGE flavio.ciotola3 #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# btpguid - return BTP subaccount/directory GUIDs

# Usage: btpguid [-t|--target] displayname
Expand Down Expand Up @@ -25,25 +26,24 @@ btp get accounts/global-account --show-hierarchy 2>/dev/null
main() {

local hierarchy subtype guid displayname rc=0
local event=Devtoberfest

displayname="${2:-$1}"

[[ -z displayname ]] && {
[[ -z $displayname ]] && {
echo "No display name specified"
exit 1
}

hierarchy="$(gethier)" || { btp login && hierarchy="$(gethier)"; }
read subtype guid <<< "$(grep -P -o "^(subaccount|directory)\s+(\S+)(?=\s+$displayname)" <<< $hierarchy)"
read -r subtype guid <<< "$(grep -P -o "^(subaccount|directory)\s+(\S+)(?=\s+$displayname)" <<< "$hierarchy")"

# Set the subtype as target if requested
[[ $1 == -t ]] || [[ $1 == --target ]] && {
btp target "--${subtype}" "$guid" &> /dev/null
rc=$?
}

echo $guid
echo "$guid"
return $rc

}
Expand Down