Maint: cli package interface rework
- return concrete struct type - split interface is sub-interfaces
This commit is contained in:
@@ -2,6 +2,6 @@ package cli
|
||||
|
||||
import "context"
|
||||
|
||||
func (c *cli) CI(context context.Context) error {
|
||||
func (c *CLI) CI(context context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
// Package cli defines an interface CLI to run command line operations.
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
var _ CLIer = (*CLI)(nil)
|
||||
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
type CLI interface {
|
||||
ClientKey(args []string) error
|
||||
HealthCheck(ctx context.Context, env params.Env, logger logging.Logger) error
|
||||
OpenvpnConfig(logger logging.Logger) error
|
||||
Update(ctx context.Context, args []string, logger logging.Logger) error
|
||||
type CLIer interface {
|
||||
ClientKeyFormatter
|
||||
HealthChecker
|
||||
OpenvpnConfigMaker
|
||||
Updater
|
||||
}
|
||||
|
||||
type cli struct {
|
||||
type CLI struct {
|
||||
repoServersPath string
|
||||
}
|
||||
|
||||
func New() CLI {
|
||||
return &cli{
|
||||
func New() *CLI {
|
||||
return &CLI{
|
||||
repoServersPath: "./internal/constants/servers.json",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,11 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func (c *cli) ClientKey(args []string) error {
|
||||
type ClientKeyFormatter interface {
|
||||
ClientKey(args []string) error
|
||||
}
|
||||
|
||||
func (c *CLI) ClientKey(args []string) error {
|
||||
flagSet := flag.NewFlagSet("clientkey", flag.ExitOnError)
|
||||
filepath := flagSet.String("path", constants.ClientKey, "file path to the client.key file")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
|
||||
@@ -12,7 +12,11 @@ import (
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
func (c *cli) HealthCheck(ctx context.Context, env params.Env,
|
||||
type HealthChecker interface {
|
||||
HealthCheck(ctx context.Context, env params.Env, logger logging.Logger) error
|
||||
}
|
||||
|
||||
func (c *CLI) HealthCheck(ctx context.Context, env params.Env,
|
||||
logger logging.Logger) error {
|
||||
// Extract the health server port from the configuration.
|
||||
config := configuration.Health{}
|
||||
|
||||
@@ -13,7 +13,11 @@ import (
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
func (c *cli) OpenvpnConfig(logger logging.Logger) error {
|
||||
type OpenvpnConfigMaker interface {
|
||||
OpenvpnConfig(logger logging.Logger) error
|
||||
}
|
||||
|
||||
func (c *CLI) OpenvpnConfig(logger logging.Logger) error {
|
||||
var allSettings configuration.Settings
|
||||
err := allSettings.Read(params.NewEnv(), logger)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,11 @@ var (
|
||||
ErrWriteToFile = errors.New("cannot write updated information to file")
|
||||
)
|
||||
|
||||
func (c *cli) Update(ctx context.Context, args []string, logger logging.Logger) error {
|
||||
type Updater interface {
|
||||
Update(ctx context.Context, args []string, logger logging.Logger) error
|
||||
}
|
||||
|
||||
func (c *CLI) Update(ctx context.Context, args []string, logger logging.Logger) error {
|
||||
options := configuration.Updater{CLI: true}
|
||||
var endUserMode, maintainerMode, updateAll bool
|
||||
flagSet := flag.NewFlagSet("update", flag.ExitOnError)
|
||||
|
||||
Reference in New Issue
Block a user