Skip to content

Commit

Permalink
feat(cmd): match upcoming node version with API (#3318)
Browse files Browse the repository at this point in the history
Resolves #2549

`docgen` cmd moved to the root celestia cmd folder, so it will be a part of the c-node binary to get the correct Semantic version.
  • Loading branch information
vgonkivs committed May 9, 2024
1 parent 34fa2ef commit 93dfedf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pb-gen:
## openrpc-gen: Generate OpenRPC spec for Celestia-Node's RPC api
openrpc-gen:
@echo "--> Generating OpenRPC spec"
@go run ./cmd/docgen fraud header state share das p2p node blob da
@go run ${LDFLAGS} ./cmd/celestia docgen
.PHONY: openrpc-gen

## lint-imports: Lint only Go imports.
Expand Down
37 changes: 16 additions & 21 deletions cmd/docgen/openrpc.go → cmd/celestia/docgen.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
package main

import (
"context"
"encoding/json"
"os"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/api/docgen"
"github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/nodebuilder"
)

var rootCmd = &cobra.Command{
Use: "docgen [packages]",
Short: "docgen generates the openrpc documentation for Celestia Node packages",
RunE: func(_ *cobra.Command, moduleNames []string) error {
// 1. Open the respective nodebuilder/X/service.go files for AST parsing
var docgenCmd = &cobra.Command{
Use: "docgen",
Short: "docgen generates the openrpc documentation for all Celestia Node packages",
RunE: func(_ *cobra.Command, _ []string) error {
// 1. Collect all node's modules
moduleNames := make([]string, 0, len(client.Modules))
for module := range client.Modules {
moduleNames = append(moduleNames, module)
}

// 2. Open the respective nodebuilder/X/service.go files for AST parsing
nodeComments, permComments := docgen.ParseCommentsFromNodebuilderModules(moduleNames...)

// 2. Create an OpenRPC document from the map of comments + hardcoded metadata
// 3. Create an OpenRPC document from the map of comments + hardcoded metadata
doc := docgen.NewOpenRPCDocument(nodeComments, permComments)

// 3. Register the client wrapper interface on the document
// 4. Register the client wrapper interface on the document
for moduleName, module := range nodebuilder.PackageToAPI {
doc.RegisterReceiverName(moduleName, module)
}

// 4. Call doc.Discover()
// 5. Call doc.Discover()
d, err := doc.Discover()
if err != nil {
return err
}

// 5. Print to Stdout
// 6. Print to Stdout
jsonOut, err := json.MarshalIndent(d, "", " ")
if err != nil {
return err
Expand All @@ -42,14 +48,3 @@ var rootCmd = &cobra.Command{
return err
},
}

func main() {
err := run()
if err != nil {
os.Exit(1)
}
}

func run() error {
return rootCmd.ExecuteContext(context.Background())
}
1 change: 1 addition & 0 deletions cmd/celestia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func init() {
bridgeCmd,
lightCmd,
fullCmd,
docgenCmd,
versionCmd,
)
rootCmd.SetHelpCommand(&cobra.Command{})
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/celestiaorg/celestia-node/libs/authtoken"
)

const APIVersion = "v0.11.0"
var APIVersion = GetBuildInfo().SemanticVersion

type module struct {
tp Type
Expand Down

0 comments on commit 93dfedf

Please sign in to comment.