Skip to content

Commit ed4ea55

Browse files
Aryan Tikaryarvagg
authored andcommitted
feat: generate CLI docs without needing compiled binaries
1 parent e233fd2 commit ed4ea55

40 files changed

+1839
-1405
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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 renamed to cli/lotus/backup.go

Lines changed: 1 addition & 1 deletion
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 renamed to cli/lotus/config.go

Lines changed: 1 addition & 1 deletion
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 renamed to cli/lotus/daemon.go

Lines changed: 1 addition & 1 deletion
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 renamed to cli/lotus/daemon_nodaemon.go

Lines changed: 1 addition & 1 deletion
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 renamed to cli/lotus/debug_advance.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 123 additions & 0 deletions
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 renamed to cli/miner/actor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package miner
22

33
import (
44
"fmt"

0 commit comments

Comments
 (0)