Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform: module to expose platform data #927

Merged
merged 2 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/eval/platform/platform.go
@@ -0,0 +1,29 @@
// Package `os` exposes variables and functions that deal with the specific
krader1961 marked this conversation as resolved.
Show resolved Hide resolved
// platform being run on; such as the OS name and CPU architecture.
package platform

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.
krader1961 marked this conversation as resolved.
Show resolved Hide resolved
// This corresponds to Go's
// [`GOARCH`](https://pkg.go.dev/runtime?tab=doc#pkg-constants) constant.
// This is read-only.

//elvdoc:var os
//
// The name of the operating system; e.g., darwin (macOS), linux, etc.
krader1961 marked this conversation as resolved.
Show resolved Hide resolved
// 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),
"os": vars.NewReadOnly(runtime.GOOS),
}
18 changes: 18 additions & 0 deletions pkg/eval/platform/platform_test.go
@@ -0,0 +1,18 @@
package platform

import (
"runtime"
"testing"

"github.com/elves/elvish/pkg/eval"
)

var That = eval.That

func TestOs(t *testing.T) {
krader1961 marked this conversation as resolved.
Show resolved Hide resolved
setup := func(ev *eval.Evaler) { ev.Builtin.AddNs("platform", Ns) }
eval.TestWithSetup(t, setup,
That(`put $platform:arch`).Puts(runtime.GOARCH),
That(`put $platform:os`).Puts(runtime.GOOS),
)
}
2 changes: 2 additions & 0 deletions pkg/program/shell/runtime.go
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/elves/elvish/pkg/eval/re"
"github.com/elves/elvish/pkg/eval/store"
"github.com/elves/elvish/pkg/eval/str"
"github.com/elves/elvish/pkg/eval/platform"
daemonp "github.com/elves/elvish/pkg/program/daemon"
)

Expand Down Expand Up @@ -74,6 +75,7 @@ func InitRuntime(binpath, sockpath, dbpath string) (*eval.Evaler, string) {
ev.InstallModule("math", eval.MathNs)
ev.InstallModule("re", re.Ns)
ev.InstallModule("str", str.Ns)
ev.InstallModule("platform", platform.Ns)
if sockpath != "" && dbpath != "" {
spawner := &daemonp.Daemon{
BinPath: binpath,
Expand Down
4 changes: 4 additions & 0 deletions website/ref/index.toml
Expand Up @@ -10,6 +10,10 @@ title = "The Builtin Module"
name = "edit"
title = "The Editor Module (edit:)"

[[articles]]
name = "platform"
title = "Access to the platform’s identifying data (platform:)"
krader1961 marked this conversation as resolved.
Show resolved Hide resolved

[[articles]]
name = "re"
title = "The Regular Expression Module (re:)"
Expand Down
7 changes: 7 additions & 0 deletions website/ref/platform.md
@@ -0,0 +1,7 @@
<!-- toc -->

# Introduction

The `platform:` module provides access to the platform’s identifying data.
krader1961 marked this conversation as resolved.
Show resolved Hide resolved

@elvdoc -ns platform: -dir ../pkg/eval/platform