-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(debug): Add databases=managed debug option (#2898)
* feat(debug): Add databases=managed debug option - Remove the --no-database flag - Refactor the shfmt package --------- Co-authored-by: Andrew Benton <[email protected]>
- Loading branch information
1 parent
5f87be3
commit df4c05b
Showing
6 changed files
with
84 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
package shfmt | ||
|
||
import ( | ||
"os" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var pat = regexp.MustCompile(`\$\{[A-Z_]+\}`) | ||
|
||
func Replace(f string, vars map[string]string) string { | ||
type Replacer struct { | ||
envmap map[string]string | ||
} | ||
|
||
func (r *Replacer) Replace(f string) string { | ||
return pat.ReplaceAllStringFunc(f, func(s string) string { | ||
s = strings.TrimPrefix(s, "${") | ||
s = strings.TrimSuffix(s, "}") | ||
return vars[s] | ||
return r.envmap[s] | ||
}) | ||
} | ||
|
||
func NewReplacer(env []string) *Replacer { | ||
r := Replacer{ | ||
envmap: map[string]string{}, | ||
} | ||
if env == nil { | ||
env = os.Environ() | ||
} | ||
for _, e := range env { | ||
k, v, _ := strings.Cut(e, "=") | ||
if k == "SQLC_AUTH_TOKEN" { | ||
continue | ||
} | ||
r.envmap[k] = v | ||
} | ||
return &r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters