Skip to content

Commit 5e566ba

Browse files
committed
feat: generate default configs for docs without compiled binaries
1 parent 942094c commit 5e566ba

8 files changed

+79
-30
lines changed

.github/workflows/check.yml

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ jobs:
3535
- run: git diff --exit-code
3636
- run: make docsgen-cli
3737
- run: git diff --exit-code
38-
- run: make docsgen-config
39-
- run: git diff --exit-code
4038
check-lint:
4139
name: Check (lint-all)
4240
runs-on: ubuntu-latest

Makefile

+1-7
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fiximports:
339339

340340
gen: actors-code-gen type-gen cfgdoc-gen docsgen api-gen
341341
$(GOCC) run ./scripts/fiximports
342-
@echo ">>> IF YOU'VE MODIFIED THE CLI OR CONFIG, REMEMBER TO ALSO RUN 'make docsgen-cli' and/or 'make docsgen-config'"
342+
@echo ">>> IF YOU'VE MODIFIED THE CLI OR CONFIG, REMEMBER TO ALSO RUN 'make docsgen-cli'"
343343
.PHONY: gen
344344

345345
jen: gen
@@ -352,12 +352,6 @@ docsgen-cli:
352352
$(GOCC) run ./scripts/docsgen-cli
353353
.PHONY: docsgen-cli
354354

355-
# Compiled lotus and lotus-miner are required to generate the default config files
356-
docsgen-config: lotus lotus-miner
357-
./lotus config default > documentation/en/default-lotus-config.toml
358-
./lotus-miner config default > documentation/en/default-lotus-miner-config.toml
359-
.PHONY: docsgen-config
360-
361355
print-%:
362356
@echo $*=$($*)
363357

documentation/en/cli-lotus-miner.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1397,10 +1397,10 @@ OPTIONS:
13971397

13981398
```
13991399
NAME:
1400-
lotus auth create-token - Create token
1400+
lotus-miner auth create-token - Create token
14011401
14021402
USAGE:
1403-
lotus auth create-token [command options] [arguments...]
1403+
lotus-miner auth create-token [command options] [arguments...]
14041404
14051405
OPTIONS:
14061406
--perm value permission to assign to the token, one of: read, write, sign, admin
@@ -1411,10 +1411,10 @@ OPTIONS:
14111411

14121412
```
14131413
NAME:
1414-
lotus auth api-info - Get token with API info required to connect to this node
1414+
lotus-miner auth api-info - Get token with API info required to connect to this node
14151415
14161416
USAGE:
1417-
lotus auth api-info [command options] [arguments...]
1417+
lotus-miner auth api-info [command options] [arguments...]
14181418
14191419
OPTIONS:
14201420
--perm value permission to assign to the token, one of: read, write, sign, admin
@@ -1444,10 +1444,10 @@ OPTIONS:
14441444

14451445
```
14461446
NAME:
1447-
lotus log list - List log systems
1447+
lotus-miner log list - List log systems
14481448
14491449
USAGE:
1450-
lotus log list [command options] [arguments...]
1450+
lotus-miner log list [command options] [arguments...]
14511451
14521452
OPTIONS:
14531453
--help, -h show help
@@ -1457,10 +1457,10 @@ OPTIONS:
14571457

14581458
```
14591459
NAME:
1460-
lotus log set-level - Set log level
1460+
lotus-miner log set-level - Set log level
14611461
14621462
USAGE:
1463-
lotus log set-level [command options] [level]
1463+
lotus-miner log set-level [command options] [level]
14641464
14651465
DESCRIPTION:
14661466
Set the log level for logging systems:
@@ -1491,10 +1491,10 @@ OPTIONS:
14911491

