cli: rename commands so they reflect the interface definition better.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
eventstore
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var del = &cli.Command{
|
||||
Name: "del",
|
||||
Usage: "deletes an event",
|
||||
var delete_ = &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "deletes an event and all its associated index entries",
|
||||
Description: ``,
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
hasError := false
|
||||
@@ -21,7 +21,7 @@ var db eventstore.Store
|
||||
var app = &cli.Command{
|
||||
Name: "eventstore",
|
||||
Usage: "a CLI for all the eventstore backends",
|
||||
UsageText: "eventstore -d ./data/sqlite <query|put|del> ...",
|
||||
UsageText: "eventstore -d ./data/sqlite <query|save|delete> ...",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "store",
|
||||
@@ -87,12 +87,12 @@ var app = &cli.Command{
|
||||
return db.Init()
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
queryOrPut,
|
||||
queryOrSave,
|
||||
query,
|
||||
put,
|
||||
del,
|
||||
save,
|
||||
delete_,
|
||||
},
|
||||
DefaultCommand: "query-or-put",
|
||||
DefaultCommand: "query-or-save",
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var queryOrPut = &cli.Command{
|
||||
var queryOrSave = &cli.Command{
|
||||
Hidden: true,
|
||||
Name: "query-or-put",
|
||||
Name: "query-or-save",
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
line := getStdin()
|
||||
|
||||
@@ -22,10 +22,10 @@ var queryOrPut = &cli.Command{
|
||||
f := &nostr.Filter{}
|
||||
if json.Unmarshal([]byte(line), ee) == nil && ee.Event.ID != "" {
|
||||
e = &ee.Event
|
||||
return doPut(ctx, line, e)
|
||||
return doSave(ctx, line, e)
|
||||
}
|
||||
if json.Unmarshal([]byte(line), e) == nil && e.ID != "" {
|
||||
return doPut(ctx, line, e)
|
||||
return doSave(ctx, line, e)
|
||||
}
|
||||
if json.Unmarshal([]byte(line), re) == nil && len(re.Filters) > 0 {
|
||||
f = &re.Filters[0]
|
||||
@@ -39,7 +39,7 @@ var queryOrPut = &cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func doPut(ctx context.Context, line string, e *nostr.Event) error {
|
||||
func doSave(ctx context.Context, line string, e *nostr.Event) error {
|
||||
if err := db.SaveEvent(ctx, e); err != nil {
|
||||
return fmt.Errorf("failed to save event '%s': %s", line, err)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
var query = &cli.Command{
|
||||
Name: "query",
|
||||
Usage: "queries an eventstore for events",
|
||||
Usage: "queries an eventstore for events, takes a Nostr filter as argument",
|
||||
Description: ``,
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
hasError := false
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var put = &cli.Command{
|
||||
Name: "put",
|
||||
Usage: "saves an event to an eventstore",
|
||||
var save = &cli.Command{
|
||||
Name: "save",
|
||||
Usage: "stores an event in the database -- doesn't perform any kind of replacement",
|
||||
Description: ``,
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
hasError := false
|
||||
Reference in New Issue
Block a user