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
Dispatch-Trailer: {"type":"trybot","CL":1174728,"patchset":4,"ref":"refs/changes/28/1174728/4","targetBranch":"alpha"}
  • Loading branch information
jpluscplusm authored and cueckoo committed Jan 22, 2024
1 parent 837b0b6 commit 8709c83
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"

inline: 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 --
{
"inline": "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: "cse+WWX+uowJG/2noGjtURmZGxLi3Y7w3JjRT1BAHD0="
}
}
}
}
}
}
}
}
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"

inline: 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
{
"inline": "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 8709c83

Please sign in to comment.