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

rm flag #151

Merged
merged 1 commit into from
Jul 11, 2021
Merged
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
rm flag
  • Loading branch information
soniah committed Jul 6, 2021
commit 8e39e87f4acab3f831e2ee6b3bc97f0f5831309b
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type userFlags struct {
formatter string
stubImpl bool
skipEnsure bool
remove bool
args []string
}

Expand All @@ -35,6 +36,7 @@ func main() {
printVersion := flag.Bool("version", false, "show the version for moq")
flag.BoolVar(&flags.skipEnsure, "skip-ensure", false,
"suppress mock implementation check, avoid import cycle if mocks generated outside of the tested package")
flag.BoolVar(&flags.remove, "rm", false, "first remove output file, if it exists")

flag.Usage = func() {
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`)
Expand Down Expand Up @@ -63,6 +65,14 @@ func run(flags userFlags) error {
return errors.New("not enough arguments")
}

if flags.remove && flags.outFile != "" {
if err := os.Remove(flags.outFile); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return err
}
}
}

var buf bytes.Buffer
var out io.Writer = os.Stdout
if flags.outFile != "" {
Expand Down