@@ -30,25 +30,8 @@ func main() {
3030func 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
8369func 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