5 Goalfile - introduction, tutorial, and reference for writing goal files
15 =head2 Standard Functions
17 =head3 basename (path)
21 basename ("dir/file.ext") ⇒ "file.ext"
23 Returns the filename part of the path.
29 dirname ("dir/file.ext") ⇒ "dir"
31 Returns the directory part of the path.
37 error ("this should not happen")
39 This prints the error message and causes goals to exit.
41 =head3 extension (filename)
45 extension ("dir/file.ext") ⇒ "ext"
47 Returns the filename extension.
49 =head3 filter (pattern, list)
53 filter ("a+", ["a", "b", "ca"]) ⇒ ["a", "ca"]
55 Filter a list returning only the elements that match the extended
56 regular expression C<pattern>.
58 =head3 filter-out (pattern, list)
62 filter-out ("a+", ["a", "b", "ca"]) ⇒ ["b"]
64 Filter a list returning only the elements that I<do not> match the
65 extended regular expression C<pattern>.
71 head (["a", "b", "c"]) ⇒ "a"
73 Returns the head (first) element of the list.
75 =head3 join (list1, list2)
79 join (["a", "b"], ["c", "d"]) ⇒ ["a", "b", "c", "d"]
81 Concatenate C<list1> and C<list2>. It's not usually necessary to use
82 this function since goals automatically flattens lists within lists
83 into simple lists in many cases.
85 =head3 read (filename)
89 read ("filename") => "this is the content of filename"
91 Read the contents of C<filename> and return it as a single string.
92 If there is a trailing C<\n> in the file it is truncated.
94 =head3 readlines (filename)
98 readlines ("filename") => ["line1", "line2", "line3"]
100 Read the lines in C<filename> returning a list of strings.
102 =head3 realpath (filename)
106 realpath ("./tests") ⇒ "/home/user/tests"
108 Run the L<realpath(1)> command to return the resolved absolute path of
109 the C<filename> parameter.
115 sort (["c", "b", "b", "a"]) ⇒ ["a", "b", "c"]
117 This takes a list of strings and sorts it, removing duplicates.
119 =head3 subst (from, to, text)
123 subst ("aa", "AA", "aabbccaa") ⇒ "AAbbccAA"
124 subst ("a.*c", "b", "aaacac") ⇒ "bb"
126 This function works something like make’s C<subst> function, except
127 that C<from> is a regular expression, specifically a L<sed(1)>
128 extended regular expression.
134 tail (["a", "b", "c"]) ⇒ ["b", "c"]
136 Returns the tail (all except first) elements of the list.
138 =head3 wildcard (pattern)
142 wildcard ("*.c") ⇒ ["bar.c", "foo.c"]
144 The single parameter is a wildcard which is expanded into a list of
145 files using ordinary globbing rules.
147 =head3 wrap (wrapper, list)
151 wrap ("*file", ["bar.c", "foo.c"]) ⇒ [*file("bar.c"), *file("foo.c")]
153 Each element in C<list> is wrapped into a call to C<wrapper(element)>.
154 There are two common uses for this: either to add explicit tactics
155 (such as C<*file>) to a plain list of strings as in the example above;
156 or to turn a list of strings into a list of goal or function calls.
164 Richard W.M. Jones <rjones@redhat.com>
168 Copyright (C) 2020 Richard W.M. Jones
170 Copyright (C) 2020 Red Hat Inc.
172 This program is free software; you can redistribute it and/or modify
173 it under the terms of the GNU General Public License as published by
174 the Free Software Foundation; either version 2 of the License, or
175 (at your option) any later version.
177 This program is distributed in the hope that it will be useful,
178 but WITHOUT ANY WARRANTY; without even the implied warranty of
179 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
180 GNU General Public License for more details.
182 You should have received a copy of the GNU General Public License along
183 with this program; if not, write to the Free Software Foundation, Inc.,
184 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.