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

running golangci-lint on ui/system package #385

Merged
merged 1 commit into from
Nov 26, 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
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run:
- ui/images
- ui/networks
- ui/pods
- ui/system
linters:
enable-all: true
disable:
Expand All @@ -35,6 +34,8 @@ linters:
- exhaustivestruct
- gomoddirectives
linters-settings:
# typecheck:
# enabled: false
errcheck:
check-blank: false
ignore: fmt:.*
Expand Down
77 changes: 60 additions & 17 deletions ui/system/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (sys *System) runCommand(cmd string) {
sys.events()
case "info":
sys.info()
case "prune":
case "prune": //nolint:goconst
sys.cprune()
case "remove connection":
sys.cremove()
Expand All @@ -46,28 +46,33 @@ func (sys *System) addConnection() {
name, uri, identity := sys.connAddDialog.GetItems()
sys.progressDialog.SetTitle("adding new connection")
sys.progressDialog.Display()

go func() {
err := sys.connectionAddFunc(name, uri, identity)
sys.progressDialog.Hide()
sys.UpdateConnectionsData()

if err != nil {
sys.displayError("ADD NEW CONNECTION ERROR", err)

return
}
}()
}

func (sys *System) connect() {
connName, _, connURI, connIdentity := sys.getSelectedItem()
selectedItem := sys.getSelectedItem()
// empty table
if connName == "" {
if selectedItem.name == "" {
return
}

dest := registry.Connection{
Name: connName,
URI: connURI,
Identity: connIdentity,
Name: selectedItem.name,
URI: selectedItem.uri,
Identity: selectedItem.identity,
}

sys.eventDialog.SetText("")
sys.connectionConnectFunc(dest)
sys.UpdateConnectionsData()
Expand All @@ -83,27 +88,35 @@ func (sys *System) df() {
if !sys.destIsSet() {
return
}

sys.progressDialog.SetTitle("podman disk usage in progress")
sys.progressDialog.Display()

diskUsage := func() {
response, err := sysinfo.DiskUsage()

sys.progressDialog.Hide()

if err != nil {
sys.displayError("SYSTEM DISK USAGE ERROR", err)

return
}

connName := registry.ConnectionName()
sys.dfDialog.SetServiceName(connName)
sys.dfDialog.UpdateDiskSummary(response)
sys.dfDialog.Display()
}

go diskUsage()
}

func (sys *System) events() {
if !sys.destIsSet() {
return
}

connName := registry.ConnectionName()
sys.eventDialog.SetServiceName(connName)
sys.eventDialog.Display()
Expand All @@ -113,9 +126,11 @@ func (sys *System) info() {
if !sys.destIsSet() {
return
}

data, err := sysinfo.Info()
if err != nil {
sys.displayError("SYSTEM INFO ERROR", err)

return
}

Expand All @@ -130,83 +145,111 @@ func (sys *System) cprune() {
if !sys.destIsSet() {
return
}

connName := registry.ConnectionName()

sys.confirmDialog.SetTitle("podman system prune")
sys.confirmData = "prune"
confirmMsg := fmt.Sprintf("Are you sure you want to remove all unused pod, container, image and volume data on %s?", connName)
confirmMsg := fmt.Sprintf(
"Are you sure you want to remove all unused pod, container, image and volume data on %s?",
connName)
sys.confirmDialog.SetText(confirmMsg)
sys.confirmDialog.Display()
}

func (sys *System) prune() {
sys.progressDialog.SetTitle("system purne in progress")
sys.progressDialog.Display()

prune := func() {
report, err := sysinfo.Prune()

sys.progressDialog.Hide()

if err != nil {
sys.displayError("SYSTEM PRUNE ERROR", err)

return
}

sys.messageDialog.SetTitle("PODMAN SYSTEM PRUNE")
sys.messageDialog.SetText(dialogs.MessageSystemInfo, registry.ConnectionName(), report)
sys.messageDialog.Display()
}

go prune()
}

func (sys *System) cremove() {
connName, status, _, _ := sys.getSelectedItem()
if status != "" {
sys.displayError("SYSTEM CONNECTION REMOVE", fmt.Errorf("%q connection in progress, need to disconnect", connName))
selectedItem := sys.getSelectedItem()
if selectedItem.status != "" {
sys.displayError(
"SYSTEM CONNECTION REMOVE",
fmt.Errorf("%w %q", ErrConnectionInprogres, selectedItem.name))

return
}
if connName == "" {

if selectedItem.name == "" {
return
}

title := "podman system connection remove"
sys.confirmDialog.SetTitle(title)
sys.confirmData = "remove_conn"
bgColor := style.GetColorHex(style.DialogBorderColor)
fgColor := style.GetColorHex(style.DialogFgColor)
serviceItem := fmt.Sprintf("[%s:%s:b]SERVICE NAME:[:-:-] %s", fgColor, bgColor, connName)
serviceItem := fmt.Sprintf("[%s:%s:b]SERVICE NAME:[:-:-] %s", fgColor, bgColor, selectedItem.name)

confirmMsg := fmt.Sprintf("%s\n\nAre you sure you want to remove the selected service connection ?", serviceItem)
sys.confirmDialog.SetText(confirmMsg)
sys.confirmDialog.Display()
}

func (sys *System) remove() {
connName, _, _, _ := sys.getSelectedItem()
selectedItem := sys.getSelectedItem()

sys.progressDialog.SetTitle("removing connection")
sys.progressDialog.Display()

go func() {
sys.connectionRemoveFunc(connName)
err := sys.connectionRemoveFunc(selectedItem.name)
sys.progressDialog.Hide()

if err != nil {
sys.displayError("SYSTEM CONNECTION REMOVE ERROR", err)

return
}

sys.UpdateConnectionsData()
}()

}

func (sys *System) setDefault() {
connName, _, _, _ := sys.getSelectedItem()
selectedItem := sys.getSelectedItem()
setDefFunc := func() {
sys.progressDialog.Hide()
if err := sys.connectionSetDefaultFunc(connName); err != nil {

if err := sys.connectionSetDefaultFunc(selectedItem.name); err != nil {
sys.displayError("SYSTEM CONNECTION SET DEFAULT ERROR", err)

return
}
}

sys.progressDialog.Display()

go setDefFunc()
}

func (sys *System) destIsSet() bool {
if !registry.ConnectionIsSet() {
sys.errorDialog.SetText("not connected to any podman service")
sys.errorDialog.Display()

return false
}

return true
}
8 changes: 7 additions & 1 deletion ui/system/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/containers/podman-tui/ui/style"
)

// UpdateConnectionsData retrieves connections list data
// UpdateConnectionsData retrieves connections list data.
func (sys *System) UpdateConnectionsData() {
destinations := sys.connectionListFunc()
sys.connectionList.mu.Lock()
Expand All @@ -19,11 +19,14 @@ func (sys *System) UpdateConnectionsData() {
func (sys *System) udpateConnectionDataStatus() {
sys.connectionList.mu.Lock()
defer sys.connectionList.mu.Unlock()

name := registry.ConnectionName()
status := registry.ConnectionStatus()

for i := 0; i < len(sys.connectionList.report); i++ {
if sys.connectionList.report[i].Name == name {
sys.connectionList.report[i].Status = status

return
}
}
Expand All @@ -33,6 +36,7 @@ func (sys *System) getConnectionsData() []registry.Connection {
sys.connectionList.mu.Lock()
destReport := sys.connectionList.report
sys.connectionList.mu.Unlock()

return destReport
}

Expand All @@ -42,11 +46,13 @@ type connectionItemStatus struct {

func (connStatus connectionItemStatus) StatusString() string {
var status string

switch connStatus.status {
case registry.ConnectionStatusConnected:
status = fmt.Sprintf("%s %s", style.HeavyGreenCheckMark, "connected")
case registry.ConnectionStatusConnectionError:
status = fmt.Sprintf("%s %s", style.HeavyRedCrossMark, "connection error")
}

return status
}
20 changes: 19 additions & 1 deletion ui/system/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,78 @@ import (
func (sys *System) Draw(screen tcell.Screen) {
sys.refresh()
sys.Box.DrawForSubclass(screen, sys)

x, y, width, height := sys.GetInnerRect()

sys.connTable.SetRect(x, y, width, height)
sys.connTable.Draw(screen)

x, y, width, height = sys.connTable.GetInnerRect()

// error dialog
if sys.errorDialog.IsDisplay() {
sys.errorDialog.SetRect(x, y, width, height)
sys.errorDialog.Draw(screen)

return
}

// connection progress dialog
if sys.connPrgDialog.IsDisplay() {
sys.connPrgDialog.SetRect(x, y, width, height)
sys.connPrgDialog.Draw(screen)

return
}
// command dialog dialog

// command dialog
if sys.cmdDialog.IsDisplay() {
sys.cmdDialog.SetRect(x, y, width, height)
sys.cmdDialog.Draw(screen)

return
}

// confirm dialog
if sys.confirmDialog.IsDisplay() {
sys.confirmDialog.SetRect(x, y, width, height)
sys.confirmDialog.Draw(screen)

return
}

// message dialog
if sys.messageDialog.IsDisplay() {
sys.messageDialog.SetRect(x, y, width, height)
sys.messageDialog.Draw(screen)

return
}

// disk usage dialog
if sys.dfDialog.IsDisplay() {
sys.dfDialog.SetRect(x, y, width, height)
sys.dfDialog.Draw(screen)

return
}

// progress dialog
if sys.progressDialog.IsDisplay() {
sys.progressDialog.SetRect(x, y, width, height)
sys.progressDialog.Draw(screen)

return
}

// connection create dialog
if sys.connAddDialog.IsDisplay() {
sys.connAddDialog.SetRect(x, y, width, height)
sys.connAddDialog.Draw(screen)

return
}

// event dialog
if sys.eventDialog.IsDisplay() {
sys.eventDialog.SetRect(x, y, width, height)
Expand Down
Loading
Loading