mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:24:03 +03:00
Move config path cli parameter to base
This commit is contained in:
+2
-4
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user