-
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: add dgate-cli with new pkg/dgclient
- Loading branch information
Showing
41 changed files
with
1,594 additions
and
335 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dgate-io/dgate/pkg/dgclient" | ||
"github.com/dgate-io/dgate/pkg/spec" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func CollectionCommand(client *dgclient.DGateClient) *cli.Command { | ||
return &cli.Command{ | ||
Name: "collection", | ||
Aliases: []string{"col"}, | ||
Args: true, | ||
ArgsUsage: "<command> <name>", | ||
Usage: "collection commands", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "create", | ||
Aliases: []string{"mk"}, | ||
Usage: "create a collection", | ||
Action: func(ctx *cli.Context) error { | ||
col, err := createMapFromArgs[spec.Collection]( | ||
ctx.Args().Slice(), "name", "schema", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(col, client.BaseUrl()) | ||
err = client.CreateCollection(col) | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(col) | ||
}, | ||
}, | ||
{ | ||
Name: "delete", | ||
Aliases: []string{"rm"}, | ||
Usage: "delete a collection", | ||
Action: func(ctx *cli.Context) error { | ||
col, err := createMapFromArgs[spec.Collection]( | ||
ctx.Args().Slice(), "name", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
err = client.DeleteCollection( | ||
col.Name, col.NamespaceName, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "list", | ||
Aliases: []string{"ls"}, | ||
Usage: "list collections", | ||
Action: func(ctx *cli.Context) error { | ||
col, err := client.ListCollection() | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(col) | ||
}, | ||
}, | ||
{ | ||
Name: "get", | ||
Usage: "get a collection", | ||
Action: func(ctx *cli.Context) error { | ||
col, err := createMapFromArgs[spec.Collection]( | ||
ctx.Args().Slice(), "name", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
col, err = client.GetCollection( | ||
col.Name, col.NamespaceName, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(col) | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
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,92 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dgate-io/dgate/pkg/dgclient" | ||
"github.com/dgate-io/dgate/pkg/spec" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func DocumentCommand(client *dgclient.DGateClient) *cli.Command { | ||
return &cli.Command{ | ||
Name: "document", | ||
Aliases: []string{"doc"}, | ||
Args: true, | ||
ArgsUsage: "<command> <name>", | ||
Usage: "document commands", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "create", | ||
Aliases: []string{"mk"}, | ||
Usage: "create a document", | ||
Action: func(ctx *cli.Context) error { | ||
doc, err := createMapFromArgs[spec.Document]( | ||
ctx.Args().Slice(), "id", | ||
"collection", "data", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(doc, client.BaseUrl()) | ||
err = client.CreateDocument(doc) | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(doc) | ||
}, | ||
}, | ||
{ | ||
Name: "delete", | ||
Aliases: []string{"rm"}, | ||
Usage: "delete a document", | ||
Action: func(ctx *cli.Context) error { | ||
doc, err := createMapFromArgs[spec.Document]( | ||
ctx.Args().Slice(), "id", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
err = client.DeleteDocument( | ||
doc.ID, doc.NamespaceName, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "list", | ||
Aliases: []string{"ls"}, | ||
Usage: "list documents", | ||
Action: func(ctx *cli.Context) error { | ||
doc, err := client.ListDocument() | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(doc) | ||
}, | ||
}, | ||
{ | ||
Name: "get", | ||
Usage: "get a document", | ||
Action: func(ctx *cli.Context) error { | ||
doc, err := createMapFromArgs[spec.Document]( | ||
ctx.Args().Slice(), "id", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
doc, err = client.GetDocument( | ||
doc.ID, doc.NamespaceName, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return jsonPrettyPrint(doc) | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.