Skip to content

Commit

Permalink
fix: immediately exit when given -version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed May 29, 2023
1 parent 33c2693 commit c5876f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 0 additions & 3 deletions cmd/yamlfmt/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ func getOperationFromFlag() command.Operation {
if *flagDry {
return command.OperationDry
}
if *flagVersion {
return command.OperationVersion
}
return command.OperationFormat
}

Expand Down
11 changes: 11 additions & 0 deletions cmd/yamlfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/google/yamlfmt"
"github.com/google/yamlfmt/command"
Expand All @@ -36,6 +38,15 @@ func run() error {
configureHelp()
flag.Parse()

if *flagVersion {
_, err := fmt.Printf("%s\n", version)
if err != nil {
return err
}

os.Exit(0)
}

c := &command.Command{
Operation: getOperationFromFlag(),
Registry: getFullRegistry(),
Expand Down
3 changes: 0 additions & 3 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
OperationLint
OperationDry
OperationStdin
OperationVersion
)

type FormatterConfig struct {
Expand Down Expand Up @@ -161,8 +160,6 @@ func (c *Command) Run(version string) error {
return err
}
fmt.Print(string(out))
case OperationVersion:
fmt.Printf("%s\n", version)
}

return nil
Expand Down

0 comments on commit c5876f3

Please sign in to comment.