Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:

# If you change this value, please change it in the following files as well:
# /Dockerfile
GO_VERSION: 1.23.12
GO_VERSION: 1.24.6

jobs:
########################
Expand Down Expand Up @@ -103,6 +103,26 @@ jobs:
- name: lint
run: make lint

########################
# Verify documentation
########################
docs-check:
name: verify that auto-generated documentation is up-to-date
runs-on: ubuntu-latest
steps:
- name: git checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: '~${{ env.GO_VERSION }}'

- name: check
run: make docs-check

########################
# run unit tests
########################
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "2"
run:
go: "1.23"
go: "1.24"

# timeout for analysis
timeout: 4m
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM} golang:1.23.12-alpine as builder
FROM --platform=${BUILDPLATFORM} golang:1.24.6-alpine as builder

# Copy in the local repository to build from.
COPY . /go/src/github.com/lightningnetwork/loop
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ sqlc-check: sqlc
@$(call print, "Verifying sql code generation.")
if test -n "$$(git status --porcelain '*.go')"; then echo "SQL models not properly generated!"; git status --porcelain '*.go'; exit 1; fi

docs: build
@$(call print, "Building man and markdown files in docs/")
./loop-debug man > docs/loop.1
./loop-debug markdown > docs/loop.md

docs-check: docs
@$(call print, "Verifying man and markdown files in docs/")
if test -n "$$(git status --porcelain 'docs/loop.*')"; then echo "Man and markdown files not properly generated!"; git diff; exit 1; fi

fsm:
@$(call print, "Generating state machine docs")
./scripts/fsm-generate.sh;
Expand Down
152 changes: 152 additions & 0 deletions cmd/loop/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package main

import (
"context"
_ "embed"
"fmt"

docs "github.com/urfave/cli-docs/v3"
"github.com/urfave/cli/v3"
)

//go:embed markdown_tabular.md.gotmpl
var markdownTabularDocTemplate string

// We have a copy of this template taken from
// https://github.com/urfave/cli-docs where we remove column
// "Environment variables" if it has no values.
// TODO: remove this when https://github.com/urfave/cli-docs/pull/15
// is merged.
func init() {
docs.MarkdownTabularDocTemplate = markdownTabularDocTemplate
}

var printManCommand = &cli.Command{
Name: "man",
Usage: "prints man file",
Description: "Prints documentation of loop CLI in man format",
Action: printMan,
Hidden: true,
}

func printMan(_ context.Context, cmd *cli.Command) error {
root := filterNestedHelpCommands(cmd.Root())

const userCommandsSection = 1
man, err := docs.ToManWithSection(root, userCommandsSection)
if err != nil {
return fmt.Errorf("failed to produce man: %w", err)
}

fmt.Println(man)

return nil
}

var printMarkdownCommand = &cli.Command{
Name: "markdown",
Usage: "prints markdown file",
Description: "Prints documentation of loop CLI in markdown format",
Action: printMarkdown,
Hidden: true,
}

func printMarkdown(_ context.Context, cmd *cli.Command) error {
root := filterNestedHelpCommands(cmd.Root())

md, err := docs.ToTabularMarkdown(root, "loop")
if err != nil {
return fmt.Errorf("failed to produce man: %w", err)
}

fmt.Println(md)

return nil
}

// filterNestedHelpCommands clones cmd, drops nested help commands, and normalises
// flag defaults so generated documentation avoids absolute paths.
func filterNestedHelpCommands(cmd *cli.Command) *cli.Command {
cloned := cloneCommand(cmd, 0)
overrideDocFlags(cloned)
return cloned
}

// cloneCommand clones the command, filtering out nested "help" subcommands.
func cloneCommand(cmd *cli.Command, depth int) *cli.Command {
if cmd == nil {
return nil
}

cloned := *cmd
if len(cmd.Commands) == 0 {
return &cloned
}

filtered := make([]*cli.Command, 0, len(cmd.Commands))
for _, sub := range cmd.Commands {
if sub == nil {
continue
}
childDepth := depth + 1

// TODO: remove when https://github.com/urfave/cli-docs/pull/16
if childDepth > 0 && sub.Name == "help" {
continue
}

filtered = append(filtered, cloneCommand(sub, childDepth))
}

cloned.Commands = filtered
return &cloned
}

