Move config path cli parameter to base

This commit is contained in:
9seconds
2021-03-18 15:20:54 +03:00
parent f155b9f37e
commit 0ad2d61742
4 changed files with 12 additions and 12 deletions
+2 -4
View File
@@ -34,18 +34,16 @@ type accessResponseURLs struct {
}
type Access struct {
base `kong:"-"`
base
PublicIPv4 net.IP `kong:"help='Public IPv4 address for proxy. By default it is resolved via remote website',name='ipv4',short='i'"` // nolint: lll
PublicIPv6 net.IP `kong:"help='Public IPv6 address for proxy. By default it is resolved via remote website',name='ipv6',short='I'"` // nolint: lll
Port uint `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
Hex bool `kong:"help='Print secret in hex encoding.',short='x'"`
ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
}
func (c *Access) Run(cli *CLI, version string) error {
if err := c.ReadConfig(cli.Access.ConfigPath, version); err != nil {
if err := c.ReadConfig(version); err != nil {
return fmt.Errorf("cannot init config: %w", err)
}
+6 -4
View File
@@ -12,12 +12,14 @@ import (
)
type base struct {
Network mtglib.Network
Config *config.Config
ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
Network mtglib.Network `kong:"-"`
Config *config.Config `kong:"-"`
}
func (b *base) ReadConfig(path, version string) error {
content, err := ioutil.ReadFile(path)
func (b *base) ReadConfig(version string) error {
content, err := ioutil.ReadFile(b.ConfigPath)
if err != nil {
return fmt.Errorf("cannot read config file: %w", err)
}
+4 -2
View File
@@ -18,11 +18,13 @@ func (suite *BaseTestSuite) SetupTest() {
}
func (suite *BaseTestSuite) TestReadConfigNok() {
suite.Error(suite.b.ReadConfig(filepath.Join("testdata", "unknown"), "dev"))
suite.b.ConfigPath = filepath.Join("testdata", "unknown")
suite.Error(suite.b.ReadConfig("dev"))
}
func (suite *BaseTestSuite) TestReadConfig() {
suite.NoError(suite.b.ReadConfig(filepath.Join("testdata", "minimal.toml"), "dev"))
suite.b.ConfigPath = filepath.Join("testdata", "minimal.toml")
suite.NoError(suite.b.ReadConfig("dev"))
}
func TestBase(t *testing.T) {
-2
View File
@@ -7,8 +7,6 @@ import (
)
type GenerateSecret struct {
base `kong:"-"`
HostName string `kong:"arg,required,help='Hostname to use for domain fronting.',name='hostname'"`
Hex bool `kong:"help='Print secret in hex encoding.',short='x'"`
}