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