Skip to content

Commit

Permalink
feat: generate CLI docs without needing compiled binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
akaladarshi authored and rvagg committed Jan 6, 2025
1 parent 9dcd3c7 commit 7fe23b0
Show file tree
Hide file tree
Showing 40 changed files with 1,839 additions and 1,405 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
- Add Magik's bootstrap node. ([filecoin-project/lotus#12792](https://github.com/filecoin-project/lotus/pull/12792))
- 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))
- 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))
- 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))

# UNRELEASED v.1.32.0


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

# Node and Miner v1.31.0 / 2024-12-02
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ snap: lotus lotus-miner lotus-worker
snapcraft
# snapcraft upload ./lotus_*.snap

# separate from gen because it needs binaries
docsgen-cli: lotus lotus-miner lotus-worker
$(GOCC) run ./scripts/docsgen-cli
./lotus config default > documentation/en/default-lotus-config.toml
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ var GetStorageMinerAPI = cliutil.GetStorageMinerAPI
var GetWorkerAPI = cliutil.GetWorkerAPI

var CommonCommands = []*cli.Command{
AuthCmd,
LogCmd,
WaitApiCmd,
FetchParamCmd,
WithCategory("developer", AuthCmd),
WithCategory("developer", LogCmd),
WithCategory("developer", WaitApiCmd),
WithCategory("developer", FetchParamCmd),
PprofCmd,
VersionCmd,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/backup.go → cli/lotus/backup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package lotus

import (
"os"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/config.go → cli/lotus/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package lotus

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/daemon.go → cli/lotus/daemon.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build !nodaemon
// +build !nodaemon

package main
package lotus

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build nodaemon
// +build nodaemon

package main
package lotus

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/debug_advance.go → cli/lotus/debug_advance.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build debug
// +build debug

package main
package lotus

import (
"encoding/binary"
Expand Down
123 changes: 123 additions & 0 deletions cli/lotus/lotus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package lotus

import (
"context"
"os"

"github.com/fatih/color"
logging "github.com/ipfs/go-log/v2"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"go.opencensus.io/trace"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/cli/clicommands"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/lib/tracing"
"github.com/filecoin-project/lotus/node/repo"
)

var log = logging.Logger("lotus")

var AdvanceBlockCmd *cli.Command

func App() *cli.App {
api.RunningNodeType = api.NodeFull

lotuslog.SetupLogLevels()

local := []*cli.Command{
DaemonCmd,
backupCmd,
configCmd,
}
if AdvanceBlockCmd != nil {
local = append(local, AdvanceBlockCmd)
}

jaeger := tracing.SetupJaegerTracing("lotus")
defer func() {
if jaeger != nil {
_ = jaeger.ForceFlush(context.Background())
}
}()

for _, cmd := range local {
cmd := cmd
originBefore := cmd.Before
cmd.Before = func(cctx *cli.Context) error {
if jaeger != nil {
_ = jaeger.Shutdown(cctx.Context)
}
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)

if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}

if originBefore != nil {
return originBefore(cctx)
}
return nil
}
}
ctx, span := trace.StartSpan(context.Background(), "/cli")
defer span.End()

interactiveDef := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())

app := &cli.App{
Name: "lotus",
Usage: "Filecoin decentralized storage network client",
Version: string(build.NodeUserVersion()),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "panic-reports",
EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"},
Hidden: true,
Value: "~/.lotus", // should follow --repo default
},
&cli.BoolFlag{
// examined in the Before above
Name: "color",
Usage: "use color in display output",
DefaultText: "depends on output being a TTY",
},
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"LOTUS_PATH"},
Hidden: true,
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
},
&cli.BoolFlag{
Name: "interactive",
Usage: "setting to false will disable interactive functionality of commands",
Value: interactiveDef,
},
&cli.BoolFlag{
Name: "force-send",
Usage: "if true, will ignore pre-send checks",
},
cliutil.FlagVeryVerbose,
},
After: func(c *cli.Context) error {
if r := recover(); r != nil {
// Generate report in LOTUS_PATH and re-raise panic
build.GenerateNodePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
panic(r)
}
return nil
},

Commands: append(local, clicommands.Commands...),
}

app.Setup()
app.Metadata["traceContext"] = ctx
app.Metadata["repoType"] = repo.FullNode

return app
}
2 changes: 1 addition & 1 deletion cmd/lotus-miner/actor.go → cli/miner/actor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/actor_test.go → cli/miner/actor_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"flag"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/backup.go → cli/miner/backup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/config.go → cli/miner/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/info.go → cli/miner/info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-miner/info_all.go → cli/miner/info_all.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"flag"
Expand Down Expand Up @@ -194,7 +194,7 @@ var infoAllCmd = &cli.Command{

if !_test {
fmt.Println("\n#: Goroutines")
if err := lcli.PprofGoroutines.Action(cctx); err != nil {
if err := lcli.PprofGoroutinesCmd.Action(cctx); err != nil {
fmt.Println("ERROR: ", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/init.go → cli/miner/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package miner

import (
"context"
Expand Down
Loading

0 comments on commit 7fe23b0

Please sign in to comment.