Skip to content

Commit

Permalink
feat: cidstore list size.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody committed Nov 25, 2024
1 parent fc48a0d commit 4ee6a55
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions core/commands/cidstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
)

const (
FilterKeyPrefix = "/gateway/filter/cid"
SizeOptionName = "size"
)

type cidList struct {
Strings []string
}
const (
FilterKeyPrefix = "/gateway/filter/cid"
DefaultSize = 50
)

var CidStoreCmd = &cmds.Command{
Helptext: cmds.HelpText{
Expand All @@ -37,10 +38,6 @@ var addCidCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Add cid to store.",
},
Options: []cmds.Option{
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, false, "cid to add to store"),
},
Expand All @@ -62,10 +59,6 @@ var getCidCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Get cid from store.",
},
Options: []cmds.Option{
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, false, "cid to add to store"),
},
Expand All @@ -86,10 +79,6 @@ var delCidCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Delete cid from store.",
},
Options: []cmds.Option{
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, false, "cid to add to store"),
},
Expand All @@ -110,10 +99,6 @@ var hasCidCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Check cid exits in store",
},
Options: []cmds.Option{
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
},
Arguments: []cmds.Argument{
cmds.StringArg("cid", true, false, "cid to add to store"),
},
Expand All @@ -137,13 +122,18 @@ var listCidCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List all cids in store",
},
Options: []cmds.Option{
cmds.IntOption(SizeOptionName, "s", "Number of cids to return.").WithDefault(DefaultSize),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
nd, err := cmdenv.GetNode(env)
if err != nil {
return err
}
size := req.Options[SizeOptionName].(int)
results, err := nd.Repo.Datastore().Query(req.Context, query.Query{
Prefix: FilterKeyPrefix,
Limit: size,
})
if err != nil {
return err
Expand Down

0 comments on commit 4ee6a55

Please sign in to comment.