gobs-cli/record.go
2025-04-24 11:54:51 +01:00

120 lines
3.0 KiB
Go

package main
import (
"fmt"
)
// RecordCmd handles the recording commands.
type RecordCmd struct {
Start RecordStartCmd `cmd:"" help:"Start recording." aliases:"s"`
Stop RecordStopCmd `cmd:"" help:"Stop recording." aliases:"st"`
Toggle RecordToggleCmd `cmd:"" help:"Toggle recording." aliases:"tg"`
Pause RecordPauseCmd `cmd:"" help:"Pause recording." aliases:"p"`
Resume RecordResumeCmd `cmd:"" help:"Resume recording." aliases:"r"`
}
// RecordStartCmd starts the recording.
type RecordStartCmd struct{} // size = 0x0
// Run executes the command to start recording.
func (cmd *RecordStartCmd) Run(ctx *context) error {
_, err := ctx.Client.Record.StartRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording started successfully.")
return nil
}
// RecordStopCmd stops the recording.
type RecordStopCmd struct{} // size = 0x0
// Run executes the command to stop recording.
func (cmd *RecordStopCmd) Run(ctx *context) error {
_, err := ctx.Client.Record.StopRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording stopped successfully.")
return nil
}
// RecordToggleCmd toggles the recording state.
type RecordToggleCmd struct{} // size = 0x0
// Run executes the command to toggle recording.
func (cmd *RecordToggleCmd) Run(ctx *context) error {
// Check if recording is in progress
status, err := ctx.Client.Record.GetRecordStatus()
if err != nil {
return err
}
if status.OutputActive {
_, err = ctx.Client.Record.StopRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording stopped successfully.")
} else {
_, err = ctx.Client.Record.StartRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording started successfully.")
}
return nil
}
// RecordPauseCmd pauses the recording.
type RecordPauseCmd struct{} // size = 0x0
// Run executes the command to pause recording.
func (cmd *RecordPauseCmd) Run(ctx *context) error {
// Check if recording in progress and not already paused
status, err := ctx.Client.Record.GetRecordStatus()
if err != nil {
return err
}
if !status.OutputActive {
return fmt.Errorf("recording is not in progress")
}
if status.OutputPaused {
return fmt.Errorf("recording is already paused")
}
_, err = ctx.Client.Record.PauseRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording paused successfully.")
return nil
}
// RecordResumeCmd resumes the recording.
type RecordResumeCmd struct{} // size = 0x0
// Run executes the command to resume recording.
func (cmd *RecordResumeCmd) Run(ctx *context) error {
// Check if recording in progress and not already resumed
status, err := ctx.Client.Record.GetRecordStatus()
if err != nil {
return err
}
if !status.OutputActive {
return fmt.Errorf("recording is not in progress")
}
if !status.OutputPaused {
return fmt.Errorf("recording is not paused")
}
_, err = ctx.Client.Record.ResumeRecord()
if err != nil {
return err
}
fmt.Fprintln(ctx.Out, "Recording resumed successfully.")
return nil
}