From 0ad2d6174269f9c9b0ed100c782c31b250aeceb5 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Thu, 18 Mar 2021 15:20:54 +0300 Subject: [PATCH] Move config path cli parameter to base --- cli/access.go | 6 ++---- cli/base.go | 10 ++++++---- cli/base_internal_test.go | 6 ++++-- cli/generate_secret.go | 2 -- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/access.go b/cli/access.go index d6212b6..b020372 100644 --- a/cli/access.go +++ b/cli/access.go @@ -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) } diff --git a/cli/base.go b/cli/base.go index f4b6635..9c19ec1 100644 --- a/cli/base.go +++ b/cli/base.go @@ -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) } diff --git a/cli/base_internal_test.go b/cli/base_internal_test.go index 1cd0b97..51909d4 100644 --- a/cli/base_internal_test.go +++ b/cli/base_internal_test.go @@ -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) { diff --git a/cli/generate_secret.go b/cli/generate_secret.go index e618dfd..e3fb0e8 100644 --- a/cli/generate_secret.go +++ b/cli/generate_secret.go @@ -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'"` }