cmd/info: Use 'info' struct
This commit is contained in:
parent
ea714aba86
commit
894c23c137
3 changed files with 53 additions and 10 deletions
50
cmd/info.go
50
cmd/info.go
|
|
@ -1,14 +1,18 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/core"
|
"github.com/FAU-CDI/wisski-distillery/internal/core"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/pkg/slicesx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Info is then 'info' command
|
// Info is then 'info' command
|
||||||
var Info wisski_distillery.Command = info{}
|
var Info wisski_distillery.Command = info{}
|
||||||
|
|
||||||
type info struct {
|
type info struct {
|
||||||
|
JSON bool `short:"j" long:"json" description:"Print information as JSON instead of as string"`
|
||||||
Positionals struct {
|
Positionals struct {
|
||||||
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to show info about"`
|
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to show info about"`
|
||||||
} `positional-args:"true"`
|
} `positional-args:"true"`
|
||||||
|
|
@ -30,16 +34,46 @@ func (i info) Run(context wisski_distillery.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Printf("URL: %s\n", instance.URL())
|
info, err := instance.Info(false)
|
||||||
context.Printf("Base directory: %s\n", instance.FilesystemBase)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
context.Printf("SQL Database: %s\n", instance.SqlDatabase)
|
if i.JSON {
|
||||||
context.Printf("SQL Username: %s\n", instance.SqlUsername)
|
json.NewEncoder(context.Stdout).Encode(info)
|
||||||
context.Printf("SQL Password: %s\n", instance.SqlPassword)
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
context.Printf("GraphDB Repository: %s\n", instance.GraphDBRepository)
|
context.Printf("Slug: %v\n", info.Slug)
|
||||||
context.Printf("GraphDB Username: %s\n", instance.GraphDBUsername)
|
context.Printf("URL: %v\n", info.URL)
|
||||||
context.Printf("GraphDB Password: %s\n", instance.GraphDBPassword)
|
|
||||||
|
context.Printf("Base directory: %v\n", instance.FilesystemBase)
|
||||||
|
|
||||||
|
context.Printf("SQL Database: %v\n", instance.SqlDatabase)
|
||||||
|
context.Printf("SQL Username: %v\n", instance.SqlUsername)
|
||||||
|
context.Printf("SQL Password: %v\n", instance.SqlPassword)
|
||||||
|
|
||||||
|
context.Printf("GraphDB Repository: %v\n", instance.GraphDBRepository)
|
||||||
|
context.Printf("GraphDB Username: %v\n", instance.GraphDBUsername)
|
||||||
|
context.Printf("GraphDB Password: %v\n", instance.GraphDBPassword)
|
||||||
|
|
||||||
|
context.Printf("Running: %v\n", info.Running)
|
||||||
|
context.Printf("Last Rebuild: %v\n", info.LastRebuild.String())
|
||||||
|
|
||||||
|
context.Printf("Prefixes: (count %d)\n", len(info.Prefixes))
|
||||||
|
for _, prefix := range info.Prefixes {
|
||||||
|
context.Printf("- %s\n", prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Printf("Snapshots: (count %d)\n", len(info.Snapshots))
|
||||||
|
for _, s := range info.Snapshots {
|
||||||
|
context.Printf("- %s (taken %s, packed %v)\n", s.Path, s.Created.String(), s.Packed)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Printf("Pathbuilders: (count %d)\n", len(info.Pathbuilders))
|
||||||
|
slicesx.ForSorted(info.Pathbuilders, func(name, data string) {
|
||||||
|
context.Printf("- %s (%d bytes)\n", name, len(data))
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package instances
|
package instances
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||||
|
|
@ -70,7 +69,6 @@ func (wisski *WissKI) Info(quick bool) (info WissKIInfo, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = group.Wait()
|
err = group.Wait()
|
||||||
fmt.Println(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,20 @@ package slicesx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ForSorted iterates over the map in an ordered fashion
|
||||||
|
func ForSorted[K constraints.Ordered, V any](mp map[K]V, callback func(k K, v V)) {
|
||||||
|
keys := maps.Keys(mp)
|
||||||
|
slices.Sort(keys)
|
||||||
|
|
||||||
|
for _, key := range keys {
|
||||||
|
callback(key, mp[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Any returns true if test returns true for any of values.
|
// Any returns true if test returns true for any of values.
|
||||||
func Any[T any](values []T, test func(T) bool) bool {
|
func Any[T any](values []T, test func(T) bool) bool {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue