mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -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
d236649b05
commit
b2111ddcb2
20 changed files with 450 additions and 18 deletions
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"
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package url
|
||||
package urlx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package util
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// FormatErrorList() is a wrapper function that unifies error list formatting
|
||||
// and makes printing error lists consistent.
|
||||
|
|
|
|||
25
internal/util/print.go
Normal file
25
internal/util/print.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func PrintJSON(data any) {
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("failed to marshal scanned results to JSON")
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
||||
func PrintYAML(data any) {
|
||||
b, err := yaml.Marshal(data)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("failed to marshal scanned results to JSON")
|
||||
}
|
||||
fmt.Printf("%s\n", string(b))
|
||||
}
|
||||
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, "\"", "'")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue