record stop now prints output path of recording

record directory command added
This commit is contained in:
onyx-and-iris 2025-05-27 01:27:30 +01:00
parent c27a5ea6c5
commit f94ac1ca0c
2 changed files with 40 additions and 9 deletions

View File

@ -2,6 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"github.com/andreykaipov/goobs/api/requests/config"
) )
// RecordCmd handles the recording commands. // RecordCmd handles the recording commands.
@ -12,6 +14,7 @@ type RecordCmd struct {
Status RecordStatusCmd `cmd:"" help:"Show recording status." aliases:"ss"` Status RecordStatusCmd `cmd:"" help:"Show recording status." aliases:"ss"`
Pause RecordPauseCmd `cmd:"" help:"Pause recording." aliases:"p"` Pause RecordPauseCmd `cmd:"" help:"Pause recording." aliases:"p"`
Resume RecordResumeCmd `cmd:"" help:"Resume recording." aliases:"r"` Resume RecordResumeCmd `cmd:"" help:"Resume recording." aliases:"r"`
Directory RecordDirectoryCmd `cmd:"" help:"Get/Set recording directory." aliases:"d"`
} }
// RecordStartCmd starts the recording. // RecordStartCmd starts the recording.
@ -32,11 +35,11 @@ type RecordStopCmd struct{} // size = 0x0
// Run executes the command to stop recording. // Run executes the command to stop recording.
func (cmd *RecordStopCmd) Run(ctx *context) error { func (cmd *RecordStopCmd) Run(ctx *context) error {
_, err := ctx.Client.Record.StopRecord() resp, err := ctx.Client.Record.StopRecord()
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintln(ctx.Out, "Recording stopped successfully.") fmt.Fprintf(ctx.Out, "%s", fmt.Sprintf("Recording stopped successfully. Output file: %s\n", resp.OutputPath))
return nil return nil
} }
@ -132,3 +135,30 @@ func (cmd *RecordResumeCmd) Run(ctx *context) error {
fmt.Fprintln(ctx.Out, "Recording resumed successfully.") fmt.Fprintln(ctx.Out, "Recording resumed successfully.")
return nil return nil
} }
// RecordDirectoryCmd sets the recording directory.
type RecordDirectoryCmd struct {
RecordDirectory string `arg:"" help:"Directory to save recordings." default:""`
}
// Run executes the command to set the recording directory.
func (cmd *RecordDirectoryCmd) Run(ctx *context) error {
if cmd.RecordDirectory == "" {
resp, err := ctx.Client.Config.GetRecordDirectory()
if err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Current recording directory: %s\n", resp.RecordDirectory)
return nil
}
_, err := ctx.Client.Config.SetRecordDirectory(
config.NewSetRecordDirectoryParams().WithRecordDirectory(cmd.RecordDirectory),
)
if err != nil {
return err
}
fmt.Fprintf(ctx.Out, "Recording directory set to: %s\n", cmd.RecordDirectory)
return nil
}

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"strings"
"testing" "testing"
"time" "time"
) )
@ -45,7 +46,7 @@ func TestRecordStartStatusStop(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to stop recording: %v", err) t.Fatalf("Failed to stop recording: %v", err)
} }
if out.String() != "Recording stopped successfully.\n" { if !strings.Contains(out.String(), "Recording stopped successfully. Output file:") {
t.Fatalf("Expected output to be 'Recording stopped successfully.', got '%s'", out.String()) t.Fatalf("Expected output to be 'Recording stopped successfully.', got '%s'", out.String())
} }
// Reset output buffer for the next command // Reset output buffer for the next command