refactor(cli): move the main package to the root. (#2836)

This commit is contained in:
Ludovic Fernandez 2026-01-30 20:33:35 +01:00 committed by GitHub
commit e2e4935b6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 23 additions and 20 deletions

View file

@ -29,4 +29,4 @@ jobs:
run: go test -v -cover ./...
- name: Build
run: go build -v -ldflags "-s -w" -trimpath -o ./dist/lego ./cmd/lego/
run: go build -v -ldflags "-s -w" -trimpath -o ./dist/lego ./

View file

@ -5,7 +5,7 @@ project_name: lego
builds:
- binary: lego
main: ./cmd/lego/
main: .
env:
- CGO_ENABLED=0
flags:

View file

@ -4,7 +4,7 @@ export GO111MODULE=on
export CGO_ENABLED=0
LEGO_IMAGE := goacme/lego
MAIN_DIRECTORY := ./cmd/lego/
MAIN_DIRECTORY := .
BIN_OUTPUT := $(if $(filter $(shell go env GOOS), windows), dist/lego.exe, dist/lego)
@ -69,7 +69,7 @@ generate-dns:
go generate ./...
validate-doc: generate-dns
validate-doc: DOC_DIRECTORIES := ./docs/ ./cmd/
validate-doc: DOC_DIRECTORIES := ./docs/ ./zz_gen_version.go
validate-doc:
@if git diff --exit-code --quiet $(DOC_DIRECTORIES) 2>/dev/null; then \
echo 'All documentation changes are done the right way.'; \

View file

@ -2,6 +2,16 @@ package cmd
import "github.com/urfave/cli/v3"
// CreateRootCommand Creates the root CLI command.
func CreateRootCommand() *cli.Command {
return &cli.Command{
Name: "lego",
Usage: "ACME client written in Go",
EnableShellCompletion: true,
Commands: CreateCommands(),
}
}
// CreateCommands Creates all CLI commands.
func CreateCommands() []*cli.Command {
return []*cli.Command{

View file

@ -80,7 +80,7 @@ Requirements:
To install the latest version from sources, just run:
```bash
go install github.com/go-acme/lego/v5/cmd/lego@latest
go install github.com/go-acme/lego/v5@latest
```
or

View file

@ -5,7 +5,7 @@
title = "lego help"
content = """
NAME:
lego - Let's Encrypt client written in Go
lego - ACME client written in Go
USAGE:
lego [global options] [command [command options]]

View file

@ -255,9 +255,7 @@ func buildLego(ctx context.Context) (string, func(), error) {
return "", func() {}, err
}
mainFolder := filepath.Join(projectRoot, "cmd", "lego")
err = os.Chdir(mainFolder)
err = os.Chdir(projectRoot)
if err != nil {
return "", func() {}, err
}

View file

@ -84,14 +84,14 @@ func generate(ctx context.Context) error {
return nil
}
// createStubApp Construct cli app, very similar to cmd/lego/main.go.
// createStubApp Construct cli app, very similar to main.go.
// Notable differences:
// - do not include version information, because we're likely running against a snapshot
// - skip DNS help and provider list, as initialization takes time, and we don't generate `lego dns --help` here.
func createStubApp() *cli.Command {
return &cli.Command{
Name: "lego",
Usage: "Let's Encrypt client written in Go",
Usage: "ACME client written in Go",
Commands: cmd.CreateCommands(),
}
}

View file

@ -22,7 +22,7 @@ const (
const (
versionTemplate = "templates/version.go.tmpl"
versionTargetFile = "./cmd/lego/zz_gen_version.go"
versionTargetFile = "./zz_gen_version.go"
)
//go:embed templates

View file

@ -22,7 +22,7 @@ const (
modeMajor = "major"
)
const versionSourceFile = "./cmd/lego/zz_gen_version.go"
const versionSourceFile = "./zz_gen_version.go"
const (
commentRelease = "release"

View file

@ -14,13 +14,8 @@ import (
)
func main() {
app := &cli.Command{
Name: "lego",
Usage: "Let's Encrypt client written in Go",
Version: getVersion(),
EnableShellCompletion: true,
Commands: cmd.CreateCommands(),
}
app := cmd.CreateRootCommand()
app.Version = getVersion()
cli.VersionPrinter = func(cmd *cli.Command) {
fmt.Printf("lego version %s %s/%s\n", cmd.Version, runtime.GOOS, runtime.GOARCH)