14921492
```
14931493
NAME:
1494-
lotus log alerts - Get alert states
1494+
lotus-miner log alerts - Get alert states
14951495
14961496
USAGE:
1497-
lotus log alerts [command options] [arguments...]
1497+
lotus-miner log alerts [command options] [arguments...]
14981498
14991499
OPTIONS:
15001500
--all get all (active and inactive) alerts (default: false)

documentation/en/default-lotus-config.toml

-1
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,3 @@
377377
# env var: LOTUS_FAULTREPORTER_CONSENSUSFAULTREPORTERADDRESS
378378
#ConsensusFaultReporterAddress = ""
379379

380-

documentation/en/default-lotus-miner-config.toml

-1
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,3 @@
650650
# env var: LOTUS_HARMONYDB_PORT
651651
#Port = "5433"
652652

653-

documentation/misc/Building_a_network_skeleton.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Note: one only needs to update `filecion-ffi`'s dependency on `go-state-types` w
248248
249249
11. Run `make gen`.
250250
251-
12. Run `make docsgen-cli docsgen-config`.
251+
12. Run `make docsgen-cli`.
252252
253253
And you're done! These are all the steps necessary to create a network upgrade skeleton that you will be able to run in a local devnet, and creates a basis where you can start testing new FIPs. When running a local developer network from this Lotus branch, bringing in all it dependencies, you should be able to:
254254

documentation/misc/RELEASE_ISSUE_TEMPLATE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<!--{{ if contains "Miner" .Type}}-->
7979
- Ensure to update `MinerBuildVersion`
8080
<!--{{ end}}-->
81-
- [ ] Run `make gen && make docsgen-cli docsgen-config` before committing changes.
81+
- [ ] Run `make gen && make docsgen-cli` before committing changes.
8282
- [ ] Update the CHANGELOG
8383
- [ ] Change the `UNRELEASED` section header to `UNRELEASED v{{.Tag}}`
8484
- [ ] Set the `UNRELEASED v{{.Tag}}` section's content to be "_See https://github.com/filecoin-project/lotus/blob/release/v{{.Tag}}/CHANGELOG.md_"
@@ -118,7 +118,7 @@
118118
<!-- {{if contains "Miner" $.Type}}-->
119119
- Ensure to update `MinerBuildVersion`
120120
<!-- {{end}}-->
121-
- [ ] Run `make gen && make docsgen-cli docsgen-config` to generate documentation
121+
- [ ] Run `make gen && make docsgen-cli` to generate documentation
122122
- [ ] Create a draft PR with title `build: release Lotus {{$.Type}} v{{$.Tag}}{{$tagSuffix}}`
123123
- Link to PR:
124124
- Opening a PR will trigger a CI run that will build assets, create a draft GitHub release, and attach the assets.

scripts/docsgen-cli/main.go

+65-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67

78
"github.com/urfave/cli/v2"
89

910
"github.com/filecoin-project/lotus/cli/lotus"
1011
"github.com/filecoin-project/lotus/cli/miner"
1112
"github.com/filecoin-project/lotus/cli/worker"
13+
"github.com/filecoin-project/lotus/node/config"
1214
)
1315

1416
const (
@@ -45,6 +47,22 @@ func main() {
4547
os.Exit(1)
4648
}
4749

50+
cliApps := loadCLIApps()
51+
52+
fmt.Println("Generating CLI documentation...")
53+
failed := generateCLIDocumentation(cliApps)
54+
55+
fmt.Println("Generating default config files...")
56+
failed = generateDefaultConfigs() || failed
57+
58+
if failed {
59+
fmt.Println("Documentation generation failed.")
60+
os.Exit(1)
61+
}
62+
fmt.Println("Documentation generation complete.")
63+
}
64+
65+
func loadCLIApps() map[string]*cli.App {
4866
// Some help output is generated based on whether the output is a terminal or not. To make stable
4967
// output text, we set Stdout to not be a terminal while we load the CLI apps and reset it
5068
// before generating the documentation.
@@ -58,23 +76,64 @@ func main() {
5876
"lotus-miner": miner.App(),
5977
}
6078

61-
w.Close()
79+
_ = w.Close()
6280
os.Stdout = stdout
6381

64-
fmt.Println("Generating CLI documentation...")
82+
return cliApps
83+
}
6584

85+
func generateCLIDocumentation(cliApps map[string]*cli.App) bool {
86+
var failed bool
6687
for name, app := range cliApps {
67-
for _, cmd := range app.Commands {
68-
cmd.HelpName = fmt.Sprintf("%s %s", app.HelpName, cmd.Name)
69-
}
88+
resetCommandHelpName(app)
7089

7190
generator := NewDocGenerator(outputDir, app)
7291
if err := generator.Generate(name); err != nil {
7392
fmt.Printf(" ❌ %s: %v\n", name, err)
93+
failed = true
7494
continue
7595
}
7696
fmt.Printf(" ✅ %s\n", name)
7797
}
98+
return failed
99+
}
78100

79-
fmt.Println("Documentation generation complete.")
101+
// resetCommandHelpName resets the HelpName of all commands to include the parent command names.
102+
// This is needed for the case where Commands are shared between apps.
103+
func resetCommandHelpName(app *cli.App) {
104+
var fix func(cmds []*cli.Command, helpName string)
105+
fix = func(cmds []*cli.Command, helpName string) {
106+
for _, cmd := range cmds {
107+
cmd.HelpName = fmt.Sprintf("%s %s", helpName, cmd.Name)
108+
fix(cmd.Subcommands, cmd.HelpName)
109+
}
110+
}
111+
fix(app.Commands, app.HelpName)
112+
}
113+
114+
func generateDefaultConfigs() bool {
115+
var failed bool
116+
if err := generateDefaultConfig(config.DefaultFullNode(), "default-lotus-config.toml"); err != nil {
117+
fmt.Printf(" ❌ %s: %v\n", "lotus", err)
118+
failed = true
119+
} else {
120+
fmt.Printf(" ✅ %s\n", "lotus")
121+
}
122+
123+
if err := generateDefaultConfig(config.DefaultStorageMiner(), "default-lotus-miner-config.toml"); err != nil {
124+
fmt.Printf(" ❌ %s: %v\n", "lotus-miner", err)
125+
failed = true
126+
} else {
127+
fmt.Printf(" ✅ %s\n", "lotus-miner")
128+
}
129+
return failed
130+
}
131+
132+
func generateDefaultConfig(c interface{}, file string) error {
133+
cb, err := config.ConfigUpdate(c, nil, config.Commented(true), config.DefaultKeepUncommented())
134+
if err != nil {
135+
return err
136+
}
137+
output := filepath.Join(outputDir, file)
138+
return os.WriteFile(output, cb, 0644)
80139
}

0 commit comments

Comments
 (0)