mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 15:11:02 +00:00
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
|
"github.com/jesseduffield/lazydocker/pkg/gui"
|
|
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
|
"github.com/jesseduffield/lazydocker/pkg/log"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
closers []io.Closer
|
|
|
|
Config *config.AppConfig
|
|
Log *logrus.Entry
|
|
OSCommand *commands.OSCommand
|
|
DockerCommand *commands.DockerCommand
|
|
Gui *gui.Gui
|
|
Tr *i18n.TranslationSet
|
|
ErrorChan chan error
|
|
}
|
|
|
|
// NewApp bootstrap a new application
|
|
func NewApp(config *config.AppConfig) (*App, error) {
|
|
app := &App{
|
|
closers: []io.Closer{},
|
|
Config: config,
|
|
ErrorChan: make(chan error),
|
|
}
|
|
var err error
|
|
app.Log = log.NewLogger(config, "23432119147a4367abf7c0de2aa99a2d")
|
|
app.Tr = i18n.NewTranslationSet(app.Log)
|
|
app.OSCommand = commands.NewOSCommand(app.Log, config)
|
|
|
|
// here is the place to make use of the docker-compose.yml file in the current directory
|
|
|
|
app.DockerCommand, err = commands.NewDockerCommand(app.Log, app.OSCommand, app.Tr, app.Config, app.ErrorChan)
|
|
if err != nil {
|
|
return app, err
|
|
}
|
|
app.Gui, err = gui.NewGui(app.Log, app.DockerCommand, app.OSCommand, app.Tr, config, app.ErrorChan)
|
|
if err != nil {
|
|
return app, err
|
|
}
|
|
return app, nil
|
|
}
|
|
|
|
func (app *App) Run() error {
|
|
return app.Gui.RunWithSubprocesses()
|
|
}
|
|
|
|
// Close closes any resources
|
|
func (app *App) Close() error {
|
|
for _, closer := range app.closers {
|
|
err := closer.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|