Support read data from stdin

This commit is contained in:
Hang Yan
2018-08-09 22:46:41 +08:00
parent 0252213efb
commit a012fba1c2
6 changed files with 79 additions and 20 deletions
+16
View File
@@ -17,6 +17,7 @@ limitations under the License.
package compose
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -115,3 +116,18 @@ func handleServiceType(ServiceType string) (string, error) {
func normalizeServiceNames(svcName string) string {
return strings.Replace(svcName, "_", "-", -1)
}
// ReadFile read data from file or stdin
func ReadFile(fileName string) ([]byte, error) {
if fileName == "-" {
if StdinData == nil {
data, err := ioutil.ReadAll(os.Stdin)
StdinData = data
return data, err
} else {
return StdinData, nil
}
}
return ioutil.ReadFile(fileName)
}