diff --git a/cmd/certs.go b/cmd/certs.go index 6603e55..434eaf0 100644 --- a/cmd/certs.go +++ b/cmd/certs.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "os" "github.com/urfave/cli/v2" @@ -10,35 +9,38 @@ import ( ) var Certs = &cli.Command{ - Name: "certs", - Usage: "manage certs manually", - Action: certs, + Name: "certs", + Usage: "manage certs manually", + Subcommands: []*cli.Command{ + &cli.Command{ + Name: "remove", + Usage: "remove a certificate from the database", + Action: removeCert, + }, + }, } -func certs(ctx *cli.Context) error { - if ctx.Args().Len() >= 1 && ctx.Args().First() == "--remove-certificate" { - if ctx.Args().Len() == 1 { - println("--remove-certificate requires at least one domain as an argument") - os.Exit(1) - } +func removeCert(ctx *cli.Context) error { + if ctx.Args().Len() < 1 { + return fmt.Errorf("'certs remove' requires at least one domain as an argument") + } - domains := ctx.Args().Slice()[2:] + domains := ctx.Args().Slice() - // TODO: make "key-database.pogreb" set via flag - keyDatabase, err := database.New("key-database.pogreb") - if err != nil { - return fmt.Errorf("could not create database: %v", err) - } + // TODO: make "key-database.pogreb" set via flag + keyDatabase, err := database.New("key-database.pogreb") + if err != nil { + return fmt.Errorf("could not create database: %v", err) + } - for _, domain := range domains { - if err := keyDatabase.Delete([]byte(domain)); err != nil { - panic(err) - } + for _, domain := range domains { + fmt.Printf("Removing domain %s from the database...\n", domain) + if err := keyDatabase.Delete([]byte(domain)); err != nil { + return err } - if err := keyDatabase.Close(); err != nil { - panic(err) - } - os.Exit(0) + } + if err := keyDatabase.Close(); err != nil { + return err } return nil } diff --git a/cmd/flags.go b/cmd/flags.go index e1838c2..78040be 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -10,7 +10,7 @@ var ServeFlags = []cli.Flag{ // TODO: Usage EnvVars: []string{"DEBUG"}, }, - + // MainDomainSuffix specifies the main domain (starting with a dot) for which subdomains shall be served as static // pages, or used for comparison in CNAME lookups. Static pages can be accessed through // https://{owner}.{MainDomain}[/{repo}], with repo defaulting to "pages".