This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from go-generalize/tsuzu/move-to-sub-packages
Move main logic to /generator and Refactor it
- Loading branch information
Showing
45 changed files
with
994 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Binary Files | ||
firestore-repo | ||
./bin/firestore-repo | ||
statik/ | ||
|
||
# etc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-generalize/firestore-repo/generator" | ||
) | ||
|
||
var ( | ||
isShowVersion = flag.Bool("v", false, "print version") | ||
isSubCollection = flag.Bool("sub-collection", false, "is SubCollection") | ||
disableMeta = flag.Bool("disable-meta", false, "Disable meta embed") | ||
outputDir = flag.String("o", "./", "Specify directory to generate code in") | ||
packageName = flag.String("p", "", "Specify the package name, default is the same as the original package") | ||
mockGenPath = flag.String("mockgen", "mockgen", "Specify mockgen path") | ||
mockOutputPath = flag.String("mock-output", "mock/mock_{{ .GeneratedFileName }}/mock_{{ .GeneratedFileName }}.go", "Specify directory to generate mock code in") | ||
) | ||
|
||
func main() { | ||
appVersion := getAppVersion() | ||
|
||
if *isShowVersion { | ||
fmt.Printf("Firestore Model Generator: %s\n", appVersion) | ||
return | ||
} | ||
|
||
l := flag.NArg() | ||
if l < 1 { | ||
fmt.Fprintln(os.Stderr, "You have to specify the struct name of target") | ||
os.Exit(1) | ||
} | ||
|
||
gen, err := generator.NewGenerator(".") | ||
|
||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to initialize generator: %+v\n", err) | ||
os.Exit(1) | ||
} | ||
gen.AppVersion = appVersion | ||
|
||
structName := flag.Arg(0) | ||
|
||
err = gen.Generate(structName, generator.GenerateOption{ | ||
OutputDir: *outputDir, | ||
PackageName: *packageName, | ||
MockGenPath: *mockGenPath, | ||
MockOutputPath: *mockOutputPath, | ||
UseMetaField: !*disableMeta, | ||
Subcollection: *isSubCollection, | ||
}) | ||
|
||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to generate repository for %s: %+v\n", structName, err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import "runtime/debug" | ||
|
||
func getAppVersion() string { | ||
bi, ok := debug.ReadBuildInfo() | ||
|
||
if !ok { | ||
return "devel" | ||
} | ||
|
||
return bi.Main.Version | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.