Skip to content

Commit

Permalink
dockerfile: implement additional expansions
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Apr 12, 2024
1 parent 13ce842 commit 97268e9
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 42 deletions.
5 changes: 5 additions & 0 deletions rhel/dockerfile/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dockerfile

//go:generate -command stringer go run golang.org/x/tools/cmd/stringer
//go:generate stringer -type itemKind
//go:generate stringer -type varExpand -linecomment
3 changes: 0 additions & 3 deletions rhel/dockerfile/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ type item struct {

type itemKind int

//go:generate -command stringer go run golang.org/x/tools/cmd/stringer
//go:generate stringer -type itemKind

const (
itemError itemKind = iota
itemComment
Expand Down
3 changes: 3 additions & 0 deletions rhel/dockerfile/testdata/Colon.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: dockerfile: bad expansion of "error": rogue colon
-- Dockerfile --
LABEL a ${error::}
15 changes: 15 additions & 0 deletions rhel/dockerfile/testdata/Default.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Dockerfile --
LABEL a ${unset}
LABEL b ${unset=set}
LABEL c ${unset}

LABEL null=
LABEL d ${null:=reset}
-- Want --
{
"a": "",
"b": "set",
"c": "set",
"d": "reset",
"null": ""
}
3 changes: 3 additions & 0 deletions rhel/dockerfile/testdata/Error.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: dockerfile: bad expansion of "unset": should error (error if unset or null)
-- Dockerfile --
LABEL a ${unset:?should error}
11 changes: 11 additions & 0 deletions rhel/dockerfile/testdata/Quoting.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Dockerfile --
ARG a=\"
ARG a=\'
ARG a=\\
ARG a=\b
LABEL s='single\' quote: \\\b' d="double\" quote: \\\b\e"
-- Want --
{
"s": "single' quote: \\\\b",
"d": "double\" quote: \\\b\\e"
}
37 changes: 37 additions & 0 deletions rhel/dockerfile/testdata/Vars.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Dockerfile --
ARG null=''
LABEL dash_a ${unset-default}
LABEL dash_b ${unset:-default}
LABEL dash_c ${null-default}
LABEL dash_d ${null:-default}
LABEL plus_a ${unset+default}
LABEL plus_b ${unset:+default}
LABEL plus_c ${null+default}
LABEL plus_d ${null:+default}

ARG var=some-pattern.
LABEL prefix ${var#*e}
LABEL greedyprefix ${var##*e}
LABEL suffix ${var%e*.}
LABEL greedysuffix ${var%%e*.}
LABEL singlechar ${var%?}
LABEL greedysinglechar ${var%%?}
LABEL noreplace ${var#\?}
-- Want --
{
"dash_a": "default",
"dash_b": "default",
"dash_c": "",
"dash_d": "default",
"plus_a": "",
"plus_b": "",
"plus_c": "default",
"plus_d": "",
"prefix": "-pattern.",
"greedyprefix": "rn.",
"suffix": "some-patt",
"greedysuffix": "som",
"singlechar": "some-pattern",
"greedysinglechar": "some-pattern",
"noreplace": "some-pattern."
}
35 changes: 35 additions & 0 deletions rhel/dockerfile/varexpand_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97268e9

Please sign in to comment.