-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5dbac3a
commit b14127c
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
.../howto/use-the-built-in-function-path-join-to-construct-well-formed-paths/en.md
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,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 |
18 changes: 18 additions & 0 deletions
18
...cs/howto/use-the-built-in-function-path-join-to-construct-well-formed-paths/gen_cache.cue
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 site | ||
{ | ||
content: { | ||
docs: { | ||
howto: { | ||
"use-the-built-in-function-path-join-to-construct-well-formed-paths": { | ||
page: { | ||
cache: { | ||
code: { | ||
cc: "y9OBCcAnpV6BCR0Yg7oiGAzQwvgKvFqM/g5jiSZOVzM=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...nt/docs/howto/use-the-built-in-function-path-join-to-construct-well-formed-paths/page.cue
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,3 @@ | ||
package site | ||
|
||
content: docs: howto: "use-the-built-in-function-path-join-to-construct-well-formed-paths": {} |
46 changes: 46 additions & 0 deletions
46
...wto/use-the-built-in-function-path-join-to-construct-well-formed-paths/index.md
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,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 |