From c381923d3e2b1164dda19e1d8e4fa66f2c0be2d1 Mon Sep 17 00:00:00 2001 From: Amogh Rameshappa Devapura Date: Tue, 29 Oct 2024 09:50:17 -0400 Subject: [PATCH] feat: add numCPU func (#1890) --- internal/templater/funcs.go | 5 +++-- website/docs/reference/templating.mdx | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/templater/funcs.go b/internal/templater/funcs.go index 1d9d9068..79c837a3 100644 --- a/internal/templater/funcs.go +++ b/internal/templater/funcs.go @@ -17,8 +17,9 @@ var templateFuncs template.FuncMap func init() { taskFuncs := template.FuncMap{ - "OS": func() string { return runtime.GOOS }, - "ARCH": func() string { return runtime.GOARCH }, + "OS": func() string { return runtime.GOOS }, + "ARCH": func() string { return runtime.GOARCH }, + "numCPU": func() int { return runtime.NumCPU() }, "catLines": func(s string) string { s = strings.ReplaceAll(s, "\r\n", " ") return strings.ReplaceAll(s, "\n", " ") diff --git a/website/docs/reference/templating.mdx b/website/docs/reference/templating.mdx index 6c9f738f..468a4333 100644 --- a/website/docs/reference/templating.mdx +++ b/website/docs/reference/templating.mdx @@ -374,7 +374,8 @@ Lastly, Task itself provides a few functions: | Function | Description | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `OS` | Returns the operating system. Possible values are `windows`, `linux`, `darwin` (macOS) and `freebsd`. | -| `ARCH` | return the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `ARCH` | Returns the architecture Task was compiled to: `386`, `amd64`, `arm` or `s390x`. | +| `numCPU` | Returns the number of logical CPU's usable by the current process. | | `splitLines` | Splits Unix (`\n`) and Windows (`\r\n`) styled newlines. | | `catLines` | Replaces Unix (`\n`) and Windows (`\r\n`) styled newlines with a space. | | `toSlash` | Does nothing on Unix, but on Windows converts a string from `\` path format to `/`. |