File tree Expand file tree Collapse file tree 3 files changed +166
-0
lines changed
website/cue/reference/remap/functions Expand file tree Collapse file tree 3 files changed +166
-0
lines changed Original file line number Diff line number Diff line change
1
+ package metadata
2
+
3
+ remap : functions : basename : {
4
+ category : " String "
5
+ description : """
6
+ Returns the filename component of the given `path`. This is similar to the Unix `basename` command.
7
+ If the path ends in a directory separator, the function returns the name of the directory.
8
+ """
9
+
10
+ arguments : [
11
+ {
12
+ name : " value "
13
+ description : " The path from which to extract the basename. "
14
+ required : true
15
+ type : [" string " ]
16
+ },
17
+ ]
18
+ internal_failure_reasons : [
19
+ " `value` is not a valid string. " ,
20
+ ]
21
+ return : types : [" string " , " null " ]
22
+
23
+ examples : [
24
+ {
25
+ title : " Extract basename from file path "
26
+ source : """
27
+ basename!("/usr/local/bin/vrl")
28
+ """
29
+ return : " vrl "
30
+ },
31
+ {
32
+ title : " Extract basename from file path with extension "
33
+ source : """
34
+ basename!("/home/user/file.txt")
35
+ """
36
+ return : " file.txt "
37
+ },
38
+ {
39
+ title : " Extract basename from directory path "
40
+ source : """
41
+ basename!("/home/user/")
42
+ """
43
+ return : " user "
44
+ },
45
+ {
46
+ title : " Root directory has no basename "
47
+ source : """
48
+ basename!("/")
49
+ """
50
+ return : null
51
+ },
52
+ ]
53
+ }
Original file line number Diff line number Diff line change
1
+ package metadata
2
+
3
+ remap : functions : dirname : {
4
+ category : " String "
5
+ description : """
6
+ Returns the directory component of the given `path`. This is similar to the Unix `dirname` command.
7
+ The directory component is the path with the final component removed.
8
+ """
9
+
10
+ arguments : [
11
+ {
12
+ name : " value "
13
+ description : " The path from which to extract the directory name. "
14
+ required : true
15
+ type : [" string " ]
16
+ },
17
+ ]
18
+ internal_failure_reasons : [
19
+ " `value` is not a valid string. " ,
20
+ ]
21
+ return : types : [" string " ]
22
+
23
+ examples : [
24
+ {
25
+ title : " Extract dirname from file path "
26
+ source : """
27
+ dirname!("/usr/local/bin/vrl")
28
+ """
29
+ return : " /usr/local/bin "
30
+ },
31
+ {
32
+ title : " Extract dirname from file path with extension "
33
+ source : """
34
+ dirname!("/home/user/file.txt")
35
+ """
36
+ return : " /home/user "
37
+ },
38
+ {
39
+ title : " Extract dirname from directory path "
40
+ source : """
41
+ dirname!("/home/user/")
42
+ """
43
+ return : " /home "
44
+ },
45
+ {
46
+ title : " Root directory dirname is itself "
47
+ source : """
48
+ dirname!("/")
49
+ """
50
+ return : " / "
51
+ },
52
+ {
53
+ title : " Relative files have current directory as dirname "
54
+ source : """
55
+ dirname!("file.txt")
56
+ """
57
+ return : " . "
58
+ },
59
+ ]
60
+ }
Original file line number Diff line number Diff line change
1
+ package metadata
2
+
3
+ remap : functions : split_path : {
4
+ category : " String "
5
+ description : """
6
+ Splits the given `path` into its constituent components, returning an array of strings.
7
+ Each component represents a part of the file system path hierarchy.
8
+ """
9
+
10
+ arguments : [
11
+ {
12
+ name : " value "
13
+ description : " The path to split into components. "
14
+ required : true
15
+ type : [" string " ]
16
+ },
17
+ ]
18
+ internal_failure_reasons : [
19
+ " `value` is not a valid string. " ,
20
+ ]
21
+ return : types : [" array " ]
22
+
23
+ examples : [
24
+ {
25
+ title : " Split path with trailing slash "
26
+ source : """
27
+ split_path!("/home/user/")
28
+ """
29
+ return : [" / " , " home " , " user " ]
30
+ },
31
+ {
32
+ title : " Split path from file path "
33
+ source : """
34
+ split_path!("/home/user")
35
+ """
36
+ return : [" / " , " home " , " user " ]
37
+ },
38
+ {
39
+ title : " Split path from root "
40
+ source : """
41
+ split_path!("/")
42
+ """
43
+ return : [" / " ]
44
+ },
45
+ {
46
+ title : " Empty path returns empty array "
47
+ source : """
48
+ split_path!("")
49
+ """
50
+ return : []
51
+ },
52
+ ]
53
+ }
You can’t perform that action at this time.
0 commit comments