Skip to content

Commit 7fe23b0

Browse files
akaladarshirvagg
authored andcommitted
feat: generate CLI docs without needing compiled binaries
1 parent 9dcd3c7 commit 7fe23b0

40 files changed

+1839
-1405
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
- Add Magik's bootstrap node. ([filecoin-project/lotus#12792](https://github.com/filecoin-project/lotus/pull/12792))
1717
- Lotus now reports the network name as a tag in most metrics. Some untagged metrics will be completed in a follow-up at a later date. ([filecoin-project/lotus#12733](https://github.com/filecoin-project/lotus/pull/12733))
1818
- Refactored Ethereum API implementation into smaller, more manageable modules in a new `github.com/filecoin-project/lotus/node/impl/eth` package. ([filecoin-project/lotus#12796](https://github.com/filecoin-project/lotus/pull/12796))
19+
- Generate the cli docs directly from the code instead compiling and executing binaries' `help` output. ([filecoin-project/lotus#12717](https://github.com/filecoin-project/lotus/pull/12717))
1920

2021
# UNRELEASED v.1.32.0
2122

22-
2323
See https://github.com/filecoin-project/lotus/blob/release/v1.32.0/CHANGELOG.md
2424

2525
# Node and Miner v1.31.0 / 2024-12-02

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ snap: lotus lotus-miner lotus-worker
348348
snapcraft
349349
# snapcraft upload ./lotus_*.snap
350350

351-
# separate from gen because it needs binaries
352351
docsgen-cli: lotus lotus-miner lotus-worker
353352
$(GOCC) run ./scripts/docsgen-cli
354353
./lotus config default > documentation/en/default-lotus-config.toml

cli/cmd.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
5757
var GetWorkerAPI = cliutil.GetWorkerAPI
5858

5959
var CommonCommands = []*cli.Command{
60-
AuthCmd,
61-
LogCmd,
62-
WaitApiCmd,
63-
FetchParamCmd,
60+
WithCategory("developer", AuthCmd),
61+
WithCategory("developer", LogCmd),
62+
WithCategory("developer", WaitApiCmd),
63+
WithCategory("developer", FetchParamCmd),
6464
PprofCmd,
6565
VersionCmd,
6666
}

cmd/lotus/backup.go cli/lotus/backup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package lotus
22

33
import (
44
"os"

cmd/lotus/config.go cli/lotus/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package lotus
22

33
import (
44
"fmt"

cmd/lotus/daemon.go cli/lotus/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build !nodaemon
22
// +build !nodaemon
33

4-
package main
4+
package lotus
55

66
import (
77
"bufio"

cmd/lotus/daemon_nodaemon.go cli/lotus/daemon_nodaemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build nodaemon
22
// +build nodaemon
33

4-
package main
4+
package lotus
55

66
import (
77
"errors"

cmd/lotus/debug_advance.go cli/lotus/debug_advance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//go:build debug
22
// +build debug
33

4-
package main
4+
package lotus
55

66
import (
77
"encoding/binary"

cli/lotus/lotus.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package lotus
2+
3+
import (
4+
"context"
5+
"os"
6+
7+
"github.com/fatih/color"
8+
logging "github.com/ipfs/go-log/v2"
9+
"github.com/mattn/go-isatty"
10+
"github.com/urfave/cli/v2"
11+
"go.opencensus.io/trace"
12+
13+
"github.com/filecoin-project/lotus/api"
14+
"github.com/filecoin-project/lotus/build"
15+
"github.com/filecoin-project/lotus/cli/clicommands"
16+
cliutil "github.com/filecoin-project/lotus/cli/util"
17+
"github.com/filecoin-project/lotus/lib/lotuslog"
18+
"github.com/filecoin-project/lotus/lib/tracing"
19+
"github.com/filecoin-project/lotus/node/repo"
20+
)
21+
22+
var log = logging.Logger("lotus")
23+
24+
var AdvanceBlockCmd *cli.Command
25+
26+
func App() *cli.App {
27+
api.RunningNodeType = api.NodeFull
28+
29+
lotuslog.SetupLogLevels()
30+
31+
local := []*cli.Command{
32+
DaemonCmd,
33+
backupCmd,
34+
configCmd,
35+
}
36+
if AdvanceBlockCmd != nil {
37+
local = append(local, AdvanceBlockCmd)
38+
}
39+
40+
jaeger := tracing.SetupJaegerTracing("lotus")
41+
defer func() {
42+
if jaeger != nil {
43+
_ = jaeger.ForceFlush(context.Background())
44+
}
45+
}()
46+
47+
for _, cmd := range local {
48+
cmd := cmd
49+
originBefore := cmd.Before
50+
cmd.Before = func(cctx *cli.Context) error {
51+
if jaeger != nil {
52+
_ = jaeger.Shutdown(cctx.Context)
53+
}
54+
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)
55+
56+
if cctx.IsSet("color") {
57+
color.NoColor = !cctx.Bool("color")
58+
}
59+
60+
if originBefore != nil {
61+
return originBefore(cctx)
62+
}
63+
return nil
64+
}
65+
}
66+
ctx, span := trace.StartSpan(context.Background(), "/cli")
67+
defer span.End()
68+
69+
interactiveDef := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
70+
71+
app := &cli.App{
72+
Name: "lotus",
73+
Usage: "Filecoin decentralized storage network client",
74+
Version: string(build.NodeUserVersion()),
75+
EnableBashCompletion: true,
76+
Flags: []cli.Flag{
77+
&cli.StringFlag{
78+
Name: "panic-reports",
79+
EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"},
80+
Hidden: true,
81+
Value: "~/.lotus", // should follow --repo default
82+
},
83+
&cli.BoolFlag{
84+
// examined in the Before above
85+
Name: "color",
86+
Usage: "use color in display output",
87+
DefaultText: "depends on output being a TTY",
88+
},
89+
&cli.StringFlag{
90+
Name: "repo",
91+
EnvVars: []string{"LOTUS_PATH"},
92+
Hidden: true,
93+
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
94+
},
95+
&cli.BoolFlag{
96+
Name: "interactive",
97+
Usage: "setting to false will disable interactive functionality of commands",
98+
Value: interactiveDef,
99+
},
100+
&cli.BoolFlag{
101+
Name: "force-send",
102+
Usage: "if true, will ignore pre-send checks",
103+
},
104+
cliutil.FlagVeryVerbose,
105+
},
106+
After: func(c *cli.Context) error {
107+
if r := recover(); r != nil {
108+
// Generate report in LOTUS_PATH and re-raise panic
109+
build.GenerateNodePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
110+
panic(r)
111+
}
112+
return nil
113+
},
114+
115+
Commands: append(local, clicommands.Commands...),
116+
}
117+
118+
app.Setup()
119+
app.Metadata["traceContext"] = ctx
120+
app.Metadata["repoType"] = repo.FullNode
121+
122+
return app
123+
}

cmd/lotus-miner/actor.go cli/miner/actor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"fmt"

cmd/lotus-miner/actor_test.go cli/miner/actor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"bytes"

cmd/lotus-miner/allinfo_test.go cli/miner/allinfo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"flag"

cmd/lotus-miner/backup.go cli/miner/backup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"github.com/urfave/cli/v2"

cmd/lotus-miner/config.go cli/miner/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"fmt"

cmd/lotus-miner/info.go cli/miner/info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"context"

cmd/lotus-miner/info_all.go cli/miner/info_all.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"flag"
@@ -194,7 +194,7 @@ var infoAllCmd = &cli.Command{
194194

195195
if !_test {
196196
fmt.Println("\n#: Goroutines")
197-
if err := lcli.PprofGoroutines.Action(cctx); err != nil {
197+
if err := lcli.PprofGoroutinesCmd.Action(cctx); err != nil {
198198
fmt.Println("ERROR: ", err)
199199
}
200200
}

cmd/lotus-miner/init.go cli/miner/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"bytes"

cmd/lotus-miner/init_restore.go cli/miner/init_restore.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"context"

0 commit comments

Comments
 (0)