Skip to content

Commit

Permalink
wtc as a package
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsq committed Oct 23, 2019
1 parent 3f94959 commit efaf33b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/rafaelsq/wtc/pkg/wtc"
)

func main() {
wtc.Start(wtc.ParseArgs())
}
2 changes: 1 addition & 1 deletion config.go → pkg/wtc/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package wtc

// Config defines the options for watching files
type Config struct {
Expand Down
13 changes: 7 additions & 6 deletions pkg/wtc/wtc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package wtc

import (
"context"
Expand Down Expand Up @@ -42,7 +42,7 @@ func getContext(label string) (context.Context, context.CancelFunc) {

var config *Config

func main() {
func ParseArgs() *Config {
flag.CommandLine.Usage = func() {
fmt.Fprintf(
flag.CommandLine.Output(),
Expand All @@ -53,7 +53,7 @@ func main() {
flag.PrintDefaults()
}

config = &Config{Debounce: 300}
config := &Config{Debounce: 300}

flag.IntVar(&config.Debounce, "debounce", 300, "global debounce")
flag.StringVar(&config.Ignore, "ignore", "", "regex")
Expand All @@ -66,7 +66,7 @@ func main() {
} else if !has && flag.NArg() < 2 {
fmt.Fprintf(os.Stderr, "No [.]wtc.yaml or valid command provided.\n")
flag.CommandLine.Usage()
return
return nil
} else if !has {
config.Rules = append(config.Rules, &Rule{
Name: "run",
Expand All @@ -75,12 +75,13 @@ func main() {
})
}

start(config)
return config
}

func start(config *Config) {
func Start(cfg *Config) {
var cancelAll context.CancelFunc

config = cfg
appContext, cancelAll = context.WithCancel(context.Background())
contexts = make(map[string]context.CancelFunc)
contextsLock = make(map[string]chan struct{})
Expand Down

0 comments on commit efaf33b

Please sign in to comment.