Skip to content

Commit 34d937b

Browse files
committed
Add goinfo builtin for version information
This new builtin identifies the go-script-bash framework, the Bash version, and the operating system environment. Useful for bug reports.
1 parent ca879ad commit 34d937b

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

libexec/goinfo

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /usr/bin/env bash
2+
#
3+
# Prints go-script-bash, Bash, and operating system version information
4+
#
5+
# Useful for diagnosing problems and filing bug reports.
6+
#
7+
# More information may be gleaned from `uname`, as well as `sw_vers` on macOS,
8+
# but this includes the most often relevant information.
9+
10+
. "$_GO_USE_MODULES" 'format' 'platform'
11+
12+
_@go.gocore() {
13+
local varnames=('_GO_CORE_VERSION'
14+
'BASH_VERSION'
15+
'OSTYPE'
16+
'_GO_PLATFORM_ID'
17+
'_GO_PLATFORM_VERSION_ID')
18+
local values=()
19+
local varname
20+
local result=()
21+
22+
for varname in "${varnames[@]}"; do
23+
values+=("${!varname}")
24+
done
25+
26+
@go.pad_items 'varnames' "${varnames[@]/%/:}"
27+
@go.zip_items 'varnames' 'values' ' ' result
28+
printf '%s\n' "${result[@]}"
29+
}
30+
31+
_@go.gocore "$@"

tests/goinfo.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /usr/bin/env bats
2+
3+
load environment
4+
5+
setup() {
6+
test_filter
7+
@go.create_test_go_script '@go "$@"'
8+
export __GO_ETC_OS_RELEASE="$BATS_TEST_ROOTDIR/os-release"
9+
}
10+
11+
teardown() {
12+
@go.remove_test_go_rootdir
13+
}
14+
15+
@test "$SUITE: emit version information about framework, Bash, and OS" {
16+
# Use simulated /etc/os-release to prevent computation via uname or sw_vers.
17+
mkdir -p "$BATS_TEST_ROOTDIR"
18+
printf '%s\n' \
19+
'ID=foobar' \
20+
'VERSION_ID=666' >"$__GO_ETC_OS_RELEASE"
21+
22+
run "$TEST_GO_SCRIPT" 'goinfo'
23+
assert_success
24+
assert_lines_equal \
25+
"_GO_CORE_VERSION: $_GO_CORE_VERSION" \
26+
"BASH_VERSION: $BASH_VERSION" \
27+
"OSTYPE: $OSTYPE" \
28+
'_GO_PLATFORM_ID: foobar' \
29+
'_GO_PLATFORM_VERSION_ID: 666'
30+
}

0 commit comments

Comments
 (0)