diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..16adc1f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: main + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.21 + - name: Build + run: go build + + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: lint + uses: golangci/golangci-lint-action@v2.5.2 + with: + version: latest + skip-build-cache: true + skip-pkg-cache: true diff --git a/.golangci.yml b/.golangci.yml index 502b2c2..9a6978b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ linters: fast: true enable: - - golint + - revive - govet - gosimple - goconst @@ -9,4 +9,3 @@ linters: - staticcheck disable: - errcheck - diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0764dec..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go -go: - - "1.11.13" - - "1.12" - - "1.13" -env: - - GO111MODULE=on -install: - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.20.0 -script: - - go mod download - - golangci-lint run - - go build diff --git a/ensure_kill.go b/ensure_kill.go index e9f2efe..d502956 100644 --- a/ensure_kill.go +++ b/ensure_kill.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package main diff --git a/ensure_kill_linux.go b/ensure_kill_linux.go index e4b6e29..42744f5 100644 --- a/ensure_kill_linux.go +++ b/ensure_kill_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package main diff --git a/go.mod b/go.mod index 1ac0696..5bb6aea 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,17 @@ module github.com/DarthSim/hivemind -go 1.12 +go 1.21 require ( github.com/DarthSim/godotenv v1.3.1 - github.com/joho/godotenv v1.4.0 // indirect github.com/pkg/term v1.2.0-beta.2 - github.com/urfave/cli v1.22.5 - golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect + github.com/urfave/cli/v2 v2.25.7 +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/joho/godotenv v1.5.1 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index f723e8d..c81a7a4 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,23 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DarthSim/godotenv v1.3.1 h1:NMWdswlRx2M9uPY4Ux8p/Q/rDs7A97OG89fECiQ/Tz0= github.com/DarthSim/godotenv v1.3.1/go.mod h1:B3ySe1HYTUFFR6+TPyHyxPWjUdh48il0Blebg9p1cCc= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= -github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/main.go b/main.go index 7c2bf58..f7ba69d 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,12 @@ import ( "os" "path/filepath" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" _ "github.com/DarthSim/godotenv/autoload" ) -const version = "1.1.0" +const version = "1.2.0" func main() { var ( @@ -17,57 +17,101 @@ func main() { err error ) - app := cli.NewApp() - - app.Name = "Hivemind" - app.HelpName = "hivemind" - app.Usage = "The mind to rule processes of your development environment" - app.Description = "Hivemind is a process manager for Procfile-based applications" - app.Author = "Sergey \"DarthSim\" Alexandrovich" - app.Email = "darthsim@gmail.com" - app.Version = version - app.ArgsUsage = "[procfile] (Use '-' to read from stdin, Procfile path can be also set with $HIVEMIND_PROCFILE)" - app.HideHelp = true - - app.Flags = []cli.Flag{ - cli.StringFlag{Name: "title, w", EnvVar: "HIVEMIND_TITLE", Usage: "Specify a title of the application", Destination: &conf.Title}, - cli.StringFlag{Name: "processes, l", EnvVar: "HIVEMIND_PROCESSES", Usage: "Specify process names to launch. Divide names with comma", Destination: &conf.ProcNames}, - cli.IntFlag{Name: "port, p", EnvVar: "HIVEMIND_PORT,PORT", Usage: "specify a port to use as the base", Value: 5000, Destination: &conf.PortBase}, - cli.IntFlag{Name: "port-step, P", EnvVar: "HIVEMIND_PORT_STEP", Usage: "specify a step to increase port number", Value: 100, Destination: &conf.PortStep}, - cli.StringFlag{Name: "root, d", EnvVar: "HIVEMIND_ROOT", Usage: "specify a working directory of application. Default: directory containing the Procfile", Destination: &conf.Root}, - cli.IntFlag{Name: "timeout, t", EnvVar: "HIVEMIND_TIMEOUT", Usage: "specify the amount of time (in seconds) processes have to shut down gracefully before being brutally killed", Value: 5, Destination: &conf.Timeout}, - cli.BoolFlag{Name: "no-prefix", EnvVar: "HIVEMIND_NO_PREFIX", Usage: "process names will not be printed if the flag is specified", Destination: &conf.NoPrefix}, - cli.BoolFlag{Name: "print-timestamps, T", EnvVar: "HIVEMIND_PRINT_TIMESTAMPS", Usage: "timestamps will be printed if the flag is specified", Destination: &conf.PrintTimestamps}, - } - - app.Action = func(c *cli.Context) error { - switch c.NArg() { - case 0: - if path := os.Getenv("HIVEMIND_PROCFILE"); len(path) > 0 { - conf.Procfile = path - } else { - conf.Procfile = "./Procfile" + app := &cli.App{ + Name: "Hivemind", + HelpName: "hivemind", + Usage: "The mind to rule processes of your development environment", + Authors: []*cli.Author{ + { + Name: "Sergey \"DarthSim\" Alexandrovich", + Email: "darthsim@gmail.com", + }, + }, + Version: version, + ArgsUsage: "[procfile] (Use '-' to read from stdin, Procfile path can be also set with $HIVEMIND_PROCFILE)", + HideHelp: true, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "title, w", + EnvVars: []string{"HIVEMIND_TITLE"}, + Usage: "Specify a title of the application", + Destination: &conf.Title, + }, + &cli.StringFlag{ + Name: "processes, l", + EnvVars: []string{"HIVEMIND_PROCESSES"}, + Usage: "Specify process names to launch. Divide names with comma", + Destination: &conf.ProcNames, + }, + &cli.IntFlag{ + Name: "port, p", + EnvVars: []string{"HIVEMIND_PORT,PORT"}, + Usage: "specify a port to use as the base", + Value: 5000, + Destination: &conf.PortBase, + }, + &cli.IntFlag{ + Name: "port-step, P", + EnvVars: []string{"HIVEMIND_PORT_STEP"}, + Usage: "specify a step to increase port number", + Value: 100, + Destination: &conf.PortStep, + }, + &cli.StringFlag{ + Name: "root, d", + EnvVars: []string{"HIVEMIND_ROOT"}, + Usage: "specify a working directory of application. Default: directory containing the Procfile", + Destination: &conf.Root, + }, + &cli.IntFlag{ + Name: "timeout, t", + EnvVars: []string{"HIVEMIND_TIMEOUT"}, + Usage: "specify the amount of time (in seconds) processes have to shut down gracefully before being brutally killed", + Value: 5, + Destination: &conf.Timeout, + }, + &cli.BoolFlag{ + Name: "no-prefix", + EnvVars: []string{"HIVEMIND_NO_PREFIX"}, + Usage: "process names will not be printed if the flag is specified", + Destination: &conf.NoPrefix, + }, + &cli.BoolFlag{ + Name: "print-timestamps, T", + EnvVars: []string{"HIVEMIND_PRINT_TIMESTAMPS"}, + Usage: "timestamps will be printed if the flag is specified", + Destination: &conf.PrintTimestamps, + }, + }, + Action: func(c *cli.Context) error { + switch c.NArg() { + case 0: + if path := os.Getenv("HIVEMIND_PROCFILE"); len(path) > 0 { + conf.Procfile = path + } else { + conf.Procfile = "./Procfile" + } + case 1: + conf.Procfile = c.Args().First() + default: + fatal("Specify a single procfile") } - case 1: - conf.Procfile = c.Args().First() - default: - fatal("Specify a single procfile") - } - if conf.Timeout < 1 { - fatal("Timeout should be greater than 0") - } + if conf.Timeout < 1 { + fatal("Timeout should be greater than 0") + } - if len(conf.Root) == 0 { - conf.Root = filepath.Dir(conf.Procfile) - } + if len(conf.Root) == 0 { + conf.Root = filepath.Dir(conf.Procfile) + } - conf.Root, err = filepath.Abs(conf.Root) - fatalOnErr(err) + conf.Root, err = filepath.Abs(conf.Root) + fatalOnErr(err) - newHivemind(conf).Run() + newHivemind(conf).Run() - return nil + return nil + }, } app.Run(os.Args)