Skip to content

Commit

Permalink
docs/howto: use path.Join
Browse files Browse the repository at this point in the history
This adds a Commented CUE guide that demonstrates using path.Join to
construct well-formed paths. One example of parent directory traversal
is included.

Preview-Path: /docs/howto/use-the-built-in-function-path-join-to-construct-well-formed-paths/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: I046a00af48dd5a34e15affe49a7ab8949bd0d787
  • Loading branch information
jpluscplusm committed Jan 23, 2024
1 parent 5dbac3a commit b14127c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Using the built-in function "path.Join" to construct well-formed paths
tags:
- commented cue
authors:
- jpluscplusm
toc_hide: true
---

This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates how to use the built-in function
[`path.Join`](https://pkg.go.dev/cuelang.org/go/pkg/path#Join)
to construct well-formed paths from their individual string components.

{{{with code "en" "cc"}}}
exec cue export
cmp stdout out
-- file.cue --
package example

import "path"

join: path.Join(["foo", "bar", "baz"], path.Unix)

unix: path.Join(_components, path.Unix)
windows: path.Join(_components, path.Windows)

_components: [
"foo",
"bar",
"baz",
"..",
"quux",
]
-- out --
{
"join": "foo/bar/baz",
"unix": "foo/bar/quux",
"windows": "foo\\bar\\quux"
}
{{{end}}}

## Related content

- The [`path`](https://pkg.go.dev/cuelang.org/go/pkg/path) built-in package
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package site
{
content: {
docs: {
howto: {
"use-the-built-in-function-path-join-to-construct-well-formed-paths": {
page: {
cache: {
code: {
cc: "y9OBCcAnpV6BCR0Yg7oiGAzQwvgKvFqM/g5jiSZOVzM="
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site

content: docs: howto: "use-the-built-in-function-path-join-to-construct-well-formed-paths": {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: Using the built-in function "path.Join" to construct well-formed paths
tags:
- commented cue
authors:
- jpluscplusm
toc_hide: true
---

This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}})
demonstrates how to use the built-in function
[`path.Join`](https://pkg.go.dev/cuelang.org/go/pkg/path#Join)
to construct well-formed paths from their individual string components.

{{< code-tabs >}}
{{< code-tab name="file.cue" language="cue" area="top-left" >}}
package example

import "path"

join: path.Join(["foo", "bar", "baz"], path.Unix)

unix: path.Join(_components, path.Unix)
windows: path.Join(_components, path.Windows)

_components: [
"foo",
"bar",
"baz",
"..",
"quux",
]
{{< /code-tab >}}
{{< code-tab name="TERMINAL" language="" type="terminal" area="top-right" >}}
$ cue export
{
"join": "foo/bar/baz",
"unix": "foo/bar/quux",
"windows": "foo\\bar\\quux"
}
{{< /code-tab >}}
{{< /code-tabs >}}

## Related content

- The [`path`](https://pkg.go.dev/cuelang.org/go/pkg/path) built-in package

0 comments on commit b14127c

Please sign in to comment.