-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add nodelist cmd * update desc * update docs * move around commands * update docs * export entity kinds * fix mark flag required * fix logging * move files around again * update docs * remove extra docs
- Loading branch information
Showing
8 changed files
with
238 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package nodelist | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/maticnetwork/polygon-cli/p2p/database" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const jsonIndent = " " | ||
|
||
type ( | ||
nodeListParams struct { | ||
ProjectID string | ||
OutputFile string | ||
Limit int | ||
} | ||
) | ||
|
||
var ( | ||
inputNodeListParams nodeListParams | ||
) | ||
|
||
var NodeListCmd = &cobra.Command{ | ||
Use: "nodelist [nodes.json]", | ||
Short: "Generate a node list to seed a node", | ||
Args: cobra.MinimumNArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) (err error) { | ||
inputNodeListParams.OutputFile = args[0] | ||
inputNodeListParams.ProjectID, err = cmd.Flags().GetString("project-id") | ||
return err | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
|
||
db := database.NewDatastore(cmd.Context(), database.DatastoreOptions{ | ||
ProjectID: inputNodeListParams.ProjectID, | ||
}) | ||
|
||
nodes, err := db.NodeList(ctx, inputNodeListParams.Limit) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bytes, err := json.MarshalIndent(nodes, "", jsonIndent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = os.WriteFile(inputNodeListParams.OutputFile, bytes, 0644); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
NodeListCmd.PersistentFlags().IntVarP(&inputNodeListParams.Limit, "limit", "l", 100, "Number of unique nodes to return") | ||
NodeListCmd.PersistentFlags().StringVarP(&inputNodeListParams.ProjectID, "project-id", "p", "", "GCP project ID") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# `polycli p2p nodelist` | ||
|
||
> Auto-generated documentation. | ||
## Table of Contents | ||
|
||
- [Description](#description) | ||
- [Usage](#usage) | ||
- [Flags](#flags) | ||
- [See Also](#see-also) | ||
|
||
## Description | ||
|
||
Generate a node list to seed a node | ||
|
||
```bash | ||
polycli p2p nodelist [nodes.json] [flags] | ||
``` | ||
|
||
## Flags | ||
|
||
```bash | ||
-h, --help help for nodelist | ||
-l, --limit int Number of unique nodes to return (default 100) | ||
-p, --project-id string GCP project ID | ||
``` | ||
|
||
The command also inherits flags from parent commands. | ||
|
||
```bash | ||
--config string config file (default is $HOME/.polygon-cli.yaml) | ||
--pretty-logs Should logs be in pretty format or JSON (default true) | ||
-v, --verbosity int 0 - Silent | ||
100 Fatal | ||
200 Error | ||
300 Warning | ||
400 Info | ||
500 Debug | ||
600 Trace (default 400) | ||
``` | ||
|
||
## See also | ||
|
||
- [polycli p2p](polycli_p2p.md) - Set of commands related to devp2p. |
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
Oops, something went wrong.