forked from forbole/juno
/
config.go
53 lines (45 loc) · 1.22 KB
/
config.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
50
51
52
53
package cmd
import (
initcmd "github.com/chain4energy/juno/v4/cmd/init"
parsecmd "github.com/chain4energy/juno/v4/cmd/parse/types"
)
// Config represents the general configuration for the commands
type Config struct {
name string
initConfig *initcmd.Config
parseConfig *parsecmd.Config
}
// NewConfig allows to build a new Config instance
func NewConfig(name string) *Config {
return &Config{
name: name,
}
}
// GetName returns the name of the root command
func (c *Config) GetName() string {
return c.name
}
// WithInitConfig sets cfg as the parse command configuration
func (c *Config) WithInitConfig(cfg *initcmd.Config) *Config {
c.initConfig = cfg
return c
}
// GetInitConfig returns the currently set parse configuration
func (c *Config) GetInitConfig() *initcmd.Config {
if c.initConfig == nil {
return initcmd.NewConfig()
}
return c.initConfig
}
// WithParseConfig sets cfg as the parse command configuration
func (c *Config) WithParseConfig(cfg *parsecmd.Config) *Config {
c.parseConfig = cfg
return c
}
// GetParseConfig returns the currently set parse configuration
func (c *Config) GetParseConfig() *parsecmd.Config {
if c.parseConfig == nil {
return parsecmd.NewConfig()
}
return c.parseConfig
}