Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sys: module to expose platform and arch vars
Resolves #916
- Loading branch information
1 parent
c34464c
commit b004f71
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package `os` exposes variables and functions that deal with the specific | ||
// platform being run on; such as the OS name and CPU architecture. | ||
package os | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/elves/elvish/pkg/eval" | ||
"github.com/elves/elvish/pkg/eval/vars" | ||
) | ||
|
||
//elvdoc:var arch | ||
// | ||
// The architecture of the platform; e.g., amd64, arm, ppc. | ||
// This corresponds to Go's | ||
// [`GOARCH`](https://pkg.go.dev/runtime?tab=doc#pkg-constants) constant. | ||
// This is read-only. | ||
|
||
//elvdoc:var platform | ||
// | ||
// The name of the platform; e.g., darwin (macOS), linux, etc. | ||
// This corresponds to Go's | ||
// [`GOOS`](https://pkg.go.dev/runtime?tab=doc#pkg-constants) constant. | ||
// This is read-only. | ||
|
||
var Ns = eval.Ns{ | ||
"arch": vars.NewReadOnly(runtime.GOARCH), | ||
"platform": vars.NewReadOnly(runtime.GOOS), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package os | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/elves/elvish/pkg/eval" | ||
) | ||
|
||
var That = eval.That | ||
|
||
func TestOs(t *testing.T) { | ||
setup := func(ev *eval.Evaler) { ev.Builtin.AddNs("os", Ns) } | ||
eval.TestWithSetup(t, setup, | ||
That(`put $os:arch`).Puts(runtime.GOARCH), | ||
That(`put $os:platform`).Puts(runtime.GOOS), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- toc --> | ||
|
||
# Introduction | ||
|
||
The `os:` module provides platform specific constants. | ||
|
||
Function usages are given in the same format as in the | ||
reference doc for the [builtin module](builtin.html). | ||
|
||
@elvdoc -ns os: -dir ../pkg/eval/os |