/
app.go
49 lines (41 loc) · 915 Bytes
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package chain
import (
"path/filepath"
"github.com/ignite/cli/ignite/pkg/gomodulepath"
"github.com/ignite/cli/ignite/pkg/xstrings"
)
// App keeps info about chain.
type App struct {
Name string
Path string
ImportPath string
}
// NewAppAt creates an App from the blockchain source code located at path.
func NewAppAt(path string) (App, error) {
p, appPath, err := gomodulepath.Find(path)
if err != nil {
return App{}, err
}
return App{
Path: appPath,
Name: p.Root,
ImportPath: p.RawPath,
}, nil
}
// N returns app name without dashes.
func (a App) N() string {
return xstrings.NoDash(a.Name)
}
// D returns appd name.
func (a App) D() string {
return a.Name + "d"
}
// ND returns no-dash appd name.
func (a App) ND() string {
return a.N() + "d"
}
// Root returns the root path of app.
func (a App) Root() string {
path, _ := filepath.Abs(a.Path)
return path
}