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

create ttp cmd not to fail if folder does not exists #496

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 9 additions & 2 deletions cmd/createttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ package cmd

import (
"fmt"
"text/template"

"github.com/facebookincubator/ttpforge/pkg/platforms"
"github.com/google/uuid"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"os"
"path/filepath"
"text/template"
)

const ttpTemplate = `---
Expand Down Expand Up @@ -74,6 +75,12 @@ func buildCreateTTPCommand() *cobra.Command {
return fmt.Errorf("%v already exists", newTTPFilePath)
}

// create the directory for the new TTP file, if it doesn't already exist
err = fsys.MkdirAll(filepath.Dir(newTTPFilePath), os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create directory for new TTP file: %w", err)
}

// create the new TTP file with afero
f, err := fsys.Create(newTTPFilePath)
if err != nil {
Expand Down
Loading