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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/core"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/slicesx"
|
||||
)
|
||||
|
||||
// Info is then 'info' command
|
||||
var Info wisski_distillery.Command = info{}
|
||||
|
||||
type info struct {
|
||||
JSON bool `short:"j" long:"json" description:"Print information as JSON instead of as string"`
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to show info about"`
|
||||
} `positional-args:"true"`
|
||||
|
|
@ -30,16 +34,46 @@ func (i info) Run(context wisski_distillery.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
context.Printf("URL: %s\n", instance.URL())
|
||||
context.Printf("Base directory: %s\n", instance.FilesystemBase)
|
||||
info, err := instance.Info(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context.Printf("SQL Database: %s\n", instance.SqlDatabase)
|
||||
context.Printf("SQL Username: %s\n", instance.SqlUsername)
|
||||
context.Printf("SQL Password: %s\n", instance.SqlPassword)
|
||||
if i.JSON {
|
||||
json.NewEncoder(context.Stdout).Encode(info)
|
||||
return nil
|
||||
}
|
||||
|
||||
context.Printf("GraphDB Repository: %s\n", instance.GraphDBRepository)
|
||||
context.Printf("GraphDB Username: %s\n", instance.GraphDBUsername)
|
||||
context.Printf("GraphDB Password: %s\n", instance.GraphDBPassword)
|
||||
context.Printf("Slug: %v\n", info.Slug)
|
||||
context.Printf("URL: %v\n", info.URL)
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue