@@ -66,12 +66,10 @@ func findModuleRoot(dir string) (roots string) {
6666
6767func initFile (filename , contents string ) error {
6868 if err := os .MkdirAll (filepath .Dir (filename ), 0o755 ); err != nil {
69- //nolint:staticcheck // yes, it is bad to end in newline here
70- return fmt .Errorf ("unable to create directory for file '%s': %w\n " , filename , err )
69+ return fmt .Errorf ("unable to create directory for file '%s': %w" , filename , err )
7170 }
7271 if err := os .WriteFile (filename , []byte (contents ), 0o644 ); err != nil {
73- //nolint:staticcheck // yes, it is bad to end in newline here
74- return fmt .Errorf ("unable to write file '%s': %w\n " , filename , err )
72+ return fmt .Errorf ("unable to write file '%s': %w" , filename , err )
7573 }
7674
7775 return nil
@@ -101,7 +99,6 @@ var initCmd = &cli.Command{
10199
102100 cwd , err := os .Getwd ()
103101 if err != nil {
104- log .Println (err )
105102 return fmt .Errorf ("unable to determine current directory: %w" , err )
106103 }
107104 pkgName := code .ImportPathForDir (cwd )
@@ -112,8 +109,7 @@ var initCmd = &cli.Command{
112109 }
113110 modRoot := findModuleRoot (cwd )
114111 if modRoot == "" {
115- //nolint:staticcheck // yes, it is bad to end in newline here
116- return errors .New ("go.mod is missing. Please, do 'go mod init' first\n " )
112+ return cli .Exit ("go.mod is missing. Please, do 'go mod init' first\n " , 1 )
117113 }
118114
119115 // check schema and config don't already exist
@@ -124,28 +120,27 @@ var initCmd = &cli.Command{
124120 }
125121 _ , err = config .LoadConfigFromDefaultLocations ()
126122 if err == nil {
127- //nolint:staticcheck // yes, it is bad to end in newline here
128- return errors .New ("gqlgen.yml already exists in a parent directory\n " )
123+ return cli .Exit ("gqlgen.yml already exists in a parent directory\n " , 1 )
129124 }
130125
131126 // create config
132127 fmt .Println ("Creating" , configFilename )
133128 if err := initFile (configFilename , getConfigFileContent (pkgName )); err != nil {
134- return err
129+ return cli . Exit ( err . Error () + " \n " , 1 )
135130 }
136131
137132 // create schema
138133 fmt .Println ("Creating" , schemaFilename )
139134
140135 if err := initFile (schemaFilename , schemaFileContent ); err != nil {
141- return err
136+ return cli . Exit ( err . Error () + " \n " , 1 )
142137 }
143138
144139 // create the package directory with a temporary file so that go recognises it as a package
145140 // and autobinding doesn't error out
146141 tmpPackageNameFile := "graph/model/_tmp_gqlgen_init.go"
147142 if err := initFile (tmpPackageNameFile , "package model" ); err != nil {
148- return err
143+ return cli . Exit ( err . Error () + " \n " , 1 )
149144 }
150145 defer os .Remove (tmpPackageNameFile )
151146
0 commit comments