clean some things up

pull/1/head
Jesse Duffield 5 years ago
parent b65df625f4
commit 5d55939719

@ -20,7 +20,7 @@ type App struct {
OSCommand *commands.OSCommand
DockerCommand *commands.DockerCommand
Gui *gui.Gui
Tr i18n.TranslationSet
Tr *i18n.TranslationSet
ErrorChan chan error
}

@ -36,17 +36,21 @@ type Container struct {
Details Details
MonitoringStats bool
}
// RecordedStats contains both the container stats we've received from docker, and our own derived stats from those container stats. When configuring a graph, you're basically specifying the path of a value in this struct
type RecordedStats struct {
ClientStats ContainerStats
DerivedStats DerivedStats
RecordedAt time.Time
}
// DerivedStats contains some useful stats that we've calculated based on the raw container stats that we got back from docker
type DerivedStats struct {
CPUPercentage float64
MemoryPercentage float64
}
// Details is a struct containing what we get back from `docker inspect` on a container
type Details struct {
ID string `json:"Id"`
Created time.Time `json:"Created"`

@ -24,7 +24,7 @@ import (
type DockerCommand struct {
Log *logrus.Entry
OSCommand *OSCommand
Tr i18n.TranslationSet
Tr *i18n.TranslationSet
Config *config.AppConfig
Client *client.Client
InDockerComposeProject bool
@ -39,7 +39,7 @@ type DockerCommand struct {
}
// NewDockerCommand it runs git commands
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
cli, err := client.NewEnvClient()
if err != nil {
return nil, err
@ -56,6 +56,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr i18n.Translati
}, nil
}
// MonitorContainerStats is a function
func (c *DockerCommand) MonitorContainerStats() {
go c.MonitorCLIContainerStats()
go c.MonitorClientContainerStats()
@ -98,6 +99,7 @@ func (c *DockerCommand) MonitorCLIContainerStats() {
return
}
// MonitorClientContainerStats is a function
func (c *DockerCommand) MonitorClientContainerStats() {
// periodically loop through running containers and see if we need to create a monitor goroutine for any
// every second we check if we need to spawn a new goroutine

@ -31,12 +31,14 @@ type ComplexError struct {
frame xerrors.Frame
}
// FormatError is a function
func (ce ComplexError) FormatError(p xerrors.Printer) error {
p.Printf("%d %s", ce.Code, ce.Message)
ce.frame.Format(p)
return nil
}
// Format is a function
func (ce ComplexError) Format(f fmt.State, c rune) {
xerrors.FormatError(ce, f, c)
}
@ -45,6 +47,7 @@ func (ce ComplexError) Error() string {
return fmt.Sprint(ce)
}
// HasErrorCode is a function
func HasErrorCode(err error, code int) bool {
var originalErr ComplexError
if xerrors.As(err, &originalErr) {

@ -59,7 +59,7 @@ type Gui struct {
SubProcess *exec.Cmd
State guiState
Config *config.AppConfig
Tr i18n.TranslationSet
Tr *i18n.TranslationSet
Errors SentinelErrors
statusManager *statusManager
waitForIntro sync.WaitGroup
@ -113,7 +113,7 @@ type guiState struct {
}
// NewGui builds a new gui handler
func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand *commands.OSCommand, tr i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*Gui, error) {
func NewGui(log *logrus.Entry, dockerCommand *commands.DockerCommand, oSCommand *commands.OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*Gui, error) {
initialState := guiState{
PreviousView: "services",

@ -17,7 +17,7 @@ type Localizer struct {
}
// NewTranslationSet creates a new Localizer
func NewTranslationSet(log *logrus.Entry) TranslationSet {
func NewTranslationSet(log *logrus.Entry) *TranslationSet {
userLang := detectLanguage(jibber_jabber.DetectLanguage)
log.Info("language: " + userLang)
@ -34,7 +34,7 @@ func NewTranslationSet(log *logrus.Entry) TranslationSet {
mergo.Merge(&set, polishSet(), mergo.WithOverride)
}
return set
return &set
}
// detectLanguage extracts user language from environment

@ -1,31 +0,0 @@
package test
import (
"github.com/go-errors/errors"
"os"
"os/exec"
"path/filepath"
"github.com/jesseduffield/lazydocker/pkg/utils"
)
// GenerateRepo generates a repo from test/repos and changes the directory to be
// inside the newly made repo
func GenerateRepo(filename string) error {
reposDir := "/test/repos/"
testPath := utils.GetProjectRoot() + reposDir
// workaround for debian packaging
if _, err := os.Stat(testPath); os.IsNotExist(err) {
cwd, _ := os.Getwd()
testPath = filepath.Dir(filepath.Dir(cwd)) + reposDir
}
if err := os.Chdir(testPath); err != nil {
return err
}
if output, err := exec.Command("bash", filename).CombinedOutput(); err != nil {
return errors.New(string(output))
}
return os.Chdir(testPath + "repo")
}

@ -50,8 +50,9 @@ func writeString(file *os.File, str string) {
}
func localisedTitle(mApp *app.App, str string) string {
viewTitle := strings.Title(str) + "Title"
return mApp.Tr.ViewTitle // FIXME: this used to be dynamic but we can't make this dynamic again without reflection since we're now using a struct of translation strings
return ""
// viewTitle := strings.Title(str) + "Title"
// return mApp.Tr.ViewTitle // FIXME: this used to be dynamic but we can't make this dynamic again without reflection since we're now using a struct of translation strings
}
func formatTitle(title string) string {
@ -80,17 +81,17 @@ func getBindingSections(mApp *app.App) []*bindingSection {
bindingSections = addBinding(title, bindingSections, binding)
}
for view, contexts := range mApp.Gui.GetContextMap() {
for contextName, contextBindings := range contexts {
translatedView := localisedTitle(mApp, view)
translatedContextName := localisedTitle(mApp, contextName)
title := fmt.Sprintf("%s (%s)", translatedView, translatedContextName)
for _, binding := range contextBindings {
bindingSections = addBinding(title, bindingSections, binding)
}
}
}
// for view, contexts := range mApp.Gui.GetContextMap() {
// for contextName, contextBindings := range contexts {
// translatedView := localisedTitle(mApp, view)
// translatedContextName := localisedTitle(mApp, contextName)
// title := fmt.Sprintf("%s (%s)", translatedView, translatedContextName)
// for _, binding := range contextBindings {
// bindingSections = addBinding(title, bindingSections, binding)
// }
// }
// }
return bindingSections
}

Loading…
Cancel
Save