Skip to content

Commit

Permalink
Correctly handle --out option with goagen swagger
Browse files Browse the repository at this point in the history
Also use relative path in generated file comments for --out option.
  • Loading branch information
raphael committed Nov 19, 2015
1 parent 3a186c4 commit 5ccb9df
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/cellar/app/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
// --pkg=app
//
Expand Down
2 changes: 1 addition & 1 deletion examples/cellar/app/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
// --pkg=app
//
Expand Down
2 changes: 1 addition & 1 deletion examples/cellar/app/hrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
// --pkg=app
//
Expand Down
2 changes: 1 addition & 1 deletion examples/cellar/app/media_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
// --pkg=app
//
Expand Down
2 changes: 1 addition & 1 deletion examples/cellar/app/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
// --pkg=app
//
Expand Down
2 changes: 1 addition & 1 deletion examples/cellar/swagger/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Generated with goagen v0.0.1, command line:
// $ goagen
// --out=/home/raphael/go/src/github.com/raphael/goa/examples/cellar
// --out=.
// --design=github.com/raphael/goa/examples/cellar/design
//
// The content of this file is auto-generated, DO NOT MODIFY
Expand Down
2 changes: 1 addition & 1 deletion goagen/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (a *BootstrapCommand) Name() string { return "bootstrap" }

// Description returns the command description.
func (a *BootstrapCommand) Description() string {
return `Bootstrap command, equivalent to running "app", "main" and "schema" commands sequentially.`
return `Bootstrap command, equivalent to running "app", "main" and "swagger" commands sequentially.`
}

// RegisterFlags registers all the sub-commands flags.
Expand Down
9 changes: 2 additions & 7 deletions goagen/codegen/command.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package codegen

import (
"os"

"gopkg.in/alecthomas/kingpin.v2"
)
import "gopkg.in/alecthomas/kingpin.v2"

var (
// OutputDir is the path to the directory the generated files should be
Expand Down Expand Up @@ -56,9 +52,8 @@ type (

// RegisterFlags registers the global flags.
func RegisterFlags(r FlagRegistry) {
cwd, _ := os.Getwd()
r.Flag("out", "output directory").
Default(cwd).
Default(".").
Short('o').
StringVar(&OutputDir)

Expand Down
10 changes: 10 additions & 0 deletions goagen/gen_swagger/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"

"gopkg.in/alecthomas/kingpin.v2"

"github.com/raphael/goa/design"
"github.com/raphael/goa/goagen/codegen"
)

// Generate is the generator entry point called by the meta generator.
func Generate(api *design.APIDefinition) ([]string, error) {
app := kingpin.New("Swagger generator", "Swagger spec generator")
codegen.RegisterFlags(app)
_, err := app.Parse(os.Args[1:])
if err != nil {
return nil, fmt.Errorf(`invalid command line: %s. Command line was "%s"`,
err, strings.Join(os.Args, " "))
}
s, err := New(api)
if err != nil {
return nil, err
Expand Down
9 changes: 4 additions & 5 deletions goagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ func command() codegen.Command {
return nil
}

const help = `The goagen tool generates various artifacts from a goa application design
package (metadata).
const help = `The goagen tool generates various artifacts from a goa service design package.
Each command supported by the tool produces a specific type of artifacts. For example
the "app" command generates the code that supports the application controllers.
the "app" command generates the code that supports the service controllers.
The "bootstrap" command runs the "app", "main" and "schema" commands generating the
The "bootstrap" command runs the "app", "main" and "swagger" commands generating the
controllers supporting code and main skeleton code (if not already present) as well as
the API JSON hyper-schema.
the API Swagger specification.
`

0 comments on commit 5ccb9df

Please sign in to comment.