diff --git a/.gitignore b/.gitignore index fe8ad27..23ca264 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea *.pem *.log +bin docker\-compose.yml airtmp/ build/ diff --git a/cmd/roadmapper/main.go b/cmd/roadmapper/main.go index 0993377..edd530b 100644 --- a/cmd/roadmapper/main.go +++ b/cmd/roadmapper/main.go @@ -1,9 +1,12 @@ package main import ( + "bufio" "fmt" + "io/ioutil" "math/rand" "os" + "strings" "time" _ "github.com/lib/pq" @@ -107,11 +110,17 @@ func createCLICommand(logger *zap.Logger) *cli.Command { &cli.StringFlag{Name: "markToday", Usage: "weather or not to add a line to mark the current day", Value: "", EnvVars: []string{"MARK_TODAY"}}, }, Action: func(c *cli.Context) error { + content, err := readContent(c.String("input")) + if err != nil { + logger.Error("failed to render roadmap", zap.Error(err)) + return err + } + io := roadmap.NewIO() - err := Render( + err = Render( io, logger, - c.String("input"), + content, c.String("output"), c.String("formatFile"), c.String("dateFormat"), @@ -129,6 +138,24 @@ func createCLICommand(logger *zap.Logger) *cli.Command { } } +func readContent(input string) (string, error) { + if input != "" { + content, err := ioutil.ReadFile(input) + if err != nil { + return "", err + } + return string(content), nil + } + + lines := []string{} + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + + return strings.Join(lines, "\n"), nil +} + func createVersionCommand() *cli.Command { return &cli.Command{ Name: "version",