stdlib: Implement error() function.
[goals.git] / docs / Goalfile.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 Goalfile - introduction, tutorial, and reference for writing goal files
6
7 =head1 SUMMARY
8
9 =head1 INTRODUCTION
10
11 =head1 TUTORIAL
12
13 =head1 REFERENCE
14
15 =head2 Standard Functions
16
17 =head3 basename (path)
18
19 For example:
20
21  basename ("dir/file.ext") ⇒ "file.ext"
22
23 Returns the filename part of the path.
24
25 =head3 dirname (path)
26
27 For example:
28
29  dirname ("dir/file.ext") ⇒ "dir"
30
31 Returns the directory part of the path.
32
33 =head3 error (msg)
34
35 For example:
36
37  error ("this should not happen")
38
39 This prints the error message and causes goals to exit.
40
41 =head3 extension (filename)
42
43 For example:
44
45  extension ("dir/file.ext") ⇒ "ext"
46
47 Returns the filename extension.
48
49 =head3 head (list)
50
51 For example:
52
53  head (["a", "b", "c"]) ⇒ "a"
54
55 Returns the head (first) element of the list.
56
57 =head3 join (list1, list2)
58
59 For example:
60
61  join (["a", "b"], ["c", "d"]) ⇒ ["a", "b", "c", "d"]
62
63 Concatenate C<list1> and C<list2>.  It's not usually necessary to use
64 this function since goals automatically flattens lists within lists
65 into simple lists in many cases.
66
67 =head3 read (filename)
68
69 For example:
70
71  read ("filename") => "this is the content of filename"
72
73 Read the contents of C<filename> and return it as a single string.
74 If there is a trailing C<\n> in the file it is truncated.
75
76 =head3 readlines (filename)
77
78 For example:
79
80  readlines ("filename") => ["line1", "line2", "line3"]
81
82 Read the lines in C<filename> returning a list of strings.
83
84 =head3 realpath (filename)
85
86 For example:
87
88  realpath ("./tests") ⇒ "/home/user/tests"
89
90 Run the L<realpath(1)> command to return the resolved absolute path of
91 the C<filename> parameter.
92
93 =head3 sort (list)
94
95 For example:
96
97  sort (["c", "b", "b", "a"]) ⇒ ["a", "b", "c"]
98
99 This takes a list of strings and sorts it, removing duplicates.
100
101 =head3 subst (from, to, text)
102
103 For example:
104
105  subst ("aa", "AA", "aabbccaa") ⇒ "AAbbccAA"
106  subst ("a.*c", "b", "aaacac") ⇒ "bb"
107
108 This function works something like make’s C<subst> function, except
109 that C<from> is a regular expression, specifically a L<sed(1)>
110 extended regular expression.
111
112 =head3 tail (list)
113
114 For example:
115
116  tail (["a", "b", "c"]) ⇒ ["b", "c"]
117
118 Returns the tail (all except first) elements of the list.
119
120 =head3 wildcard (pattern)
121
122 For example:
123
124  wildcard ("*.c") ⇒ ["bar.c", "foo.c"]
125
126 The single parameter is a wildcard which is expanded into a list of
127 files using ordinary globbing rules.
128
129 =head3 wrap (wrapper, list)
130
131 For example:
132
133  wrap ("*file", ["bar.c", "foo.c"]) ⇒ [*file("bar.c"), *file("foo.c")]
134
135 Each element in C<list> is wrapped into a call to C<wrapper(element)>.
136 There are two common uses for this: either to add explicit tactics
137 (such as C<*file>) to a plain list of strings as in the example above;
138 or to turn a list of strings into a list of goal or function calls.
139
140 =head1 SEE ALSO
141
142 L<goals(1)>.
143
144 =head1 AUTHORS
145
146 Richard W.M. Jones <rjones@redhat.com>
147
148 =head1 COPYRIGHT
149
150 Copyright (C) 2020 Richard W.M. Jones
151
152 Copyright (C) 2020 Red Hat Inc.
153
154 This program is free software; you can redistribute it and/or modify
155 it under the terms of the GNU General Public License as published by
156 the Free Software Foundation; either version 2 of the License, or
157 (at your option) any later version.
158
159 This program is distributed in the hope that it will be useful,
160 but WITHOUT ANY WARRANTY; without even the implied warranty of
161 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162 GNU General Public License for more details.
163
164 You should have received a copy of the GNU General Public License along
165 with this program; if not, write to the Free Software Foundation, Inc.,
166 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.