Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): generate cli docs directly from the struct #12717

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Add F3GetCertificate & F3GetLatestCertificate to the gateway. ([filecoin-project/lotus#12778](https://github.com/filecoin-project/lotus/pull/12778))
- 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))
- 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

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ 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
docsgen-cli:lotus lotus-miner lotus-worker
$(GOCC) run ./scripts/docsgen-cli
./lotus config default > documentation/en/default-lotus-config.toml
./lotus-miner config default > documentation/en/default-lotus-miner-config.toml

.PHONY: docsgen-cli

print-%:
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
Loading