forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): pass Start options; add WithFlagSet option (celestiaorg#2950)
<!-- Thank you for submitting a pull request! Please make sure you have reviewed our contributors guide before submitting your first PR. Please ensure you've addressed or included references to any related issues. Tips: - Use keywords like "closes" or "fixes" followed by an issue number to automatically close related issues when the PR is merged (e.g., "closes celestiaorg#123" or "fixes celestiaorg#123"). - Describe the changes made in the PR. - Ensure the PR has one of the required tags (kind:fix, kind:misc, kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci, kind:chore, kind:testing) --> Fixes celestiaorg#2936 This PR updates the `Start` command to accept a variadic number of `funcs` which can be used to customise the command. This allows the caller to hook into and modify the command, for example to add a `PreRun` hook, as required for `celestia-da`. With this PR in place, the `celestia-da` requirement, which needs to add some required flags and add a `PreRun` hook can be satisfied as: ```go bridgeCmd := bridge.NewCommand(WithPreRun()) lightCmd := light.NewCommand(WithPreRun()) fullCmd := full.NewCommand(WithPreRun()) ``` Ideally this can be applied for other commands `Init`, `Auth` as well, but it's not required for the current requirement.
- Loading branch information
Showing
7 changed files
with
121 additions
and
153 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-node/nodebuilder/core" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/gateway" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/header" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/node" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/p2p" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/rpc" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/state" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func NewBridge(options ...func(*cobra.Command, []*pflag.FlagSet)) *cobra.Command { | ||
flags := []*pflag.FlagSet{ | ||
NodeFlags(), | ||
p2p.Flags(), | ||
MiscFlags(), | ||
core.Flags(), | ||
rpc.Flags(), | ||
gateway.Flags(), | ||
state.Flags(), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "bridge [subcommand]", | ||
Args: cobra.NoArgs, | ||
Short: "Manage your Bridge node", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
return PersistentPreRunEnv(cmd, node.Bridge, args) | ||
}, | ||
} | ||
for _, option := range options { | ||
option(cmd, flags) | ||
} | ||
return cmd | ||
} | ||
|
||
func NewLight(options ...func(*cobra.Command, []*pflag.FlagSet)) *cobra.Command { | ||
flags := []*pflag.FlagSet{ | ||
NodeFlags(), | ||
p2p.Flags(), | ||
header.Flags(), | ||
MiscFlags(), | ||
core.Flags(), | ||
rpc.Flags(), | ||
gateway.Flags(), | ||
state.Flags(), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "light [subcommand]", | ||
Args: cobra.NoArgs, | ||
Short: "Manage your Light node", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
return PersistentPreRunEnv(cmd, node.Light, args) | ||
}, | ||
} | ||
for _, option := range options { | ||
option(cmd, flags) | ||
} | ||
return cmd | ||
} | ||
|
||
func NewFull(options ...func(*cobra.Command, []*pflag.FlagSet)) *cobra.Command { | ||
flags := []*pflag.FlagSet{ | ||
NodeFlags(), | ||
p2p.Flags(), | ||
header.Flags(), | ||
MiscFlags(), | ||
core.Flags(), | ||
rpc.Flags(), | ||
gateway.Flags(), | ||
state.Flags(), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "full [subcommand]", | ||
Args: cobra.NoArgs, | ||
Short: "Manage your Full node", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
return PersistentPreRunEnv(cmd, node.Full, args) | ||
}, | ||
} | ||
for _, option := range options { | ||
option(cmd, flags) | ||
} | ||
return cmd | ||
} |
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