2019-06-17 09:48:05 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-11-21 17:36:05 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2020-08-17 16:04:03 +00:00
|
|
|
"github.com/traefik/paerser/cli"
|
|
|
|
"github.com/traefik/paerser/flag"
|
2019-06-17 09:48:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FlagLoader loads configuration from flags.
|
|
|
|
type FlagLoader struct{}
|
|
|
|
|
|
|
|
// Load loads the command's configuration from flag arguments.
|
2020-08-17 16:04:03 +00:00
|
|
|
func (*FlagLoader) Load(args []string, cmd *cli.Command) (bool, error) {
|
2019-06-24 14:40:06 +00:00
|
|
|
if len(args) == 0 {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2019-06-17 09:48:05 +00:00
|
|
|
if err := flag.Decode(args, cmd.Configuration); err != nil {
|
2020-05-11 10:06:07 +00:00
|
|
|
return false, fmt.Errorf("failed to decode configuration from flags: %w", err)
|
2019-06-17 09:48:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 17:36:05 +00:00
|
|
|
log.Print("Configuration loaded from flags")
|
2019-06-17 09:48:05 +00:00
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|