|
5 | 5 | "flag" |
6 | 6 | "fmt" |
7 | 7 | "os" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/BurntSushi/toml" |
10 | 11 | awsconfig "github.com/aws/aws-sdk-go-v2/config" |
@@ -61,6 +62,21 @@ func runDeploy(args []string) { |
61 | 62 | debugHeaders := fs.Bool("debug-headers", false, "inject debug headers into viewer-response function") |
62 | 63 | fs.Parse(args) |
63 | 64 |
|
| 65 | + // Resolve @FILE syntax for string flags |
| 66 | + mustResolve := func(v, flag string) string { |
| 67 | + result, err := resolveAtFile(v) |
| 68 | + if err != nil { |
| 69 | + fatal("--%s: %v", flag, err) |
| 70 | + } |
| 71 | + return result |
| 72 | + } |
| 73 | + *outputDir = mustResolve(*outputDir, "output-dir") |
| 74 | + *redirectsKVS = mustResolve(*redirectsKVS, "redirects-kvs-name") |
| 75 | + *headersKVS = mustResolve(*headersKVS, "headers-kvs-name") |
| 76 | + *requestFunc = mustResolve(*requestFunc, "request-function-name") |
| 77 | + *responseFunc = mustResolve(*responseFunc, "response-function-name") |
| 78 | + *region = mustResolve(*region, "region") |
| 79 | + |
64 | 80 | // Load config file |
65 | 81 | cfg := loadConfig(*configPath) |
66 | 82 |
|
@@ -257,3 +273,15 @@ func fatal(format string, args ...any) { |
257 | 273 | fmt.Fprintf(os.Stderr, "error: "+format+"\n", args...) |
258 | 274 | os.Exit(1) |
259 | 275 | } |
| 276 | + |
| 277 | +// resolveAtFile resolves @FILE syntax: if s starts with '@', reads and returns the trimmed file contents. |
| 278 | +func resolveAtFile(s string) (string, error) { |
| 279 | + if !strings.HasPrefix(s, "@") { |
| 280 | + return s, nil |
| 281 | + } |
| 282 | + data, err := os.ReadFile(s[1:]) |
| 283 | + if err != nil { |
| 284 | + return "", fmt.Errorf("reading file %q: %w", s[1:], err) |
| 285 | + } |
| 286 | + return strings.TrimSpace(string(data)), nil |
| 287 | +} |
0 commit comments