Skip to content

Commit

Permalink
Merge pull request #14 from fujiwara/dry-run
Browse files Browse the repository at this point in the history
Add -dry-run mode.
  • Loading branch information
fujiwara committed Mar 18, 2021
2 parents 67b760f + d76d6ba commit e076044
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion cmd/rin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
showVersion bool
batchMode bool
debug bool
dryRun bool
)
flag.StringVar(&config, "config", "config.yaml", "config file path")
flag.StringVar(&config, "c", "config.yaml", "config file path")
Expand All @@ -30,6 +31,7 @@ func main() {
flag.BoolVar(&showVersion, "v", false, "show version")
flag.BoolVar(&batchMode, "batch", false, "batch mode")
flag.BoolVar(&batchMode, "b", false, "batch mode")
flag.BoolVar(&dryRun, "dry-run", false, "dry run mode (load configuration only)")
flag.Parse()

if showVersion {
Expand All @@ -50,7 +52,11 @@ func main() {
log.SetOutput(filter)
log.Println("[info] rin version:", version)

if err := rin.Run(config, batchMode); err != nil {
run := rin.Run
if dryRun {
run = rin.DryRun
}
if err := run(config, batchMode); err != nil {
log.Println("[error]", err)
os.Exit(1)
}
Expand Down
11 changes: 10 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ type SQLParam struct {
}

func (t *Target) String() string {
return strings.Join([]string{t.S3.String(), t.Redshift.String()}, " => ")
var s string
if t.Discard {
s = strings.Join([]string{t.S3.String(), "Discard"}, " => ")
} else {
s = strings.Join([]string{t.S3.String(), t.Redshift.String()}, " => ")
}
if t.Break {
s = s + " => Break"
}
return s
}

func (t *Target) Match(bucket, key string) (bool, *[]string) {
Expand Down
13 changes: 13 additions & 0 deletions rin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func (e NoMessageError) Error() string {
return e.s
}

func DryRun(configFile string, batchMode bool) error {
var err error
log.Println("[info] Loading config:", configFile)
config, err = LoadConfig(configFile)
if err != nil {
return err
}
for _, target := range config.Targets {
log.Println("[info] Define target", target.String())
}
return nil
}

func Run(configFile string, batchMode bool) error {
return RunWithContext(context.Background(), configFile, batchMode)
}
Expand Down

0 comments on commit e076044

Please sign in to comment.