-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate CLI docs without needing compiled binaries
- Loading branch information
1 parent
9dcd3c7
commit 7fe23b0
Showing
40 changed files
with
1,839 additions
and
1,405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package lotus | ||
|
||
import ( | ||
"os" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package lotus | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"flag" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package miner | ||
|
||
import ( | ||
"context" | ||
|
Oops, something went wrong.