Skip to content

Commit

Permalink
type command: supports dashes in app names (#210)
Browse files Browse the repository at this point in the history
* type command: supports dashes in app names

* update changelog

* services/serve: fix determining root path of the app

* services/serve: fix binary name in the appd and appcli

* trig ci
  • Loading branch information
ilgooz authored Aug 31, 2020
1 parent fb54cd0 commit 662619b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 6 additions & 2 deletions starport/interface/cli/starport/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions starport/interface/cli/starport/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 7 additions & 3 deletions starport/interface/cli/starport/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
}

Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions starport/interface/cli/starport/cmd/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand All @@ -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,
})
Expand Down
3 changes: 2 additions & 1 deletion starport/services/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ 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}
}

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit 662619b

Please sign in to comment.