Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
version: latest
skip-build-cache: true
skip-pkg-cache: true
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
linters:
fast: true
enable:
- golint
- revive
- govet
- gosimple
- goconst
- goimports
- staticcheck
disable:
- errcheck

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions ensure_kill.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package main
Expand Down
1 change: 1 addition & 0 deletions ensure_kill_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package main
Expand Down
14 changes: 10 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
27 changes: 14 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
138 changes: 91 additions & 47 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,114 @@ 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 (
conf hivemindConfig
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 = "[email protected]"
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: "[email protected]",
},
},
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)
Expand Down