diff --git a/changelog.md b/changelog.md index eb2f355be2..58b68dece1 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ * Running `appcli tx app create-x` now checks for all required args. -#173. * Removed unused `--denom` flag from the `app` command. It previously has moved as a prop to the `config.yml` under `accounts` section. * Disabled proxy server in the Vue app (this was causing to some compatibilitiy issues) and enabled CORS for `appcli rest-server` instead. +* `type` command supports dashes in app names. ## `v0.0.10-rc.3` diff --git a/go.mod b/go.mod index 6b9e883564..14f6b6b632 100644 --- a/go.mod +++ b/go.mod @@ -32,4 +32,5 @@ require ( golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect + golang.org/x/tools v0.0.0-20200828161849-5deb26317202 // indirect ) diff --git a/go.sum b/go.sum index 4f049167f7..d1fecd0963 100644 --- a/go.sum +++ b/go.sum @@ -81,6 +81,7 @@ github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7T github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= github.com/gobuffalo/packd v1.0.0 h1:6ERZvJHfe24rfFmA9OaoKBdC7+c9sydrytMg8SdFGBM= github.com/gobuffalo/packd v1.0.0/go.mod h1:6VTc4htmJRFB7u1m/4LeMTWjFoYrUiBkU9Fdec9hrhI= +github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= github.com/gobuffalo/packr/v2 v2.7.1/go.mod h1:qYEvAazPaVxy7Y7KR0W8qYEE+RymX74kETFqjFoFlOc= github.com/gobuffalo/packr/v2 v2.8.0 h1:IULGd15bQL59ijXLxEvA5wlMxsmx/ZkQv9T282zNVIY= github.com/gobuffalo/packr/v2 v2.8.0/go.mod h1:PDk2k3vGevNE3SwVyVRgQCCXETC9SaONCNSXT1Q8M1g= @@ -262,6 +263,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g= github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -336,6 +338,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191224055732-dd894d0a8a40/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 h1:9Di9iYgOt9ThCipBxChBVhgNipDoE5mxO84rQV7D0FE= golang.org/x/tools v0.0.0-20200308013534-11ec41452d41/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200828161849-5deb26317202 h1:DrWbY9UUFi/sl/3HkNVoBjDbGfIPZZfgoGsGxOL1EU8= +golang.org/x/tools v0.0.0-20200828161849-5deb26317202/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/starport/interface/cli/starport/cmd/add.go b/starport/interface/cli/starport/cmd/add.go index 3d108792f2..91657d75f4 100644 --- a/starport/interface/cli/starport/cmd/add.go +++ b/starport/interface/cli/starport/cmd/add.go @@ -11,6 +11,7 @@ import ( "github.com/gobuffalo/genny" "github.com/spf13/cobra" + "github.com/tendermint/starport/starport/pkg/gomodulepath" "github.com/tendermint/starport/starport/templates/add" ) @@ -37,10 +38,13 @@ func addHandler(cmd *cobra.Command, args []string) error { if ok { return errors.New("CosmWasm is already added.") } - appName, _ := getAppAndModule(appPath) + path, err := gomodulepath.Parse(getModule(appPath)) + if err != nil { + return err + } g, _ := add.New(&add.Options{ Feature: args[0], - AppName: appName, + AppName: path.Package, }) run := genny.WetRunner(context.Background()) run.With(g) diff --git a/starport/interface/cli/starport/cmd/cmd.go b/starport/interface/cli/starport/cmd/cmd.go index 0a379cc658..a21aa49198 100644 --- a/starport/interface/cli/starport/cmd/cmd.go +++ b/starport/interface/cli/starport/cmd/cmd.go @@ -24,16 +24,12 @@ func New() *cobra.Command { return c } -func getAppAndModule(path string) (string, string) { +func getModule(path string) string { goModFile, err := ioutil.ReadFile(filepath.Join(path, "go.mod")) if err != nil { log.Fatal(err) } moduleString := strings.Split(string(goModFile), "\n")[0] modulePath := strings.ReplaceAll(moduleString, "module ", "") - var appName string - if t := strings.Split(modulePath, "/"); len(t) > 0 { - appName = t[len(t)-1] - } - return appName, modulePath + return modulePath } diff --git a/starport/interface/cli/starport/cmd/serve.go b/starport/interface/cli/starport/cmd/serve.go index 92a3b4da91..92da5cedd6 100644 --- a/starport/interface/cli/starport/cmd/serve.go +++ b/starport/interface/cli/starport/cmd/serve.go @@ -7,6 +7,7 @@ import ( "os/signal" "github.com/spf13/cobra" + "github.com/tendermint/starport/starport/pkg/gomodulepath" starportserve "github.com/tendermint/starport/starport/services/serve" ) @@ -26,9 +27,12 @@ func NewServe() *cobra.Command { func serveHandler(cmd *cobra.Command, args []string) error { verbose, _ := cmd.Flags().GetBool("verbose") - appName, _ := getAppAndModule(appPath) + path, err := gomodulepath.Parse(getModule(appPath)) + if err != nil { + return err + } app := starportserve.App{ - Name: appName, + Name: path.Root, Path: appPath, } @@ -42,7 +46,7 @@ func serveHandler(cmd *cobra.Command, args []string) error { cancel() }() - err := starportserve.Serve(ctx, app, verbose) + err = starportserve.Serve(ctx, app, verbose) if err == context.Canceled { fmt.Println("aborted") return nil diff --git a/starport/interface/cli/starport/cmd/type.go b/starport/interface/cli/starport/cmd/type.go index f11a1c2c49..227c15a112 100644 --- a/starport/interface/cli/starport/cmd/type.go +++ b/starport/interface/cli/starport/cmd/type.go @@ -12,6 +12,7 @@ import ( "github.com/gobuffalo/genny" "github.com/spf13/cobra" + "github.com/tendermint/starport/starport/pkg/gomodulepath" "github.com/tendermint/starport/starport/templates/typed" ) @@ -27,9 +28,12 @@ func NewType() *cobra.Command { } func typeHandler(cmd *cobra.Command, args []string) error { - appName, modulePath := getAppAndModule(appPath) + path, err := gomodulepath.Parse(getModule(appPath)) + if err != nil { + return err + } typeName := args[0] - ok, err := isTypeCreated(appPath, appName, typeName) + ok, err := isTypeCreated(appPath, path.Package, typeName) if err != nil { return err } @@ -56,8 +60,8 @@ func typeHandler(cmd *cobra.Command, args []string) error { fields = append(fields, field) } g, _ := typed.New(&typed.Options{ - ModulePath: modulePath, - AppName: appName, + ModulePath: path.RawPath, + AppName: path.Package, TypeName: typeName, Fields: fields, }) diff --git a/starport/services/serve/serve.go b/starport/services/serve/serve.go index 047d394354..789443a71a 100644 --- a/starport/services/serve/serve.go +++ b/starport/services/serve/serve.go @@ -198,6 +198,7 @@ func (s *starportServe) serve(ctx context.Context) error { if err != nil { return err } + rootPath := filepath.Join(cwd, s.app.Path) conf, err := s.config() if err != nil { return &CannotBuildAppError{err} @@ -205,7 +206,7 @@ func (s *starportServe) serve(ctx context.Context) error { if err := cmdrunner. New(opts...). - Run(ctx, s.buildSteps(ctx, conf, cwd)...); err != nil { + Run(ctx, s.buildSteps(ctx, conf, rootPath)...); err != nil { return err } return cmdrunner. diff --git a/starport/templates/app/templates/cmd/{{binaryNamePrefix}}cli/main.go.plush b/starport/templates/app/templates/cmd/{{binaryNamePrefix}}cli/main.go.plush index d233de519f..c6403f7532 100644 --- a/starport/templates/app/templates/cmd/{{binaryNamePrefix}}cli/main.go.plush +++ b/starport/templates/app/templates/cmd/{{binaryNamePrefix}}cli/main.go.plush @@ -41,7 +41,7 @@ func main() { // with the cdc rootCmd := &cobra.Command{ - Use: "<%= AppName %>cli", + Use: "<%= BinaryNamePrefix %>cli", Short: "Command line interface for interacting with <%= AppName %>d", } diff --git a/starport/templates/app/templates/cmd/{{binaryNamePrefix}}d/main.go.plush b/starport/templates/app/templates/cmd/{{binaryNamePrefix}}d/main.go.plush index 6935450eee..d5a0c8f0e5 100644 --- a/starport/templates/app/templates/cmd/{{binaryNamePrefix}}d/main.go.plush +++ b/starport/templates/app/templates/cmd/{{binaryNamePrefix}}d/main.go.plush @@ -38,7 +38,7 @@ func main() { ctx := server.NewDefaultContext() cobra.EnableCommandSorting = false rootCmd := &cobra.Command{ - Use: "<%= AppName %>d", + Use: "<%= BinaryNamePrefix %>d", Short: "app Daemon (server)", PersistentPreRunE: server.PersistentPreRunEFn(ctx), }