Explorar el Código

Move config path cli parameter to base

tags/v2.0.0-rc1
9seconds hace 5 años
padre
commit
0ad2d61742
Se han modificado 4 ficheros con 12 adiciones y 12 borrados
  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 Ver fichero

34
 }
34
 }
35
 
35
 
36
 type Access struct {
36
 type Access struct {
37
-	base `kong:"-"`
37
+	base
38
 
38
 
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
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
 	PublicIPv6 net.IP `kong:"help='Public IPv6 address for proxy. By default it is resolved via remote website',name='ipv6',short='I'"`   // nolint: lll
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
 	Port       uint   `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
41
 	Port       uint   `kong:"help='Port number. Default port is taken from configuration file, bind-to parameter',type:'uint',short='p'"` // nolint: lll
42
 	Hex        bool   `kong:"help='Print secret in hex encoding.',short='x'"`
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
 func (c *Access) Run(cli *CLI, version string) error {
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
 		return fmt.Errorf("cannot init config: %w", err)
47
 		return fmt.Errorf("cannot init config: %w", err)
50
 	}
48
 	}
51
 
49
 

+ 6
- 4
cli/base.go Ver fichero

12
 )
12
 )
13
 
13
 
14
 type base struct {
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
 	if err != nil {
23
 	if err != nil {
22
 		return fmt.Errorf("cannot read config file: %w", err)
24
 		return fmt.Errorf("cannot read config file: %w", err)
23
 	}
25
 	}

+ 4
- 2
cli/base_internal_test.go Ver fichero

18
 }
18
 }
19
 
19
 
20
 func (suite *BaseTestSuite) TestReadConfigNok() {
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
 func (suite *BaseTestSuite) TestReadConfig() {
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
 func TestBase(t *testing.T) {
30
 func TestBase(t *testing.T) {

+ 0
- 2
cli/generate_secret.go Ver fichero

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

Loading…
Cancelar
Guardar