diff --git a/builder.go b/builder.go index f4cf1ba..28e1bbf 100644 --- a/builder.go +++ b/builder.go @@ -8,7 +8,7 @@ import ( "strings" ) -// Builder ... +// Builder is a interface for the build process type Builder interface { Build() error Binary() string @@ -22,7 +22,7 @@ type builder struct { buildArgs []string } -// NewBuilder ... +// NewBuilder creates a new builder func NewBuilder(dir string, bin string, wd string, buildArgs []string) Builder { // resolve bin name by current folder name if bin == "" { @@ -40,12 +40,12 @@ func NewBuilder(dir string, bin string, wd string, buildArgs []string) Builder { return &builder{dir: dir, binary: bin, wd: wd, buildArgs: buildArgs} } -// Binary ... +// Binary returns its build binary's path func (b *builder) Binary() string { return b.binary } -// Build ... +// Build the Golang project set for this builder func (b *builder) Build() error { logger.Info("Building program") args := append([]string{"go", "build", "-o", filepath.Join(b.wd, b.binary)}, b.buildArgs...) diff --git a/loggger.go b/loggger.go index 9616151..7029a88 100644 --- a/loggger.go +++ b/loggger.go @@ -7,62 +7,55 @@ import ( "github.com/fatih/color" ) -// Logger .. +// Logger used by gaper type Logger struct { verbose bool logDebug *log.Logger - logWarn *log.Logger logInfo *log.Logger logError *log.Logger } -// NewLogger ... +// NewLogger creates a new logger func NewLogger(prefix string) *Logger { prefix = "[" + prefix + "] " return &Logger{ verbose: false, logDebug: log.New(os.Stdout, prefix, 0), - logWarn: log.New(os.Stdout, color.YellowString(prefix), 0), logInfo: log.New(os.Stdout, color.CyanString(prefix), 0), logError: log.New(os.Stdout, color.RedString(prefix), 0), } } -// Verbose ... +// Verbose toggle this logger verbosity func (l *Logger) Verbose(verbose bool) { l.verbose = verbose } -// Debug ... +// Debug logs a debug message func (l *Logger) Debug(v ...interface{}) { if l.verbose { l.logDebug.Println(v...) } } -// Debugf ... +// Debugf logs a debug message with format func (l *Logger) Debugf(format string, v ...interface{}) { if l.verbose { l.logDebug.Printf(format, v...) } } -// Warn ... -func (l *Logger) Warn(v ...interface{}) { - l.logWarn.Println(v...) -} - -// Info ... +// Info logs a info message func (l *Logger) Info(v ...interface{}) { l.logInfo.Println(v...) } -// Error ... +// Error logs an error message func (l *Logger) Error(v ...interface{}) { l.logError.Println(v...) } -// Errorf ... +// Errorf logs and error message with format func (l *Logger) Errorf(format string, v ...interface{}) { l.logError.Printf(format, v...) } diff --git a/main.go b/main.go index 825ab99..cc86352 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,5 @@ +// Package gaper implements a supervisor restarts a go project +// when it crashes or a watched file changes package main import ( @@ -19,7 +21,7 @@ var logger = NewLogger("gaper") var exitStatusSuccess = 0 var exitStatusError = 1 -// Config ... +// Config contains all settings supported by gaper type Config struct { BinName string BuildPath string diff --git a/main_test.go b/main_test.go index a7063b3..f0c3559 100644 --- a/main_test.go +++ b/main_test.go @@ -1,10 +1,9 @@ package main import ( - "fmt" "testing" ) func TestGaper(t *testing.T) { - fmt.Println("Sample test") + // TODO: add test to main file } diff --git a/runner.go b/runner.go index 8dec508..590f8f7 100644 --- a/runner.go +++ b/runner.go @@ -10,13 +10,13 @@ import ( "time" ) -// OSWindows ... +// OSWindows is used to check if current OS is a Windows const OSWindows = "windows" // os errors var errFinished = errors.New("os: process already finished") -// Runner ... +// Runner is a interface for the run process type Runner interface { Run() (*exec.Cmd, error) Kill() error @@ -35,7 +35,7 @@ type runner struct { end chan bool // used internally by Kill to wait a process die } -// NewRunner ... +// NewRunner creates a new runner func NewRunner(wStdout io.Writer, wStderr io.Writer, bin string, args []string) Runner { return &runner{ bin: bin, @@ -48,7 +48,7 @@ func NewRunner(wStdout io.Writer, wStderr io.Writer, bin string, args []string) } } -// Run ... +// Run executes the project binary func (r *runner) Run() (*exec.Cmd, error) { logger.Info("Starting program") @@ -63,7 +63,7 @@ func (r *runner) Run() (*exec.Cmd, error) { return r.command, nil } -// Kill ... +// Kill the current process running for the Golang project func (r *runner) Kill() error { if r.command == nil || r.command.Process == nil { return nil @@ -97,12 +97,12 @@ func (r *runner) Kill() error { return nil } -// Exited ... +// Exited checks if the process has exited func (r *runner) Exited() bool { return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited() } -// Errors ... +// Errors get errors occurred during the build func (r *runner) Errors() chan error { return r.errors } diff --git a/watcher.go b/watcher.go index f7f29e9..d125250 100644 --- a/watcher.go +++ b/watcher.go @@ -16,7 +16,7 @@ var DefaultExtensions = []string{"go"} // DefaultPoolInterval used by the watcher var DefaultPoolInterval = 500 -// Watcher ... +// Watcher is a interface for the watch process type Watcher struct { PollInterval int WatchItems []string @@ -26,7 +26,7 @@ type Watcher struct { Errors chan error } -// NewWatcher ... +// NewWatcher creates a new watcher func NewWatcher(pollInterval int, watchItems []string, ignoreItems []string, extensions []string) (*Watcher, error) { if pollInterval == 0 { pollInterval = DefaultPoolInterval @@ -64,7 +64,7 @@ func NewWatcher(pollInterval int, watchItems []string, ignoreItems []string, ext var startTime = time.Now() var errDetectedChange = errors.New("done") -// Watch ... +// Watch starts watching for file changes func (w *Watcher) Watch() { for { for i := range w.WatchItems {