File tree Expand file tree Collapse file tree
third_party/github.com/drone/envsubst/parse Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package carapace
22
33import (
4+ "fmt"
45 "os"
56 "path/filepath"
67 "strings"
@@ -101,6 +102,11 @@ func TestEnvsubst(t *testing.T) {
101102 t .Fail ()
102103 }
103104
105+ if s , err := c .Envsubst ("start${!example}end" ); s != "start${example}end" || err != nil {
106+ fmt .Println (s )
107+ t .Fail ()
108+ }
109+
104110 if s , err := c .Envsubst ("start${example:-default}end" ); s != "startdefaultend" || err != nil {
105111 t .Fail ()
106112 }
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package parse
22
33import (
44 "errors"
5+ "fmt"
6+ "strings"
57)
68
79var (
@@ -90,6 +92,8 @@ func (t *Tree) parseFunc() (Node, error) {
9092 // Turn on all escape characters
9193 t .scanner .escapeChars = escapeAll
9294 switch t .scanner .peek () {
95+ case '!' :
96+ return t .parseIgnoredFunc ()
9397 case '#' :
9498 return t .parseLenFunc ()
9599 }
@@ -355,6 +359,21 @@ func (t *Tree) parseCasingFunc(name string) (Node, error) {
355359 return node , t .consumeRbrack ()
356360}
357361
362+ // parses the ignored ${!...} function
363+ func (t * Tree ) parseIgnoredFunc () (Node , error ) {
364+ node := new (TextNode )
365+
366+ t .scanner .accept = acceptNotClosing
367+ t .scanner .mode = scanIdent
368+ switch t .scanner .scan () {
369+ case tokenIdent :
370+ node .Value = fmt .Sprintf ("${%v}" , strings .TrimPrefix (t .scanner .string (), "!" ))
371+ default :
372+ return nil , ErrBadSubstitution
373+ }
374+ return node , t .consumeRbrack ()
375+ }
376+
358377// parses the ${#param} string function
359378func (t * Tree ) parseLenFunc () (Node , error ) {
360379 node := new (FuncNode )
You can’t perform that action at this time.
0 commit comments