From 08d0ecce78272d54696864a0ed9f1cee228c5792 Mon Sep 17 00:00:00 2001 From: catatsuy Date: Wed, 20 Mar 2024 17:32:46 +0900 Subject: [PATCH] Add check for input file in CLI Run method --- cli/cli.go | 4 ++++ go.mod | 5 +++++ go.sum | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index d5fc244..931a1e7 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -15,6 +15,7 @@ import ( "github.com/catatsuy/notify_slack/config" "github.com/catatsuy/notify_slack/slack" "github.com/catatsuy/notify_slack/throttle" + "golang.org/x/term" ) var ( @@ -106,6 +107,9 @@ func (c *CLI) Run(args []string) int { fmt.Fprintln(c.errStream, "You cannot pass multiple files") return ExitCodeParseFlagError } + } else if term.IsTerminal(int(os.Stdin.Fd())) { + fmt.Fprintln(c.errStream, "No input file specified") + return ExitCodeFail } tomlFile = config.LoadTOMLFilename(tomlFile) diff --git a/go.mod b/go.mod index b9673f6..c2ef506 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,8 @@ module github.com/catatsuy/notify_slack go 1.19 require github.com/pelletier/go-toml/v2 v2.2.0 + +require ( + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect +) diff --git a/go.sum b/go.sum index 1422472..3cdeb39 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=