From d2d302c8017a7602e0bde2c55b08d64c718cb3e0 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 24 Jan 2026 03:49:15 +0100 Subject: [PATCH] refactor: isolate domains flags creation --- cmd/flags.go | 59 +++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/cmd/flags.go b/cmd/flags.go index 03edd25db..1fa62c533 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -268,27 +268,6 @@ func CreateOutputFlags() []cli.Flag { } } -func CreatePathFlag(forceCreation bool) cli.Flag { - return &cli.StringFlag{ - Name: flgPath, - Sources: cli.NewValueSourceChain(cli.EnvVar(envPath), &defaultPathValueSource{}), - Usage: "Directory to use for storing the data.", - Validator: func(s string) error { - if !forceCreation { - return nil - } - - err := storage.CreateNonExistingFolder(s) - if err != nil { - return fmt.Errorf("could not check/create the path %q: %w", s, err) - } - - return nil - }, - Required: true, - } -} - func CreateAccountFlags() []cli.Flag { return []cli.Flag{ &cli.BoolFlag{ @@ -367,14 +346,9 @@ func CreateObtainFlags() []cli.Flag { } func CreateFlags() []cli.Flag { - flags := []cli.Flag{ - &cli.StringSliceFlag{ - Name: flgDomains, - Aliases: []string{"d"}, - Usage: "Add a domain to the process. Can be specified multiple times.", - }, - } + var flags []cli.Flag + flags = append(flags, CreateDomainFlag()) flags = append(flags, CreateAccountFlags()...) flags = append(flags, CreateACMEClientFlags()...) flags = append(flags, CreateOutputFlags()...) @@ -385,6 +359,35 @@ func CreateFlags() []cli.Flag { return flags } +func CreateDomainFlag() cli.Flag { + return &cli.StringSliceFlag{ + Name: flgDomains, + Aliases: []string{"d"}, + Usage: "Add a domain to the process. Can be specified multiple times or use comma as a separator.", + } +} + +func CreatePathFlag(forceCreation bool) cli.Flag { + return &cli.StringFlag{ + Name: flgPath, + Sources: cli.NewValueSourceChain(cli.EnvVar(envPath), &defaultPathValueSource{}), + Usage: "Directory to use for storing the data.", + Validator: func(s string) error { + if !forceCreation { + return nil + } + + err := storage.CreateNonExistingFolder(s) + if err != nil { + return fmt.Errorf("could not check/create the path %q: %w", s, err) + } + + return nil + }, + Required: true, + } +} + // defaultPathValueSource gets the default path based on the current working directory. // The field value is only here because clihelp/generator. type defaultPathValueSource struct{}