Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow --output to override output location #178

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var (
ttydMinVersion = version.Must(version.NewVersion("1.7.2"))

publish bool
outputs *[]string

rootCmd = &cobra.Command{
Use: "vhs <file>",
Short: "Run a given tape file and generates its outputs.",
Expand Down Expand Up @@ -63,17 +65,34 @@ var (
return errors.New("no input provided")
}

var output string
var publishFile string
errs := Evaluate(cmd.Context(), string(input), os.Stdout, func(v *VHS) {
output = v.Options.Video.Output.GIF
// Output is being overridden, prevent all outputs
if len(*outputs) <= 0 {
publishFile = v.Options.Video.Output.GIF
return
}

for _, output := range *outputs {
if strings.HasSuffix(output, ".gif") {
v.Options.Video.Output.GIF = output
} else if strings.HasSuffix(output, ".webm") {
v.Options.Video.Output.WebM = output
} else if strings.HasSuffix(output, ".mp4") {
v.Options.Video.Output.MP4 = output
}
}

publishFile = v.Options.Video.Output.GIF
})

if len(errs) > 0 {
printErrors(os.Stderr, string(input), errs)
return errors.New("recording failed")
}

if publish && output != "" {
url, err := Publish(cmd.Context(), output)
if publish && publishFile != "" {
url, err := Publish(cmd.Context(), publishFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -191,6 +210,7 @@ func main() {

func init() {
rootCmd.Flags().BoolVarP(&publish, "publish", "p", false, "publish your GIF to vhs.charm.sh and get a shareable URL")
outputs = rootCmd.Flags().StringSliceP("output", "o", []string{}, "file name(s) of video output")
themesCmd.Flags().BoolVar(&markdown, "markdown", false, "output as markdown")
_ = themesCmd.Flags().MarkHidden("markdown")
recordCmd.Flags().StringVarP(&shell, "shell", "s", "bash", "shell for recording")
Expand Down
6 changes: 3 additions & 3 deletions video.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func MakeGIF(opts VideoOptions) *exec.Cmd {
return nil
}

fmt.Println("Creating GIF...")
fmt.Printf("Creating %s...\n", opts.Output.GIF)

//nolint:gosec
return exec.Command(
Expand Down Expand Up @@ -116,7 +116,7 @@ func MakeWebM(opts VideoOptions) *exec.Cmd {
return nil
}

fmt.Println("Creating WebM...")
fmt.Printf("Creating %s...\n", opts.Output.WebM)

//nolint:gosec
return exec.Command(
Expand Down Expand Up @@ -151,7 +151,7 @@ func MakeMP4(opts VideoOptions) *exec.Cmd {
return nil
}

fmt.Println("Creating MP4...")
fmt.Printf("Creating %s...\n", opts.Output.MP4)

//nolint:gosec
return exec.Command(
Expand Down