mirror of
https://github.com/go-acme/lego
synced 2026-03-14 22:45:48 +01:00
refactor(cli): move the main package to the root. (#2836)
This commit is contained in:
parent
317a9043ce
commit
e2e4935b6d
12 changed files with 23 additions and 20 deletions
2
.github/workflows/go-cross.yml
vendored
2
.github/workflows/go-cross.yml
vendored
|
|
@ -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 ./
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ project_name: lego
|
|||
builds:
|
||||
- binary: lego
|
||||
|
||||
main: ./cmd/lego/
|
||||
main: .
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
flags:
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -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.'; \
|
||||
|
|
|
|||
10
cmd/cmd.go
10
cmd/cmd.go
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
2
docs/data/zz_cli_help.toml
generated
2
docs/data/zz_cli_help.toml
generated
|
|
@ -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]]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const (
|
|||
modeMajor = "major"
|
||||
)
|
||||
|
||||
const versionSourceFile = "./cmd/lego/zz_gen_version.go"
|
||||
const versionSourceFile = "./zz_gen_version.go"
|
||||
|
||||
const (
|
||||
commentRelease = "release"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
0
cmd/lego/zz_gen_version.go → zz_gen_version.go
generated
0
cmd/lego/zz_gen_version.go → zz_gen_version.go
generated
Loading…
Add table
Add a link
Reference in a new issue