summaryrefslogtreecommitdiff
path: root/main.go
blob: ebe6583e17ff909a2b0cd9bdf14183122f2c3454 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"os"

	"github.com/isacikgoz/gitbatch/app"
	log "github.com/sirupsen/logrus"
	kingpin "gopkg.in/alecthomas/kingpin.v2"
)

var (
	dirs         = kingpin.Flag("directory", "Directory(s) to roam for git repositories.").Short('d').Strings()
	mode         = kingpin.Flag("mode", "Application start mode, more sensible with quick run.").Short('m').String()
	recurseDepth = kingpin.Flag("recursive-depth", "Find directories recursively.").Default("0").Short('r').Int()
	logLevel     = kingpin.Flag("log-level", "Logging level; trace,debug,info,warn,error").Default("error").Short('l').String()
	quick        = kingpin.Flag("quick", "runs without gui and fetches/pull remote upstream.").Short('q').Bool()
)

func main() {
	kingpin.Version("gitbatch version 0.3.0")
	// parse the command line flag and options
	kingpin.Parse()

	if err := run(); err != nil {
		log.WithFields(log.Fields{
			"error": err.Error(),
		}).Error("Application quitted with an unhandled error.")
		os.Exit(1)
	}
}

func run() error {
	// set the app
	app, err := app.Setup(&app.SetupConfig{
		Directories: *dirs,
		LogLevel:    *logLevel,
		Depth:       *recurseDepth,
		QuickMode:   *quick,
		Mode:        *mode,
	})
	if err != nil {
		return err
	}

	// good citizens always clean up their mess
	defer app.Close()

	// execute the app and wait its routine
	return app.Gui.Run()
}