mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-19 19:17:02 -07:00
Add support for storage command and crawler output
Partially addresses issue #3 by adding a simple `magellan list devices` command to list storage devices. To close the issue, this PR still requires including storage device information in the `crawler`'s output. Reviewed-on: towk/magellan-ng#5
This commit is contained in:
parent
461c006d75
commit
2596e8945f
5 changed files with 77 additions and 1 deletions
2
go.sum
2
go.sum
|
|
@ -192,6 +192,8 @@ golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
|||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
|
|
|
|||
1
internal/cache/edit/modify.go
vendored
Normal file
1
internal/cache/edit/modify.go
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
package cache
|
||||
48
internal/cache/edit/table.go
vendored
Normal file
48
internal/cache/edit/table.go
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/table"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var baseStyle = lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.NormalBorder()).
|
||||
BorderForeground(lipgloss.Color("240"))
|
||||
|
||||
type Model struct {
|
||||
selected int
|
||||
Table table.Model
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd { return nil }
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
// m.Table = m.Table.Width(msg.Width)
|
||||
// m.Table = m.Table.Height(msg.Height)
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
if m.Table.Focused() {
|
||||
m.Table.Blur()
|
||||
} else {
|
||||
m.Table.Focus()
|
||||
}
|
||||
case "q", "ctrl+c":
|
||||
return m, tea.Quit
|
||||
case "enter":
|
||||
return m, tea.Batch(
|
||||
tea.Printf("Selected host '%s'", m.Table.SelectedRow()[0]),
|
||||
)
|
||||
}
|
||||
}
|
||||
m.Table, cmd = m.Table.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
return baseStyle.Render(m.Table.View()) + "\n"
|
||||
}
|
||||
10
internal/util/strings.go
Normal file
10
internal/util/strings.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package util
|
||||
|
||||
import "strings"
|
||||
|
||||
func TidyJSON(s string) string {
|
||||
s = strings.ReplaceAll(s, "\n", "")
|
||||
s = strings.ReplaceAll(s, "\t", "")
|
||||
s = strings.ReplaceAll(s, " ", "")
|
||||
return strings.ReplaceAll(s, "\"", "'")
|
||||
}
|
||||
17
pkg/list.go
17
pkg/list.go
|
|
@ -23,7 +23,22 @@ func PrintRemoteAssets(data []RemoteAsset, format string) {
|
|||
fmt.Printf("%s:%d (%s) @%s\n", r.Host, r.Port, r.Protocol, r.Timestamp.Format(time.UnixDate))
|
||||
}
|
||||
default:
|
||||
log.Error().Msg("PrintRemoteAssets: unrecognized format")
|
||||
log.Error().Msg("unrecognized format")
|
||||
}
|
||||
}
|
||||
|
||||
func PrintMapFormat(data map[string]any, format string) {
|
||||
switch strings.ToLower(format) {
|
||||
case "json":
|
||||
util.PrintJSON(data)
|
||||
case "yaml":
|
||||
util.PrintYAML(data)
|
||||
case "none":
|
||||
for k, v := range data {
|
||||
fmt.Printf("%s: %v\n", k, v)
|
||||
}
|
||||
default:
|
||||
log.Error().Msg("unrecognized format")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue