Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cli to a different folder so Godoc works for the rest
- Loading branch information
Showing
17 changed files
with
350 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
# binaries | ||
*.exe | ||
gaper | ||
/gaper | ||
srv | ||
vendor | ||
coverage.out | ||
.DS_Store | ||
testdata/server/server | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
builds: | ||
- main: main.go | ||
- main: ./cmd/gaper/main.go | ||
binary: gaper | ||
goos: | ||
- windows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package gaper | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package gaper | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Oops, something went wrong.