// overrideDocFlags walks the command tree and replaces string flag defaults
// that leak user-specific filesystem paths, keeping generated docs stable.
func overrideDocFlags(cmd *cli.Command) {
if cmd == nil {
return
}

if len(cmd.Flags) > 0 {
clonedFlags := make([]cli.Flag, len(cmd.Flags))
for i, fl := range cmd.Flags {
clonedFlags[i] = cloneFlagWithOverrides(fl)
}
cmd.Flags = clonedFlags
}

for _, sub := range cmd.Commands {
overrideDocFlags(sub)
}
}

// docFlagOverrides maps global flag names to the canonical values we want to
// show in documentation instead of user-specific absolute paths.
var docFlagOverrides = map[string]string{
loopDirFlag.Name: "~/.loop",
tlsCertFlag.Name: "~/.loop/mainnet/tls.cert",
macaroonPathFlag.Name: "~/.loop/mainnet/loop.macaroon",
}

// cloneFlagWithOverrides returns a copy of flag with overridden default values
// when the flag participates in docFlagOverrides. Non-string flags are reused
// unchanged to minimise allocations.
func cloneFlagWithOverrides(flag cli.Flag) cli.Flag {
sf, ok := flag.(*cli.StringFlag)
if !ok {
return flag
}

value, ok := docFlagOverrides[sf.Name]
if !ok {
return flag
}

cloned := *sf
cloned.Value = value
cloned.DefaultText = value

return &cloned
}
1 change: 1 addition & 0 deletions cmd/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ var (
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
instantOutCommand, listInstantOutsCommand,
printManCommand, printMarkdownCommand,
}
)

Expand Down
80 changes: 80 additions & 0 deletions cmd/loop/markdown_tabular.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{ define "flags" }}
{{- $hasEnvVars := false -}}
{{- range . -}}
{{- if and (not $hasEnvVars) .EnvVars -}}
{{- $hasEnvVars = true -}}
{{- end -}}
{{- end }}
| Name | Description | Type | Default value {{ if $hasEnvVars }}| Environment variables {{ end }}|
|------|-------------|------|:-------------:{{ if $hasEnvVars }}|:---------------------:{{ end }}|
{{ range $flag := . -}}
{{- /**/ -}} | `{{ $flag.Name }}{{ if $flag.TakesValue }}="…"{{ end }}` {{ if $flag.Aliases }}(`{{ join $flag.Aliases "`, `" }}`) {{ end }}
{{- /**/ -}} | {{ $flag.Usage }}
{{- /**/ -}} | {{ $flag.Type }}
{{- /**/ -}} | {{ if $flag.Default }}`{{ $flag.Default }}`{{ end }}
{{- if $hasEnvVars -}}
{{- /**/ -}} | {{ if $flag.EnvVars }}`{{ join $flag.EnvVars "`, `" }}`{{ else }}*none*{{ end }}
{{- end -}}
{{- /**/ -}} |
{{ end }}
{{ end }}

{{ define "command" }}
### `{{ .Name }}` {{ if gt .Level 0 }}sub{{ end }}command{{ if .Aliases }} (aliases: `{{ join .Aliases "`, `" }}`){{ end }}
{{ if .Usage }}
{{ .Usage }}.
{{ end }}
{{ if .UsageText }}
{{ range $line := .UsageText -}}
> {{ $line }}
{{ end -}}
{{ end }}
{{ if .Description }}
{{ .Description }}.
{{ end }}
Usage:

```bash
$ {{ .AppPath }} [GLOBAL FLAGS] {{ .Name }}{{ if .Flags }} [COMMAND FLAGS]{{ end }} {{ if .ArgsUsage }}{{ .ArgsUsage }}{{ else }}[ARGUMENTS...]{{ end }}
```

{{ if .Flags -}}
The following flags are supported:
{{ template "flags" .Flags }}
{{ end -}}

{{ if .SubCommands -}}
{{ range $subCmd := .SubCommands -}}
{{ template "command" $subCmd }}
{{ end -}}
{{ end -}}
{{ end }}

## CLI interface{{ if .Name }} - {{ .Name }}{{ end }}

