Skip to content

Commit

Permalink
Move cli to a different folder so Godoc works for the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes committed Jun 22, 2018
1 parent a2fa6af commit 18ea15a
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 304 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,7 +1,9 @@
# binaries
*.exe
gaper
/gaper
srv
vendor
coverage.out
.DS_Store
testdata/server/server
dist
2 changes: 1 addition & 1 deletion .goreleaser.yml
@@ -1,5 +1,5 @@
builds:
- main: main.go
- main: ./cmd/gaper/main.go
binary: gaper
goos:
- windows
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -7,10 +7,12 @@ go:
- 1.10.x
# - master

script:
before_script:
- go version
- make setup
- make lint

script:
- make test

after_success:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -19,7 +19,7 @@ ifndef LINTER
endif

build:
@go build .
@go build -o ./gaper cmd/gaper/main.go

## lint: Validate golang code
lint:
Expand All @@ -30,7 +30,7 @@ lint:
--vendor ./...

test:
@go test -v -coverpkg $(COVER_PACKAGES) \
@go test -p=1 -coverpkg $(COVER_PACKAGES) \
-covermode=atomic -coverprofile=coverage.out $(TEST_PACKAGES)

cover: test
Expand Down
39 changes: 21 additions & 18 deletions README.md
Expand Up @@ -2,7 +2,8 @@
<img width="200px" src="https://raw.githubusercontent.com/maxcnunes/gaper/master/gopher-gaper.png">
<h3 align="center">gaper</h3>
<p align="center">
Restarts programs when they crash or a watched file changes.<br />
Used to build and restart a Go project when it crashes or some watched file changes
<br />
<b>Aimed to be used in development only.</b>
</p>
</p>
Expand All @@ -20,7 +21,7 @@
## Installation

```
go get -u github.com/maxcnunes/gaper
go get -u github.com/maxcnunes/gaper/cmd/gaper
```

## Changelog
Expand All @@ -31,32 +32,34 @@ See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history

```
NAME:
gaper - Used to restart programs when they crash or a watched file changes
gaper - Used to build and restart a Go project when it crashes or some watched file changes
USAGE:
gaper [global options] command [command options] [arguments...]
VERSION:
0.0.0
version
COMMANDS:
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--bin-name value name for the binary built by Gaper for the executed program
--build-path value path to the program source code
--build-args value build arguments passed to the program
--verbose turns on the verbose messages from Gaper
--watch value, -w value list of folders or files to watch for changes
--ignore value, -i value list of folders or files to ignore for changes
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
--extensions value, -e value a comma-delimited list of file extensions to watch for changes (default: "go")
--no-restart-on value, -n value don't automatically restart the executed program if it ends:
if "error", an exit code of 0 will still restart.
if "exit", no restart regardless of exit code.
if "success", no restart only if exit code is 0.
--help, -h show help
--version, -v print the version
--bin-name value name for the binary built by gaper for the executed program (default current directory name)
--build-path value path to the program source code (default: ".")
--build-args value arguments used on building the program
--program-args value arguments used on executing the program
--verbose turns on the verbose messages from gaper
--watch value, -w value list of folders or files to watch for changes
--ignore value, -i value list of folders or files to ignore for changes
(always ignores all hidden files and directories)
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
--extensions value, -e value a comma-delimited list of file extensions to watch for changes (default: "go")
--no-restart-on value, -n value don't automatically restart the supervised program if it ends:
if "error", an exit code of 0 will still restart.
if "exit", no restart regardless of exit code.
if "success", no restart only if exit code is 0.
--help, -h show help
--version, -v print the version
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion builder.go
@@ -1,4 +1,4 @@
package main
package gaper

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion builder_test.go
@@ -1,4 +1,4 @@
package main
package gaper

import (
"os"
Expand Down
107 changes: 107 additions & 0 deletions cmd/gaper/main.go
@@ -0,0 +1,107 @@
package main

import (
"os"

"github.com/maxcnunes/gaper"
"github.com/urfave/cli"
)

// build info
var (
version = "dev"
)

var logger = gaper.NewLogger("gaper")

func main() {
parseArgs := func(c *cli.Context) *gaper.Config {
return &gaper.Config{
BinName: c.String("bin-name"),
BuildPath: c.String("build-path"),
BuildArgsMerged: c.String("build-args"),
ProgramArgsMerged: c.String("program-args"),
Verbose: c.Bool("verbose"),
WatchItems: c.StringSlice("watch"),
IgnoreItems: c.StringSlice("ignore"),
PollInterval: c.Int("poll-interval"),
Extensions: c.StringSlice("extensions"),
NoRestartOn: c.String("no-restart-on"),
ExitOnSIGINT: true,
}
}

app := cli.NewApp()
app.Name = "gaper"
app.Usage = "Used to build and restart a Go project when it crashes or some watched file changes"
app.Version = version

app.Action = func(c *cli.Context) {
args := parseArgs(c)
if err := gaper.Run(args); err != nil {
logger.Error(err)
os.Exit(1)
}
}

exts := make(cli.StringSlice, len(gaper.DefaultExtensions))
for i := range gaper.DefaultExtensions {
exts[i] = gaper.DefaultExtensions[i]
}

// supported arguments
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "bin-name",
Usage: "name for the binary built by gaper for the executed program (default current directory name)",
},
cli.StringFlag{
Name: "build-path",
Value: gaper.DefaultBuildPath,
Usage: "path to the program source code",
},
cli.StringFlag{
Name: "build-args",
Usage: "arguments used on building the program",
},
cli.StringFlag{
Name: "program-args",
Usage: "arguments used on executing the program",
},
cli.BoolFlag{
Name: "verbose",
Usage: "turns on the verbose messages from gaper",
},
cli.StringSliceFlag{
Name: "watch, w",
Usage: "list of folders or files to watch for changes",
},
cli.StringSliceFlag{
Name: "ignore, i",
Usage: "list of folders or files to ignore for changes\n" +
"\t\t(always ignores all hidden files and directories)",
},
cli.IntFlag{
Name: "poll-interval, p",
Value: gaper.DefaultPoolInterval,
Usage: "how often in milliseconds to poll watched files for changes",
},
cli.StringSliceFlag{
Name: "extensions, e",
Value: &exts,
Usage: "a comma-delimited list of file extensions to watch for changes",
},
cli.StringFlag{
Name: "no-restart-on, n",
Usage: "don't automatically restart the supervised program if it ends:\n" +
"\t\tif \"error\", an exit code of 0 will still restart.\n" +
"\t\tif \"exit\", no restart regardless of exit code.\n" +
"\t\tif \"success\", no restart only if exit code is 0.",
},
}

if err := app.Run(os.Args); err != nil {
logger.Errorf("Error running gaper: %v", err)
os.Exit(1)
}
}

0 comments on commit 18ea15a

Please sign in to comment.