Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit ef39bfa

Browse files
authored
Merge pull request #4 from Code-Hex/fix/main-code
fixed behavior to run command
2 parents 22cdff9 + 28c1208 commit ef39bfa

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

cmd/gqldoc/main.go

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,8 @@ func main() {
3030
func run(ctx context.Context) error {
3131
app := cli.NewApp()
3232
app.Name = "gqldoc"
33-
app.Usage = genCmd.Usage
3433
app.Description = "This is a command for quickly generating documents from graphql schema in golang."
35-
app.HideVersion = true
36-
app.Flags = genCmd.Flags
37-
app.Version = Version
38-
39-
app.Action = genCmd.Action
40-
app.Commands = []*cli.Command{
41-
genCmd,
42-
}
43-
44-
return app.Run(os.Args)
45-
}
46-
47-
var genCmd = &cli.Command{
48-
Name: "generate",
49-
Aliases: []string{"gen"},
50-
Usage: "generate documents based on graphql schema or server",
51-
Flags: []cli.Flag{
34+
app.Flags = []cli.Flag{
5235
&cli.StringFlag{
5336
Name: "endpoint",
5437
Aliases: []string{"e"},
@@ -67,17 +50,20 @@ var genCmd = &cli.Command{
6750
&cli.StringSliceFlag{
6851
Name: "schema",
6952
Aliases: []string{"s"},
70-
Usage: `GraphQL schema file. "1 json graphql schema" or "1 or more graphql files (.graphql, .qgl)".`,
53+
Usage: `GraphQL schema file. "1 json graphql schema" or "1 or more graphql files (.graphqls, .graphql, .gql)".`,
7154
},
7255
&cli.StringFlag{
7356
Name: "output",
7457
Aliases: []string{"o"},
7558
Usage: `Output directory.`,
7659
},
77-
},
78-
Action: func(ctx *cli.Context) error {
60+
}
61+
app.Version = Version
62+
app.Action = func(ctx *cli.Context) error {
7963
return generateCommand(ctx)
80-
},
64+
}
65+
66+
return app.Run(os.Args)
8167
}
8268

8369
func generateCommand(ctx *cli.Context) (err error) {
@@ -132,19 +118,19 @@ func convertSchemaTree(schemaFiles []string) (*introspection.Root, error) {
132118
return &schema, nil
133119
}
134120

135-
gqlfiles := make([]string, 0, len(schemaFiles))
121+
if len(schemaFiles) == 0 {
122+
return nil, errHelp
123+
}
124+
136125
for _, schema := range schemaFiles {
137126
switch filepath.Ext(schema) {
138-
case ".graphql", ".gql":
139-
gqlfiles = append(gqlfiles, schema)
127+
case ".graphqls", ".graphql", ".gql":
128+
default:
129+
return nil, errHelp
140130
}
141131
}
142132

143-
if len(gqlfiles) == 0 {
144-
return nil, errHelp
145-
}
146-
147-
schema, err := loader.LoadSchema(gqlfiles...)
133+
schema, err := loader.LoadSchema(schemaFiles...)
148134
if err != nil {
149135
return nil, errors.WithStack(err)
150136
}

0 commit comments

Comments
 (0)