summaryrefslogtreecommitdiffstats
path: root/pkg/app
diff options
context:
space:
mode:
authorMark Kopenga <mkopenga@gmail.com>2018-08-14 11:05:26 +0200
committerMark Kopenga <mkopenga@gmail.com>2018-08-14 11:05:26 +0200
commitdfafb988713a79664139d15ad471736a5a4b1b90 (patch)
treeebde4bd5c64ce8e1fe5e8670657c708984b0e8ff /pkg/app
parentf2dfcb6e12d78f3e7b890d5bd43be7b032e1df88 (diff)
tried to update to latest master
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/app.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
new file mode 100644
index 000000000..d558ed250
--- /dev/null
+++ b/pkg/app/app.go
@@ -0,0 +1,71 @@
+package app
+
+import (
+ "io"
+ "io/ioutil"
+ "os"
+
+ "github.com/Sirupsen/logrus"
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/config"
+ "github.com/jesseduffield/lazygit/pkg/gui"
+)
+
+// App struct
+type App struct {
+ closers []io.Closer
+
+ Config config.AppConfigurer
+ Log *logrus.Logger
+ OSCommand *commands.OSCommand
+ GitCommand *commands.GitCommand
+ Gui *gui.Gui
+}
+
+func newLogger(config config.AppConfigurer) *logrus.Logger {
+ log := logrus.New()
+ if !config.GetDebug() {
+ log.Out = ioutil.Discard
+ return log
+ }
+ file, err := os.OpenFile("development.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
+ if err != nil {
+ panic("unable to log to file") // TODO: don't panic (also, remove this call to the `panic` function)
+ }
+ log.SetOutput(file)
+ return log
+}
+
+// NewApp retruns a new applications
+func NewApp(config config.AppConfigurer) (*App, error) {
+ app := &App{
+ closers: []io.Closer{},
+ Config: config,
+ }
+ var err error
+ app.Log = newLogger(config)
+ app.OSCommand, err = commands.NewOSCommand(app.Log)
+ if err != nil {
+ return nil, err
+ }
+ app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand)
+ if err != nil {
+ return nil, err
+ }
+ app.Gui, err = gui.NewGui(app.Log, app.GitCommand, app.OSCommand, config.GetVersion())
+ if err != nil {
+ return nil, err
+ }
+ return app, nil
+}
+
+// Close closes any resources
+func (app *App) Close() error {
+ for _, closer := range app.closers {
+ err := closer.Close()
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}