mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
refactor: isolate domains flags creation
This commit is contained in:
parent
85715a1bc3
commit
d2d302c801
1 changed files with 31 additions and 28 deletions
59
cmd/flags.go
59
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{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue