Skip to content

Commit

Permalink
handle --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Jul 14, 2021
1 parent 9e178fc commit 9487668
Showing 1 changed file with 3 additions and 38 deletions.
41 changes: 3 additions & 38 deletions cmd/schemalex-deploy/schemalex-deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"runtime"
"runtime/debug"

"github.com/shogo82148/schemalex-deploy"
"github.com/shogo82148/schemalex-deploy/diff"
"github.com/shogo82148/schemalex-deploy/internal/errors"
)

func main() {
Expand All @@ -21,9 +17,7 @@ func main() {
}

func _main() error {
var txn bool
var version bool
var outfile string

flag.Usage = func() {
// TODO: fill the usage
Expand All @@ -32,6 +26,7 @@ func _main() error {
schemalex -version
`, getVersion())
}
flag.BoolVar(&version, "version", false, "show the version")
flag.Parse()

if version {
Expand All @@ -45,38 +40,8 @@ schemalex -version
return nil
}

if flag.NArg() != 2 {
flag.Usage()
return errors.New("wrong number of arguments")
}

var dst io.Writer = os.Stdout
if len(outfile) > 0 {
f, err := os.OpenFile(outfile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return errors.Wrapf(err, `failed to open file %s for writing`, outfile)
}
dst = f
defer f.Close()
}

fromSource, err := schemalex.NewSchemaSource(flag.Arg(0))
if err != nil {
return errors.Wrap(err, `failed to create schema source for "from"`)
}

toSource, err := schemalex.NewSchemaSource(flag.Arg(1))
if err != nil {
return errors.Wrap(err, `failed to create schema source for "to"`)
}

p := schemalex.New()
return diff.Sources(
dst,
fromSource,
toSource,
diff.WithTransaction(txn), diff.WithParser(p),
)
fmt.Println("TODO: implement")
return nil
}

func getVersion() string {
Expand Down

0 comments on commit 9487668

Please sign in to comment.