{{ if .Description }}{{ .Description }}.
{{ end }}
{{ if .Usage }}{{ .Usage }}.
{{ end }}
{{ if .UsageText }}
{{ range $line := .UsageText -}}
> {{ $line }}
{{ end -}}
{{ end }}
Usage:

```bash
$ {{ .AppPath }}{{ if .GlobalFlags }} [GLOBAL FLAGS]{{ end }} [COMMAND] [COMMAND FLAGS] {{ if .ArgsUsage }}{{ .ArgsUsage }}{{ else }}[ARGUMENTS...]{{ end }}
```

{{ if .GlobalFlags }}
Global flags:

{{ template "flags" .GlobalFlags }}

{{ end -}}
{{ if .Commands -}}
{{ range $cmd := .Commands -}}
{{ template "command" $cmd }}
{{ end }}
{{- end }}
16 changes: 8 additions & 8 deletions docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ for a release using the following commands:
```bash
$ go version
go version go1.25.0 linux/amd64
$ go install golang.org/dl/go1.23.12@latest
$ go1.23.12 download
Unpacking /home/user/sdk/go1.23.12/go1.23.12.linux-amd64.tar.gz ...
Success. You may now run 'go1.23.12'
$ go1.23.12 version
go version go1.23.12 linux/amd64

$ GO_CMD=/home/user/go/bin/go1.23.12 ./release.sh v0.31.5
$ go install golang.org/dl/go1.24.6@latest
$ go1.24.6 download
Unpacking /home/user/sdk/go1.24.6/go1.24.6.linux-amd64.tar.gz ...
Success. You may now run 'go1.24.6'
$ go1.24.6 version
go version go1.24.6 linux/amd64

$ GO_CMD=/home/user/go/bin/go1.24.6 ./release.sh v0.31.3
```

On MacOS, you will need to install GNU tar and GNU gzip, which can be done with
Expand Down
17 changes: 10 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/lib/pq v1.10.9
github.com/lightninglabs/aperture v0.3.13-beta
github.com/lightninglabs/lndclient v0.19.0-12
github.com/lightninglabs/lndclient v0.20.0-1
github.com/lightninglabs/loop/looprpc v1.0.7
github.com/lightninglabs/loop/swapserverrpc v1.0.14
github.com/lightninglabs/taproot-assets v0.6.1
github.com/lightninglabs/taproot-assets/taprpc v1.0.8-0.20250716163904-2ef55ba74036
github.com/lightningnetwork/lnd v0.19.3-beta
github.com/lightninglabs/taproot-assets v0.7.0-rc1.0.20251014172227-e6ae082c0b4b
github.com/lightninglabs/taproot-assets/taprpc v1.0.10-0.20251014172227-e6ae082c0b4b
github.com/lightningnetwork/lnd v0.20.0-beta.rc1
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/queue v1.1.1
Expand All @@ -34,6 +34,7 @@ require (
github.com/lightningnetwork/lnd/tor v1.1.6
github.com/ory/dockertest/v3 v3.10.0
github.com/stretchr/testify v1.10.0
github.com/urfave/cli-docs/v3 v3.1.0
github.com/urfave/cli/v3 v3.4.1
go.etcd.io/bbolt v1.4.3
golang.org/x/sync v0.13.0
Expand Down Expand Up @@ -72,6 +73,7 @@ require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/lru v1.1.2 // indirect
github.com/docker/cli v28.1.1+incompatible // indirect
Expand Down Expand Up @@ -121,11 +123,11 @@ require (
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.3 // indirect
github.com/lightninglabs/neutrino v0.16.1 // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 // indirect
github.com/lightningnetwork/lnd/fn/v2 v2.0.8 // indirect
github.com/lightningnetwork/lnd/healthcheck v1.2.6 // indirect
github.com/lightningnetwork/lnd/kvdb v1.4.16 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.10 // indirect
github.com/lightningnetwork/lnd/sqldb v1.0.11 // indirect
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
Expand All @@ -149,6 +151,7 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/fastuuid v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/pflag v1.0.6 // indirect
Expand Down Expand Up @@ -216,4 +219,4 @@ replace github.com/lightninglabs/loop/swapserverrpc => ./swapserverrpc

replace github.com/lightninglabs/loop/looprpc => ./looprpc

go 1.23.12
go 1.24.6
Loading
Loading