Skip to content

Commit

Permalink
Add --run-file support for stdin
Browse files Browse the repository at this point in the history
If the run-file argument is speficied as '-', read the config file from stdin

Signed-off-by: Stuart Leeks <stuartle@microsoft.com>
  • Loading branch information
stuartleeks committed Nov 9, 2023
1 parent a339bdf commit 5a04ffd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ dapr run --run-file dapr.yaml
# Run multiple apps by providing a directory path containing the run config file(dapr.yaml)
dapr run --run-file /path/to/directory
# Run multiple apps by providing config via stdin
cat dapr.template.yaml | envsubst | dapr run --run-file -
# Run multiple apps in Kubernetes by proficing path of a run config file
dapr run --run-file dapr.yaml -k
Expand Down Expand Up @@ -1008,6 +1011,9 @@ func putDaprLogFilePathInMeta(runE *runExec.RunExec, daprLogFilePath string) {
// If the provided path is a path to a YAML file then return the same.
// Else it returns the path of "dapr.yaml" in the provided directory.
func getRunFilePath(path string) (string, error) {
if path == "-" {
return path, nil // will be read from stdin later.
}
fileInfo, err := os.Stat(path)
if err != nil {
return "", fmt.Errorf("error getting file info for %s: %w", path, err)
Expand Down
7 changes: 7 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ func ResolveHomeDir(filePath string) (string, error) {
}

func ReadFile(filePath string) ([]byte, error) {
if filePath == "-" {
bytes, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, fmt.Errorf("error in reading the provided app config from stdin: %w", err)
}
return bytes, nil
}
bytes, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("error in reading the provided app config file: %w", err)
Expand Down

0 comments on commit 5a04ffd

Please sign in to comment.