Skip to content

Commit

Permalink
fix: Update all flag incorrectly set
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedalhulaibi committed Mar 7, 2018
1 parent f199a4e commit ad5bcb6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ var updateGqlFields bool
var updateGqlTypes bool
var updateModel bool
var updateMain bool
var updateAll bool

func init() {
generate.Flags().BoolVarP(&updateSchema, "update-schema", "u", false, "update and overwrite schema.graphql")
generate.Flags().BoolVarP(&updateGormQueries, "update-gormQueries", "q", false, "update and overwrite gormQueries.go")
generate.Flags().BoolVarP(&updateGqlFields, "update-gqlFields", "g", false, "update and overwrite graphqlFields.go")
generate.Flags().BoolVarP(&updateGqlTypes, "update-gqlTypes", "t", false, "update and overwrite graphqlTypes.go")
generate.Flags().BoolVarP(&updateMain, "update-main", "m", false, "update and overwrite main.go")
generate.Flags().BoolVarP(&updateModel, "update-all", "a", false, "update and overwrite all files")
generate.Flags().BoolVarP(&updateModel, "update-gormStruct", "s", false, "update and overwrite model.go")
generate.Flags().BoolVarP(&updateAll, "update-all", "a", false, "update and overwrite all files")
RootCmd.AddCommand(generate)
}

Expand All @@ -46,10 +48,10 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
gqlGen.AddJSONTagsToProperties(gqlObjectTypes)

if gqlPkg.GenMode == "graphql-go" {
if !updateGormQueries && !updateGqlFields && !updateGqlTypes && !updateModel && !updateSchema && !updateMain {
if !updateGormQueries && !updateGqlFields && !updateGqlTypes && !updateModel && !updateSchema && !updateMain && !updateAll {
cmd.Help()
}
if updateMain {
if updateMain || updateAll {
mainFile := createFile("main.go", true)

var mainFileBuffer bytes.Buffer
Expand All @@ -63,7 +65,7 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
mainFile.Close()
}

if updateGqlTypes {
if updateGqlTypes || updateAll {
graphqlTypesFile := createFile("graphqlTypes.go", true)

var graphqlTypesFileBuff bytes.Buffer
Expand All @@ -78,7 +80,7 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
graphqlTypesFile.Close()
}

if updateModel {
if updateModel || updateAll {
dataModelFile := createFile("model.go", true)

var dataModelFileBuff bytes.Buffer
Expand All @@ -94,7 +96,7 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
dataModelFile.Close()
}

if updateGqlFields {
if updateGqlFields || updateAll {
gqlFieldsFile := createFile("graphqlFields.go", true)

var gqlFieldsFileBuff bytes.Buffer
Expand All @@ -107,7 +109,7 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
gqlFieldsFile.Close()
}

if updateGormQueries {
if updateGormQueries || updateAll {
gormQueriesFile := createFile("gormQueries.go", true)

var gormQueriesFileBuff bytes.Buffer
Expand All @@ -122,7 +124,7 @@ Run 'graphqlator init' before running 'graphqlator generate'`,
gormQueriesFile.Close()
}

if updateSchema {
if updateSchema || updateAll {
graphqlSchemaFile := createFile("schema.graphql", true)
graphqlSchemaFileBuffer := gqlGen.OutputGraphqlSchema(gqlObjectTypes)
_, err := graphqlSchemaFile.Write(graphqlSchemaFileBuffer.Bytes())
Expand Down

0 comments on commit ad5bcb6

Please sign in to comment.