{backup,snapshot,system_update}: Use better UI

This commit is contained in:
Tom Wiesing 2022-09-30 18:33:42 +02:00
parent 196555e897
commit ea56ff4aac
No known key found for this signature in database
11 changed files with 168 additions and 115 deletions

View file

@ -8,15 +8,17 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/targz"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/status"
)
// Backup is the 'backup' command
var Backup wisski_distillery.Command = backupC{}
type backupC struct {
NoPrune bool `short:"n" long:"no-prune" description:"Do not prune older backup archives"`
StagingOnly bool `short:"s" long:"staging-only" description:"Do not package into a backup archive, but only create a staging directory"`
Positionals struct {
NoPrune bool `short:"n" long:"no-prune" description:"Do not prune older backup archives"`
StagingOnly bool `short:"s" long:"staging-only" description:"Do not package into a backup archive, but only create a staging directory"`
ConcurrentSnapshots int `short:"c" long:"concurrent-snapshots" description:"Maximum number of concurrent snapshots" default:"2"`
Positionals struct {
Dest string `positional-arg-name:"DEST" description:"Destination path to write backup archive to. Defaults to the snapshots/archives/ directory"`
} `positional-args:"true"`
}
@ -81,8 +83,9 @@ func (bk backupC) Run(context wisski_distillery.Context) error {
logging.LogOperation(func() error {
backup := backup.New(context.IOStream, dis, backup.Description{
Dest: sPath,
Auto: bk.Positionals.Dest == "",
Dest: sPath,
Auto: bk.Positionals.Dest == "",
ConcurrentSnapshots: bk.ConcurrentSnapshots,
})
backup.WriteReport(dis.Core.Environment, context.IOStream)
return nil
@ -105,10 +108,13 @@ func (bk backupC) Run(context wisski_distillery.Context) error {
if err := logging.LogOperation(func() error {
context.IOStream.Println(archivePath)
st := status.NewWithCompat(context.Stdout, 1)
st.Start()
defer st.Stop()
count, err = targz.Package(dis.Core.Environment, archivePath, sPath, func(dst, src string) {
context.Printf("\033[2K\r%s", dst)
st.Set(0, dst)
})
context.Println("")
return err
}, context.IOStream, "Writing backup archive"); err != nil {
return errSnapshotFailed.Wrap(err)

View file

@ -10,6 +10,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/targz"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/status"
)
// Snapshot creates a snapshot of an instance
@ -115,10 +116,13 @@ func (bi snapshot) Run(context wisski_distillery.Context) error {
if err := logging.LogOperation(func() error {
context.IOStream.Println(archivePath)
st := status.NewWithCompat(context.Stdout, 1)
st.Start()
defer st.Stop()
count, err = targz.Package(dis.Core.Environment, archivePath, sPath, func(dst, src string) {
context.Printf("\033[2K\r%s", dst)
st.Set(0, dst)
})
context.Println("")
return err
}, context.IOStream, "Writing snapshot archive"); err != nil {
return errSnapshotFailed.Wrap(err)

View file

@ -11,8 +11,8 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/lib/status"
"github.com/tkw1536/goprogram/parser"
"github.com/tkw1536/goprogram/status"
"github.com/tkw1536/goprogram/stream"
)
@ -111,18 +111,12 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
}
if err := logging.LogOperation(func() error {
group := &status.Group[component.Installable]{
Writer: context.Stdout,
return status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
PrefixString: func(item component.Installable, index int) string {
return fmt.Sprintf("[install %q]: ", item.Name())
},
PrefixAlign: true,
ErrString: func(item component.Installable, index int, err error) string {
if err == nil {
return "ok"
}
return "failed (" + err.Error() + ")"
},
Handler: func(item component.Installable, index int, writer io.Writer) error {
io := stream.NewIOStream(writer, writer, stream.Null, 0)
stack := item.Stack(context.Environment.Environment)
@ -137,9 +131,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
return nil
},
}
return group.Run(dis.Installables())
}, dis.Installables())
}, context.IOStream, "Performing Stack Updates"); err != nil {
return err
}