Просмотр исходного кода

Move config path cli parameter to base

tags/v2.0.0-rc1
9seconds 5 лет назад
Родитель
Сommit
0ad2d61742
4 измененных файлов: 12 добавлений и 12 удалений
  1. 2
    4
      cli/access.go
  2. 6
    4
      cli/base.go
  3. 4
    2
      cli/base_internal_test.go
  4. 0
    2
      cli/generate_secret.go

+ 2
- 4
cli/access.go Просмотреть файл

@@ -34,18 +34,16 @@ type accessResponseURLs struct {
34 34
 }
35 35
 
36 36
 type Access struct {
37
-	base `kong:"-"`
37
+	base
38 38
 
39 39
 	PublicIPv4 net.IP `kong:"help='Public IPv4 address for proxy. By default it is resolved via remote website',name='ipv4',short='i'"`   // nolint: lll
40 40
 	PublicIPv6 net.IP `kong:"help='Public IPv6 address for proxy. By default it is resolved via remote website',name='ipv6',short='I'"`   // nolint: lll
41 41
 	Port       uint   `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
42 42
 	Hex        bool   `kong:"help='Print secret in hex encoding.',short='x'"`
43
-
44
-	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
45 43
 }
46 44
 
47 45
 func (c *Access) Run(cli *CLI, version string) error {
48
-	if err := c.ReadConfig(cli.Access.ConfigPath, version); err != nil {
46
+	if err := c.ReadConfig(version); err != nil {
49 47
 		return fmt.Errorf("cannot init config: %w", err)
50 48
 	}
51 49
 

+ 6
- 4
cli/base.go Просмотреть файл

@@ -12,12 +12,14 @@ import (
12 12
 )
13 13
 
14 14
 type base struct {
15
-	Network mtglib.Network
16
-	Config  *config.Config
15
+	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` // nolint: lll
16
+
17
+	Network mtglib.Network `kong:"-"`
18
+	Config  *config.Config `kong:"-"`
17 19
 }
18 20
 
19
-func (b *base) ReadConfig(path, version string) error {
20
-	content, err := ioutil.ReadFile(path)
21
+func (b *base) ReadConfig(version string) error {
22
+	content, err := ioutil.ReadFile(b.ConfigPath)
21 23
 	if err != nil {
22 24
 		return fmt.Errorf("cannot read config file: %w", err)
23 25
 	}

+ 4
- 2
cli/base_internal_test.go Просмотреть файл

@@ -18,11 +18,13 @@ func (suite *BaseTestSuite) SetupTest() {
18 18
 }
19 19
 
20 20
 func (suite *BaseTestSuite) TestReadConfigNok() {
21
-	suite.Error(suite.b.ReadConfig(filepath.Join("testdata", "unknown"), "dev"))
21
+	suite.b.ConfigPath = filepath.Join("testdata", "unknown")
22
+	suite.Error(suite.b.ReadConfig("dev"))
22 23
 }
23 24
 
24 25
 func (suite *BaseTestSuite) TestReadConfig() {
25
-	suite.NoError(suite.b.ReadConfig(filepath.Join("testdata", "minimal.toml"), "dev"))
26
+	suite.b.ConfigPath = filepath.Join("testdata", "minimal.toml")
27
+	suite.NoError(suite.b.ReadConfig("dev"))
26 28
 }
27 29
 
28 30
 func TestBase(t *testing.T) {

+ 0
- 2
cli/generate_secret.go Просмотреть файл

@@ -7,8 +7,6 @@ import (
7 7
 )
8 8
 
9 9
 type GenerateSecret struct {
10
-	base `kong:"-"`
11
-
12 10
 	HostName string `kong:"arg,required,help='Hostname to use for domain fronting.',name='hostname'"`
13 11
 	Hex      bool   `kong:"help='Print secret in hex encoding.',short='x'"`
14 12
 }

Загрузка…
Отмена
Сохранить