mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-26 00:09:11 +00:00
snapshot commands implemented
This commit is contained in:
parent
27922d41bb
commit
4db173154b
@ -16,7 +16,7 @@ func NewSnapshot(c *Client) *Snapshot {
|
||||
|
||||
// Name gets the name of the snapshot at the given index.
|
||||
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)
|
||||
if err != nil {
|
||||
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.
|
||||
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)
|
||||
}
|
||||
|
||||
// Load loads the snapshot at the given index.
|
||||
func (s *Snapshot) Load(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/load/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentName sets the name of the current snapshot.
|
||||
func (s *Snapshot) CurrentName(name string) error {
|
||||
address := s.baseAddress + "/name"
|
||||
return s.client.SendMessage(address, name)
|
||||
}
|
||||
|
||||
// Save saves the current state to the snapshot at the given index.
|
||||
func (s *Snapshot) Save(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/save/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentLoad loads the snapshot at the given index.
|
||||
func (s *Snapshot) CurrentLoad(index int) error {
|
||||
address := s.baseAddress + "/load"
|
||||
return s.client.SendMessage(address, int32(index))
|
||||
}
|
||||
|
||||
// Delete deletes the snapshot at the given index.
|
||||
func (s *Snapshot) Delete(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/delete/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentSave saves the current state to the snapshot at the given index.
|
||||
func (s *Snapshot) CurrentSave(index int) error {
|
||||
address := s.baseAddress + "/save"
|
||||
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
75
snapshot.go
Normal 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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user