Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "networks" panel under "volumes" #424

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ lazydocker*
TODO.md
Lazydocker.code-workspace
.vscode
.idea
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Netzwerk

<pre>
<kbd>c</kbd>: führe vordefinierten benutzerdefinierten Befehl aus
<kbd>d</kbd>: entferne Netzwerk
<kbd>b</kbd>: view bulk commands
<kbd>enter</kbd>: fokussieren aufs Hauptpanel
<kbd>[</kbd>: vorheriges Tab
<kbd>]</kbd>: nächstes Tab
<kbd>/</kbd>: filter list
</pre>

## Haupt

<pre>
Expand Down
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Networks

<pre>
<kbd>c</kbd>: run predefined custom command
<kbd>d</kbd>: remove network
<kbd>b</kbd>: view bulk commands
<kbd>enter</kbd>: focus main panel
<kbd>[</kbd>: previous tab
<kbd>]</kbd>: next tab
<kbd>/</kbd>: filter list
</pre>

## Main

<pre>
Expand Down
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Réseaux

<pre>
<kbd>c</kbd>: executer une commande prédéfinie
<kbd>d</kbd>: supprimer le réseau
<kbd>b</kbd>: voir les commandes groupés
<kbd>enter</kbd>: focus paneau principal
<kbd>[</kbd>: onglet précédent
<kbd>]</kbd>: onglet suivant
<kbd>/</kbd>: filter list
</pre>

## Principal

<pre>
Expand Down
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Networks

<pre>
<kbd>c</kbd>: draai een vooraf bedacht aangepaste opdracht
<kbd>d</kbd>: verwijder network
<kbd>b</kbd>: view bulk commands
<kbd>enter</kbd>: focus hoofdpaneel
<kbd>[</kbd>: vorige tab
<kbd>]</kbd>: volgende tab
<kbd>/</kbd>: filter list
</pre>

## Hoofd

<pre>
Expand Down
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Seici

<pre>
<kbd>c</kbd>: wykonaj predefiniowaną własną komende
<kbd>d</kbd>: usuń seici
<kbd>b</kbd>: view bulk commands
<kbd>enter</kbd>: skup na głównym panelu
<kbd>[</kbd>: poprzednia zakładka
<kbd>]</kbd>: następna zakładka
<kbd>/</kbd>: filter list
</pre>

## Główne

<pre>
Expand Down
12 changes: 12 additions & 0 deletions docs/keybindings/Keybindings_tr.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>/</kbd>: filter list
</pre>

## Ağları

<pre>
<kbd>c</kbd>: önceden tanımlanmış özel komutu çalıştır
<kbd>d</kbd>: ağı kaldır
<kbd>b</kbd>: view bulk commands
<kbd>enter</kbd>: ana panele odaklan
<kbd>[</kbd>: önceki sekme
<kbd>]</kbd>: sonraki sekme
<kbd>/</kbd>: filter list
</pre>

## Ana

<pre>
Expand Down
1 change: 1 addition & 0 deletions pkg/cheatsheet/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func getBindingSections(mApp *app.App) []*bindingSection {
"containers": mApp.Tr.ContainersTitle,
"images": mApp.Tr.ImagesTitle,
"volumes": mApp.Tr.VolumesTitle,
"networks": mApp.Tr.NetworksTitle,
}

bindingSections = addBinding(titleMap[viewName], bindingSections, binding)
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type CommandObject struct {
Container *Container
Image *Image
Volume *Volume
Network *Network
}

// NewCommandObject takes a command object and returns a default command object with the passed command object merged in
Expand Down
54 changes: 54 additions & 0 deletions pkg/commands/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package commands

import (
"context"

dockerTypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)

// Network : A docker Network
type Network struct {
Name string
Network dockerTypes.NetworkResource
Client *client.Client
OSCommand *OSCommand
Log *logrus.Entry
DockerCommand LimitedDockerCommand
}

// RefreshNetworks gets the networks and stores them
func (c *DockerCommand) RefreshNetworks() ([]*Network, error) {
networks, err := c.Client.NetworkList(context.Background(), dockerTypes.NetworkListOptions{})
if err != nil {
return nil, err
}

ownNetworks := make([]*Network, len(networks))

for i, network := range networks {
ownNetworks[i] = &Network{
Name: network.Name,
Network: network,
Client: c.Client,
OSCommand: c.OSCommand,
Log: c.Log,
DockerCommand: c,
}
}

return ownNetworks, nil
}

// PruneNetworks prunes networks
func (c *DockerCommand) PruneNetworks() error {
_, err := c.Client.NetworksPrune(context.Background(), filters.Args{})
return err
}

// Remove removes the network
func (v *Network) Remove() error {
return v.Client.NetworkRemove(context.Background(), v.Name)
}
3 changes: 3 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ type CustomCommands struct {

// Volumes contains the custom commands for volumes
Volumes []CustomCommand `yaml:"volumes,omitempty"`

// Networks contains the custom commands for networks
Networks []CustomCommand `yaml:"networks,omitempty"`
}

// Replacements contains the stuff relating to rendering a container's info
Expand Down
7 changes: 7 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Panels struct {
Containers *panels.SideListPanel[*commands.Container]
Images *panels.SideListPanel[*commands.Image]
Volumes *panels.SideListPanel[*commands.Volume]
Networks *panels.SideListPanel[*commands.Network]
Menu *panels.SideListPanel[*types.MenuItem]
}

Expand Down Expand Up @@ -273,6 +274,7 @@ func (gui *Gui) setPanels() {
Containers: gui.getContainersPanel(),
Images: gui.getImagesPanel(),
Volumes: gui.getVolumesPanel(),
Networks: gui.getNetworksPanel(),
Menu: gui.getMenuPanel(),
}
}
Expand All @@ -297,6 +299,11 @@ func (gui *Gui) refresh() {
gui.Log.Error(err)
}
}()
go func() {
if err := gui.reloadNetworks(); err != nil {
gui.Log.Error(err)
}
}()
go func() {
if err := gui.reloadImages(); err != nil {
gui.Log.Error(err)
Expand Down
21 changes: 21 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,27 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleVolumesBulkCommand,
Description: gui.Tr.ViewBulkCommands,
},
{
ViewName: "networks",
Key: 'c',
Modifier: gocui.ModNone,
Handler: gui.handleNetworksCustomCommand,
Description: gui.Tr.RunCustomCommand,
},
{
ViewName: "networks",
Key: 'd',
Modifier: gocui.ModNone,
Handler: gui.handleNetworksRemoveMenu,
Description: gui.Tr.RemoveNetwork,
},
{
ViewName: "networks",
Key: 'b',
Modifier: gocui.ModNone,
Handler: gui.handleNetworksBulkCommand,
Description: gui.Tr.ViewBulkCommands,
},
{
ViewName: "main",
Key: gocui.KeyEsc,
Expand Down
Loading