snapshot commands implemented

This commit is contained in:
onyx-and-iris 2026-02-06 17:31:41 +00:00
parent 27922d41bb
commit 4db173154b
2 changed files with 95 additions and 14 deletions

View File

@ -16,7 +16,7 @@ func NewSnapshot(c *Client) *Snapshot {
// Name gets the name of the snapshot at the given index. // Name gets the name of the snapshot at the given index.
func (s *Snapshot) Name(index int) (string, error) { func (s *Snapshot) Name(index int) (string, error) {
address := s.baseAddress + fmt.Sprintf("/name/%d", index) address := s.baseAddress + fmt.Sprintf("/%02d/name", index)
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return "", err return "", err
@ -35,24 +35,30 @@ func (s *Snapshot) Name(index int) (string, error) {
// SetName sets the name of the snapshot at the given index. // SetName sets the name of the snapshot at the given index.
func (s *Snapshot) SetName(index int, name string) error { func (s *Snapshot) SetName(index int, name string) error {
address := s.baseAddress + fmt.Sprintf("/name/%d", index) address := s.baseAddress + fmt.Sprintf("/%02d/name", index)
return s.client.SendMessage(address, name) return s.client.SendMessage(address, name)
} }
// Load loads the snapshot at the given index. // CurrentName sets the name of the current snapshot.
func (s *Snapshot) Load(index int) error { func (s *Snapshot) CurrentName(name string) error {
address := s.baseAddress + fmt.Sprintf("/load/%d", index) address := s.baseAddress + "/name"
return s.client.SendMessage(address) return s.client.SendMessage(address, name)
} }
// Save saves the current state to the snapshot at the given index. // CurrentLoad loads the snapshot at the given index.
func (s *Snapshot) Save(index int) error { func (s *Snapshot) CurrentLoad(index int) error {
address := s.baseAddress + fmt.Sprintf("/save/%d", index) address := s.baseAddress + "/load"
return s.client.SendMessage(address) return s.client.SendMessage(address, int32(index))
} }
// Delete deletes the snapshot at the given index. // CurrentSave saves the current state to the snapshot at the given index.
func (s *Snapshot) Delete(index int) error { func (s *Snapshot) CurrentSave(index int) error {
address := s.baseAddress + fmt.Sprintf("/delete/%d", index) address := s.baseAddress + "/save"
return s.client.SendMessage(address) return s.client.SendMessage(address, int32(index))
}
// CurrentDelete deletes the snapshot at the given index.
func (s *Snapshot) CurrentDelete(index int) error {
address := s.baseAddress + "/delete"
return s.client.SendMessage(address, int32(index))
} }

75
snapshot.go Normal file
View File

@ -0,0 +1,75 @@
package main
import "fmt"
type SnapshotCmdGroup struct {
List ListCmd `help:"List all snapshots." cmd:"list"`
Index struct {
Index int `arg:"" help:"The index of the snapshot."`
Name NameCmd `help:"Get or set the name of a snapshot." cmd:"name"`
Save SaveCmd `help:"Save the current mixer state." cmd:"save"`
Load LoadCmd `help:"Load a mixer state." cmd:"load"`
Delete DeleteCmd `help:"Delete a snapshot." cmd:"delete"`
} `help:"The index of the snapshot." arg:""`
}
type ListCmd struct {
}
func (c *ListCmd) Run(ctx *context) error {
for i := range 64 {
name, err := ctx.Client.Snapshot.Name(i + 1)
if err != nil {
break
}
if name == "" {
continue
}
fmt.Fprintf(ctx.Out, "%d: %s\n", i+1, name)
}
return nil
}
type NameCmd struct {
Name *string `arg:"" help:"The name of the snapshot." optional:""`
}
func (c *NameCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
if c.Name == nil {
name, err := ctx.Client.Snapshot.Name(snapshot.Index.Index)
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, name)
return nil
}
return ctx.Client.Snapshot.SetName(snapshot.Index.Index, *c.Name)
}
type SaveCmd struct {
Name string `arg:"" help:"The name of the snapshot."`
}
func (c *SaveCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
err := ctx.Client.Snapshot.CurrentName(c.Name)
if err != nil {
return err
}
return ctx.Client.Snapshot.CurrentSave(snapshot.Index.Index)
}
type LoadCmd struct {
}
func (c *LoadCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
return ctx.Client.Snapshot.CurrentLoad(snapshot.Index.Index)
}
type DeleteCmd struct {
}
func (c *DeleteCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
return ctx.Client.Snapshot.CurrentDelete(snapshot.Index.Index)
}