diff --git a/pkg/app/app.go b/pkg/app/app.go index bb0bcaaf..96d9503b 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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 } diff --git a/pkg/commands/container.go b/pkg/commands/container.go index ce0d44c2..216af724 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -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"` diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 269e9666..217b0068 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -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 diff --git a/pkg/commands/errors.go b/pkg/commands/errors.go index 5b91e9fa..f7165fca 100644 --- a/pkg/commands/errors.go +++ b/pkg/commands/errors.go @@ -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) { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 23c6d862..9fcc7c84 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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", diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index e1cecbb4..3b9a36e4 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -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 diff --git a/pkg/test/test.go b/pkg/test/test.go deleted file mode 100644 index f21cb6b7..00000000 --- a/pkg/test/test.go +++ /dev/null @@ -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") -} diff --git a/scripts/generate_cheatsheet.go b/scripts/generate_cheatsheet.go index 4fad5593..d4e834dd 100644 --- a/scripts/generate_cheatsheet.go +++ b/scripts/generate_cheatsheet.go @@ -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 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 _, binding := range contextBindings { + // bindingSections = addBinding(title, bindingSections, binding) + // } + // } + // } return bindingSections }