mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-04 10:25:17 -06:00
@@ -23,52 +23,108 @@ import (
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/events"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
// CommandFunc specifies the signature of the functions that will be called based on the command line being executed.
|
||||
type CommandFunc func(context.Context, string, []string, *env.DoltEnv) int
|
||||
|
||||
// Command represents either a command to be run, or a command that is a parent of a subcommand.
|
||||
type Command struct {
|
||||
// Name is what the user will type on the command line in order to execute this command
|
||||
Name string
|
||||
// Desc is a short description of the command
|
||||
Desc string
|
||||
// Func is the CommandFunc that gets called when the user executes this command
|
||||
Func CommandFunc
|
||||
// ReqRepo says whether the command must be executed in an initialized dolt data repository directory. This should
|
||||
// always be set to false for non leaf commands.
|
||||
ReqRepo bool
|
||||
// Hide says whether to hide this command from help listings (for features that aren't ready to be released publicly).
|
||||
HideFromHelp bool
|
||||
// A client event associated with this command
|
||||
EventType eventsapi.ClientEventType
|
||||
}
|
||||
|
||||
// MapCommands takes a list of commands and maps them based on the commands name
|
||||
func MapCommands(commands []*Command) map[string]*Command {
|
||||
commandMap := make(map[string]*Command, len(commands))
|
||||
|
||||
for _, command := range commands {
|
||||
commandMap[strings.ToLower(command.Name)] = command
|
||||
func isHelp(str string) bool {
|
||||
switch {
|
||||
case str == "-h":
|
||||
return true
|
||||
case strings.TrimLeft(str, "- ") == "help":
|
||||
return true
|
||||
}
|
||||
|
||||
return commandMap
|
||||
return false
|
||||
}
|
||||
|
||||
// GenSubCommandHandler returns a handler function that will handle subcommand processing.
|
||||
func GenSubCommandHandler(commands []*Command) CommandFunc {
|
||||
commandMap := MapCommands(commands)
|
||||
|
||||
return func(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
if len(args) < 1 {
|
||||
printUsage(commandStr, commands)
|
||||
return 1
|
||||
func hasHelpFlag(args []string) bool {
|
||||
for _, arg := range args {
|
||||
if isHelp(arg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
subCommandStr := strings.ToLower(strings.TrimSpace(args[0]))
|
||||
if command, ok := commandMap[subCommandStr]; ok {
|
||||
if command.ReqRepo && !hasHelpFlag(args) {
|
||||
// Command is the interface which defines a Dolt cli command
|
||||
type Command interface {
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
Name() string
|
||||
// Description returns a description of the command
|
||||
Description() string
|
||||
// Exec executes the command
|
||||
Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
CreateMarkdown(fs filesys.Filesys, path, commandStr string) error
|
||||
}
|
||||
|
||||
// RepoNotRequiredCommand is an optional interface that commands can implement if the command can be run without
|
||||
// the current directory being a valid Dolt data repository. Any commands not implementing this interface are
|
||||
// assumed to require that they be run from a directory containing a Dolt data repository.
|
||||
type RepoNotRequiredCommand interface {
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
RequiresRepo() bool
|
||||
}
|
||||
|
||||
// EventMonitoredCommand is an optional interface that can be overridden in order to generate an event which is sent
|
||||
// to the metrics system when the command is run
|
||||
type EventMonitoredCommand interface {
|
||||
// EventType returns the type of the event to log
|
||||
EventType() eventsapi.ClientEventType
|
||||
}
|
||||
|
||||
// HiddenCommand is an optional interface that can be overridden so that a command is hidden from the help text
|
||||
type HiddenCommand interface {
|
||||
// Hidden should return true if this command should be hidden from the help text
|
||||
Hidden() bool
|
||||
}
|
||||
|
||||
// SubCommandHandler is a command implementation which holds subcommands which can be called
|
||||
type SubCommandHandler struct {
|
||||
name string
|
||||
description string
|
||||
Subcommands []Command
|
||||
}
|
||||
|
||||
// NewSubCommandHandler returns a new SubCommandHandler instance
|
||||
func NewSubCommandHandler(name, description string, subcommands []Command) SubCommandHandler {
|
||||
return SubCommandHandler{name, description, subcommands}
|
||||
}
|
||||
|
||||
func (hc SubCommandHandler) Name() string {
|
||||
return hc.name
|
||||
}
|
||||
|
||||
func (hc SubCommandHandler) Description() string {
|
||||
return hc.description
|
||||
}
|
||||
|
||||
func (hc SubCommandHandler) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (hc SubCommandHandler) CreateMarkdown(_ filesys.Filesys, _, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hc SubCommandHandler) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
if len(args) < 1 {
|
||||
hc.printUsage(commandStr)
|
||||
return 1
|
||||
}
|
||||
|
||||
subCommandStr := strings.ToLower(strings.TrimSpace(args[0]))
|
||||
for _, cmd := range hc.Subcommands {
|
||||
lwrName := strings.ToLower(cmd.Name())
|
||||
|
||||
if lwrName == subCommandStr {
|
||||
cmdRequiresRepo := true
|
||||
if rnrCmd, ok := cmd.(RepoNotRequiredCommand); ok {
|
||||
cmdRequiresRepo = rnrCmd.RequiresRepo()
|
||||
}
|
||||
|
||||
if cmdRequiresRepo && !hasHelpFlag(args) {
|
||||
if !dEnv.HasDoltDir() {
|
||||
PrintErrln(color.RedString("The current directory is not a valid dolt repository."))
|
||||
PrintErrln("run: dolt init before trying to run this command")
|
||||
@@ -85,12 +141,12 @@ func GenSubCommandHandler(commands []*Command) CommandFunc {
|
||||
}
|
||||
|
||||
var evt *events.Event
|
||||
if command.EventType != eventsapi.ClientEventType_TYPE_UNSPECIFIED {
|
||||
evt = events.NewEvent(command.EventType)
|
||||
if evtCmd, ok := cmd.(EventMonitoredCommand); ok {
|
||||
evt = events.NewEvent(evtCmd.EventType())
|
||||
ctx = events.NewContextForEvent(ctx, evt)
|
||||
}
|
||||
|
||||
ret := command.Func(ctx, commandStr+" "+subCommandStr, args[1:], dEnv)
|
||||
ret := cmd.Exec(ctx, commandStr+" "+subCommandStr, args[1:], dEnv)
|
||||
|
||||
if evt != nil {
|
||||
events.GlobalCollector.CloseEventAndAdd(evt)
|
||||
@@ -98,41 +154,26 @@ func GenSubCommandHandler(commands []*Command) CommandFunc {
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
if !isHelp(subCommandStr) {
|
||||
PrintErrln(color.RedString("Unknown Command " + subCommandStr))
|
||||
}
|
||||
printUsage(commandStr, commands)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
func isHelp(str string) bool {
|
||||
switch {
|
||||
case str == "-h":
|
||||
return true
|
||||
case strings.TrimLeft(str, "- ") == "help":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func hasHelpFlag(args []string) bool {
|
||||
for _, arg := range args {
|
||||
if arg == "-h" || arg == "--help" {
|
||||
return true
|
||||
}
|
||||
if !isHelp(subCommandStr) {
|
||||
PrintErrln(color.RedString("Unknown Command " + subCommandStr))
|
||||
}
|
||||
return false
|
||||
|
||||
hc.printUsage(commandStr)
|
||||
return 1
|
||||
}
|
||||
|
||||
func printUsage(commandStr string, commands []*Command) {
|
||||
func (hc SubCommandHandler) printUsage(commandStr string) {
|
||||
Println("Valid commands for", commandStr, "are")
|
||||
|
||||
for _, command := range commands {
|
||||
if !command.HideFromHelp {
|
||||
Printf(" %16s - %s\n", command.Name, command.Desc)
|
||||
for _, cmd := range hc.Subcommands {
|
||||
if hiddenCmd, ok := cmd.(HiddenCommand); ok {
|
||||
if hiddenCmd.Hidden() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Printf(" %16s - %s\n", cmd.Name(), cmd.Description())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
)
|
||||
|
||||
@@ -27,36 +29,57 @@ const (
|
||||
appName = "app"
|
||||
)
|
||||
|
||||
type trackedCommandFunc struct {
|
||||
called bool
|
||||
cmdStr string
|
||||
args []string
|
||||
type trackedCommand struct {
|
||||
name string
|
||||
description string
|
||||
called bool
|
||||
cmdStr string
|
||||
args []string
|
||||
}
|
||||
|
||||
func (tf *trackedCommandFunc) wasCalled() bool {
|
||||
return tf.called
|
||||
func NewTrackedCommand(name, desc string) *trackedCommand {
|
||||
return &trackedCommand{name, desc, false, "", nil}
|
||||
}
|
||||
|
||||
func (tf *trackedCommandFunc) commandFunc(ctx context.Context, cmdStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
tf.called = true
|
||||
tf.cmdStr = cmdStr
|
||||
tf.args = args
|
||||
func (cmd *trackedCommand) wasCalled() bool {
|
||||
return cmd.called
|
||||
}
|
||||
|
||||
func (cmd *trackedCommand) Name() string {
|
||||
return cmd.name
|
||||
}
|
||||
|
||||
func (cmd *trackedCommand) Description() string {
|
||||
return cmd.description
|
||||
}
|
||||
|
||||
func (cmd *trackedCommand) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *trackedCommand) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd *trackedCommand) Exec(ctx context.Context, cmdStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
cmd.called = true
|
||||
cmd.cmdStr = cmdStr
|
||||
cmd.args = args
|
||||
return 0
|
||||
}
|
||||
|
||||
func (tf *trackedCommandFunc) equalsState(called bool, cmdStr string, args []string) bool {
|
||||
return called == tf.called && cmdStr == tf.cmdStr && reflect.DeepEqual(args, tf.args)
|
||||
func (cmd *trackedCommand) equalsState(called bool, cmdStr string, args []string) bool {
|
||||
return called == cmd.called && cmdStr == cmd.cmdStr && reflect.DeepEqual(args, cmd.args)
|
||||
}
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
child1 := &trackedCommandFunc{}
|
||||
grandChild1 := &trackedCommandFunc{}
|
||||
commands := &Command{Name: appName, Desc: "test application", Func: GenSubCommandHandler([]*Command{
|
||||
{Name: "child1", Desc: "first child command", Func: child1.commandFunc},
|
||||
{Name: "child2", Desc: "second child command", Func: GenSubCommandHandler([]*Command{
|
||||
{Name: "grandchild1", Desc: "child2's first child", Func: grandChild1.commandFunc},
|
||||
})},
|
||||
})}
|
||||
grandChild1 := NewTrackedCommand("grandchild1", "child2's first child")
|
||||
child2 := NewSubCommandHandler("child2", "second child command", []Command{grandChild1})
|
||||
child1 := NewTrackedCommand("child1", "first child command")
|
||||
commands := NewSubCommandHandler(appName, "test application", []Command{
|
||||
child1,
|
||||
child2,
|
||||
})
|
||||
|
||||
res := runCommand(commands, "app")
|
||||
|
||||
@@ -96,12 +119,12 @@ func TestCommands(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func runCommand(root *Command, commandLine string) int {
|
||||
func runCommand(root Command, commandLine string) int {
|
||||
tokens := strings.Split(commandLine, " ")
|
||||
|
||||
if tokens[0] != appName {
|
||||
panic("Invalid test commandh line")
|
||||
panic("Invalid test command line")
|
||||
}
|
||||
|
||||
return root.Func(context.Background(), appName, tokens[1:], nil)
|
||||
return root.Exec(context.Background(), appName, tokens[1:], nil)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ import (
|
||||
"github.com/fatih/color"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/funcitr"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
)
|
||||
|
||||
var underline = color.New(color.Underline)
|
||||
@@ -66,6 +68,59 @@ func PrintHelpText(commandStr, shortDesc, longDesc string, synopsis []string, pa
|
||||
}
|
||||
}
|
||||
|
||||
func CreateMarkdown(fs filesys.Filesys, path, commandStr, shortDesc, longDesc string, synopsis []string, parser *argparser.ArgParser) error {
|
||||
wr, err := fs.OpenForWrite(path)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer wr.Close()
|
||||
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("## Command\n\n"), nil)
|
||||
err = iohelp.WriteIfNoErr(wr, []byte(commandStr+" - "+shortDesc+"\n\n"), err)
|
||||
|
||||
if len(synopsis) > 0 {
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("## Synopsis\n\n"), err)
|
||||
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("```sh\n"), err)
|
||||
for _, synopsisLine := range synopsis {
|
||||
err = iohelp.WriteIfNoErr(wr, []byte(commandStr+" "+synopsisLine+"\n"), err)
|
||||
}
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("```\n\n"), err)
|
||||
}
|
||||
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("## Description\n\n"), err)
|
||||
err = iohelp.WriteIfNoErr(wr, []byte(markdownEscape(longDesc)+"\n\n"), err)
|
||||
|
||||
if len(parser.Supported) > 0 || len(parser.ArgListHelp) > 0 {
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("## Options\n\n"), err)
|
||||
|
||||
for _, kvTuple := range parser.ArgListHelp {
|
||||
k, v := kvTuple[0], kvTuple[1]
|
||||
err = iohelp.WriteIfNoErr(wr, []byte("<"+k+">\n"+v+"\n\n"), err)
|
||||
}
|
||||
|
||||
for _, supOpt := range parser.Supported {
|
||||
argHelpFmt := "--%[2]s"
|
||||
|
||||
if supOpt.Abbrev != "" && supOpt.ValDesc != "" {
|
||||
argHelpFmt = "-%[1]s <%[3]s>, --%[2]s=<%[3]s>"
|
||||
} else if supOpt.Abbrev != "" {
|
||||
argHelpFmt = "-%[1]s, --%[2]s"
|
||||
} else if supOpt.ValDesc != "" {
|
||||
argHelpFmt = "--%[2]s=<%[3]s>"
|
||||
}
|
||||
|
||||
argHelp := fmt.Sprintf(argHelpFmt, supOpt.Abbrev, supOpt.Name, supOpt.ValDesc)
|
||||
err = iohelp.WriteIfNoErr(wr, []byte(argHelp+"\n"), err)
|
||||
err = iohelp.WriteIfNoErr(wr, []byte(supOpt.Desc+"\n\n"), err)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func PrintUsage(commandStr string, synopsis []string, parser *argparser.ArgParser) {
|
||||
_, termWidth := terminalSize()
|
||||
|
||||
@@ -101,6 +156,15 @@ const (
|
||||
|
||||
var bold = color.New(color.Bold)
|
||||
|
||||
func markdownEscape(str string) string {
|
||||
str = strings.ReplaceAll(str, "<b>", "**")
|
||||
str = strings.ReplaceAll(str, "</b>", "**")
|
||||
str = strings.ReplaceAll(str, "<", "<")
|
||||
str = strings.ReplaceAll(str, ">", ">")
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func embolden(str string) string {
|
||||
res := ""
|
||||
curr := str
|
||||
@@ -166,7 +230,8 @@ func terminalSize() (width, height int) {
|
||||
func OptionsUsage(ap *argparser.ArgParser, indent string, lineLen int) string {
|
||||
var lines []string
|
||||
|
||||
for k, v := range ap.ArgListHelp {
|
||||
for _, kvTuple := range ap.ArgListHelp {
|
||||
k, v := kvTuple[0], kvTuple[1]
|
||||
lines = append(lines, "<"+k+">")
|
||||
descLines := toParagraphLines(v, lineLen)
|
||||
descLines = indentLines(descLines, " ")
|
||||
|
||||
@@ -16,6 +16,8 @@ package cli
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestToIndentedParagraph(t *testing.T) {
|
||||
@@ -60,3 +62,31 @@ func TestEmbolden(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarkdownEscape(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
str string
|
||||
expected string
|
||||
}{
|
||||
{"Nothing to do", "some text no angle brackets", "some text no angle brackets"},
|
||||
{"Open with no close", "x < y, ", "x < y, "},
|
||||
{"Close with no open", "x > y, ", "x > y, "},
|
||||
{"Begin with open, no close", "<something", "<something"},
|
||||
{"End with close with no begin", "something>", "something>"},
|
||||
{"Basic escape", "test <test> test", "test <test> test"},
|
||||
{"Start", "<test> test", "<test> test"},
|
||||
{"End", "test <test>", "test <test>"},
|
||||
{"Start and end", "<test>", "<test>"},
|
||||
{"Start after end", "this > that, <test>, that < this", "this > that, <test>, that < this"},
|
||||
{"has spaces", "<has spaces>", "<has spaces>"},
|
||||
{"bold tags", "regular text, <b>bolt text</b>, more regular", "regular text, **bolt text**, more regular"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
res := markdownEscape(test.str)
|
||||
assert.Equal(t, test.expected, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -39,10 +41,34 @@ var addSynopsis = []string{
|
||||
`[<table>...]`,
|
||||
}
|
||||
|
||||
func Add(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type AddCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd AddCmd) Name() string {
|
||||
return "add"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd AddCmd) Description() string {
|
||||
return "Add table changes to the list of staged table changes."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd AddCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, addShortDesc, addLongDesc, addSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd AddCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "Working table(s) to add to the list tables staged to be committed. The abbreviation '.' can be used to add all tables."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "Working table(s) to add to the list tables staged to be committed. The abbreviation '.' can be used to add all tables."})
|
||||
ap.SupportsFlag(allParam, "a", "Stages any and all changes (adds, deletes, and modifications).")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd AddCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
helpPr, _ := cli.HelpAndUsagePrinters(commandStr, addShortDesc, addLongDesc, addSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, helpPr)
|
||||
|
||||
|
||||
@@ -23,12 +23,14 @@ import (
|
||||
"github.com/jedib0t/go-pretty/table"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions/commitwalk"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/hash"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
@@ -71,7 +73,35 @@ func (bi *blameInfo) TimestampString() string {
|
||||
// A blame graph is a map of primary key hashes to blameInfo structs
|
||||
type blameGraph map[hash.Hash]blameInfo
|
||||
|
||||
// Blame implements the `dolt blame` command. Blame annotates each row in the given table with information
|
||||
type BlameCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd BlameCmd) Name() string {
|
||||
return "blame"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd BlameCmd) Description() string {
|
||||
return "Show what revision and author last modified each row of a table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd BlameCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, blameShortDesc, blameLongDesc, blameSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd BlameCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd BlameCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_BLAME
|
||||
}
|
||||
|
||||
// Exec implements the `dolt blame` command. Blame annotates each row in the given table with information
|
||||
// from the revision which last modified the row, optionally starting from a given revision.
|
||||
//
|
||||
// Blame is computed as follows:
|
||||
@@ -86,8 +116,9 @@ type blameGraph map[hash.Hash]blameInfo
|
||||
// changed between the commits. If so, mark it with `new` as the blame origin and continue to the next node without blame.
|
||||
//
|
||||
// When all nodes have blame information, stop iterating through commits and print the blame graph.
|
||||
func Blame(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
// Exec executes the command
|
||||
func (cmd BlameCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, blameShortDesc, blameLongDesc, blameSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -24,11 +24,13 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
|
||||
)
|
||||
|
||||
@@ -69,9 +71,27 @@ const (
|
||||
allFlag = "all"
|
||||
)
|
||||
|
||||
func Branch(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type BranchCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd BranchCmd) Name() string {
|
||||
return "branch"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd BranchCmd) Description() string {
|
||||
return "Create, list, edit, delete branches."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd BranchCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, branchShortDesc, branchLongDesc, branchSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd BranchCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["start-point"] = "A commit that a new branch should point at."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"start-point", "A commit that a new branch should point at."})
|
||||
ap.SupportsFlag(listFlag, "", "List branches")
|
||||
ap.SupportsFlag(forceFlag, "f", branchForceFlagDesc)
|
||||
ap.SupportsFlag(copyFlag, "c", "Create a copy of a branch.")
|
||||
@@ -80,6 +100,17 @@ func Branch(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
ap.SupportsFlag(deleteForceFlag, "", "Shortcut for --delete --force.")
|
||||
ap.SupportsFlag(verboseFlag, "v", "When in list mode, show the hash and commit subject line for each head")
|
||||
ap.SupportsFlag(allFlag, "a", "When in list mode, shows remote tracked branches")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd BranchCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_BRANCH
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd BranchCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, branchShortDesc, branchLongDesc, branchSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,14 +17,15 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
var coShortDesc = `Switch branches or restore working tree tables`
|
||||
@@ -34,7 +35,7 @@ dolt checkout <branch>
|
||||
To prepare for working on <branch>, switch to it by updating the index and the tables in the working tree, and by pointing HEAD at the branch. Local modifications to the tables in the working
|
||||
tree are kept, so that they can be committed to the <branch>.
|
||||
|
||||
dolt checkout -b <new_branch> [<start point>]
|
||||
dolt checkout -b <new_branch> [<start_point>]
|
||||
Specifying -b causes a new branch to be created as if dolt branch were called and then checked out.
|
||||
|
||||
dolt checkout <table>...
|
||||
@@ -46,10 +47,40 @@ var coSynopsis = []string{
|
||||
`-b <new-branch> [<start-point>]`,
|
||||
}
|
||||
|
||||
func Checkout(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
const coBranchArg = "b"
|
||||
const coBranchArg = "b"
|
||||
|
||||
type CheckoutCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CheckoutCmd) Name() string {
|
||||
return "checkout"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CheckoutCmd) Description() string {
|
||||
return "Checkout a branch or overwrite a table from HEAD."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CheckoutCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, coShortDesc, coLongDesc, coSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd CheckoutCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(coBranchArg, "", "branch", "Create a new branch named <new_branch> and start it at <start_point>.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CheckoutCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CHECKOUT
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
helpPrt, usagePrt := cli.HelpAndUsagePrinters(commandStr, coShortDesc, coLongDesc, coSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, helpPrt)
|
||||
|
||||
|
||||
@@ -59,7 +59,31 @@ var cloneSynopsis = []string{
|
||||
"[-remote <remote>] [-branch <branch>] [--aws-region <region>] [--aws-creds-type <creds-type>] [--aws-creds-file <file>] [--aws-creds-profile <profile>] <remote-url> <new-dir>",
|
||||
}
|
||||
|
||||
func Clone(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CloneCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CloneCmd) Name() string {
|
||||
return "clone"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CloneCmd) Description() string {
|
||||
return "Clone from a remote data repository."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd CloneCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CloneCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, cloneShortDesc, cloneLongDesc, cloneSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd CloneCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(remoteParam, "", "name", "Name of the remote to be added. Default will be 'origin'.")
|
||||
ap.SupportsString(branchParam, "b", "branch", "The branch to be cloned. If not specified all branches will be cloned.")
|
||||
@@ -67,6 +91,17 @@ func Clone(ctx context.Context, commandStr string, args []string, dEnv *env.Dolt
|
||||
ap.SupportsValidatedString(dbfactory.AWSCredsTypeParam, "", "creds-type", "", argparser.ValidatorFromStrList(dbfactory.AWSCredsTypeParam, credTypes))
|
||||
ap.SupportsString(dbfactory.AWSCredsFileParam, "", "file", "AWS credentials file.")
|
||||
ap.SupportsString(dbfactory.AWSCredsProfile, "", "profile", "AWS profile to use.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CloneCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CLONE
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CloneCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, cloneShortDesc, cloneLongDesc, cloneSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package cnfcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -40,9 +43,39 @@ var catSynopsis = []string{
|
||||
"[<commit>] <table>...",
|
||||
}
|
||||
|
||||
func Cat(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CatCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CatCmd) Name() string {
|
||||
return "cat"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CatCmd) Description() string {
|
||||
return "Writes out the table conflicts."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CatCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, catShortDesc, catLongDesc, catSynopsis, ap)
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CatCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CONF_CAT
|
||||
}
|
||||
|
||||
func (cmd CatCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "List of tables to be printed. '.' can be used to print conflicts for all tables."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "List of tables to be printed. '.' can be used to print conflicts for all tables."})
|
||||
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CatCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, catShortDesc, catLongDesc, catSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
args = apr.Args()
|
||||
|
||||
@@ -16,10 +16,9 @@ package cnfcmds
|
||||
|
||||
import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
)
|
||||
|
||||
var Commands = cli.GenSubCommandHandler([]*cli.Command{
|
||||
{Name: "cat", Desc: "Writes out the table conflicts.", Func: Cat, ReqRepo: true, EventType: eventsapi.ClientEventType_CONF_CAT},
|
||||
{Name: "resolve", Desc: "Removes rows from list of conflicts", Func: Resolve, ReqRepo: true, EventType: eventsapi.ClientEventType_CONF_RESOLVE},
|
||||
var Commands = cli.NewSubCommandHandler("conflicts", "Send events logs to server.", []cli.Command{
|
||||
CatCmd{},
|
||||
ResolveCmd{},
|
||||
})
|
||||
|
||||
@@ -17,6 +17,9 @@ package cnfcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -61,12 +64,42 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func Resolve(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type ResolveCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ResolveCmd) Name() string {
|
||||
return "resolve"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ResolveCmd) Description() string {
|
||||
return "Removes rows from list of conflicts"
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ResolveCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, resShortDesc, resLongDesc, resSynopsis, ap)
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ResolveCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CONF_RESOLVE
|
||||
}
|
||||
|
||||
func (cmd ResolveCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "List of tables to be printed. When in auto-resolve mode, '.' can be used to resolve all tables."
|
||||
ap.ArgListHelp["key"] = "key(s) of rows within a table whose conflicts have been resolved"
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "List of tables to be printed. When in auto-resolve mode, '.' can be used to resolve all tables."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"key", "key(s) of rows within a table whose conflicts have been resolved"})
|
||||
ap.SupportsFlag("ours", "", "For all conflicts, take the version from our branch and resolve the conflict")
|
||||
ap.SupportsFlag("theirs", "", "Fol all conflicts, take the version from our branch and resolve the conflict")
|
||||
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ResolveCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, resShortDesc, resLongDesc, resSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -53,15 +53,15 @@ func createUninitializedEnv() *env.DoltEnv {
|
||||
|
||||
func TestCommandsRequireInitializedDir(t *testing.T) {
|
||||
tests := []struct {
|
||||
cmdStr string
|
||||
args []string
|
||||
commFunc cli.CommandFunc
|
||||
cmdStr string
|
||||
args []string
|
||||
comm cli.Command
|
||||
}{
|
||||
{"dolt config", []string{"-local", "-list"}, Config},
|
||||
{"dolt config", []string{"-local", "-list"}, ConfigCmd{}},
|
||||
}
|
||||
|
||||
dEnv := createUninitializedEnv()
|
||||
for _, test := range tests {
|
||||
test.commFunc(context.Background(), test.cmdStr, test.args, dEnv)
|
||||
test.comm.Exec(context.Background(), test.cmdStr, test.args, dEnv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/editor"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -54,12 +55,35 @@ var commitSynopsis = []string{
|
||||
"[options]",
|
||||
}
|
||||
|
||||
func Commit(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CommitCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CommitCmd) Name() string {
|
||||
return "commit"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CommitCmd) Description() string {
|
||||
return "Record changes to the repository."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CommitCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, commitShortDesc, commitLongDesc, commitSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd CommitCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(commitMessageArg, "m", "msg", "Use the given <msg> as the commit message.")
|
||||
ap.SupportsFlag(allowEmptyFlag, "", "Allow recording a commit that has the exact same data as its sole parent. This is usually a mistake, so it is disabled by default. This option bypasses that safety.")
|
||||
ap.SupportsString(dateParam, "", "date", "Specify the date used in the commit. If not specified the current system time is used.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CommitCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, commitShortDesc, commitLongDesc, commitSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -81,7 +105,7 @@ func Commit(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
err := actions.CommitStaged(ctx, dEnv, msg, t, apr.Contains(allowEmptyFlag))
|
||||
if err == nil {
|
||||
// if the commit was successful, print it out using the log command
|
||||
return Log(ctx, "log", []string{"-n=1"}, dEnv)
|
||||
return LogCmd{}.Exec(ctx, "log", []string{"-n=1"}, dEnv)
|
||||
}
|
||||
|
||||
return handleCommitErr(ctx, dEnv, err, usage)
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/config"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
|
||||
)
|
||||
|
||||
@@ -50,8 +51,31 @@ var cfgSynopsis = []string{
|
||||
"[--global|--local] --unset <name>...",
|
||||
}
|
||||
|
||||
// Config is used by the config command to allow users to view / edit their global and repository local configurations.
|
||||
func Config(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type ConfigCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ConfigCmd) Name() string {
|
||||
return "config"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ConfigCmd) Description() string {
|
||||
return "Dolt configuration."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd ConfigCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ConfigCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, cfgShortDesc, cfgLongDesc, cfgSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ConfigCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(globalParamName, "", "Use global config.")
|
||||
ap.SupportsFlag(localParamName, "", "Use repository local config.")
|
||||
@@ -59,6 +83,13 @@ func Config(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
ap.SupportsFlag(listOperationStr, "", "List the values of all config parameters.")
|
||||
ap.SupportsFlag(getOperationStr, "", "Get the value of one or more config parameters.")
|
||||
ap.SupportsFlag(unsetOperationStr, "", "Unset the value of one or more config paramaters.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec is used by the config command to allow users to view / edit their global and repository local configurations.
|
||||
// Exec executes the command
|
||||
func (cmd ConfigCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, cfgShortDesc, cfgLongDesc, cfgSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -30,8 +30,10 @@ var localCfg = set.NewStrSet([]string{localParamName})
|
||||
func TestConfig(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
dEnv := createTestEnv()
|
||||
ret := Config(ctx, "dolt config", []string{"-global", "--add", "name", "bheni"}, dEnv)
|
||||
ret += Config(ctx, "dolt config", []string{"-global", "--add", "title", "dufus"}, dEnv)
|
||||
|
||||
configCmd := ConfigCmd{}
|
||||
ret := configCmd.Exec(ctx, "dolt config", []string{"-global", "--add", "name", "bheni"}, dEnv)
|
||||
ret += configCmd.Exec(ctx, "dolt config", []string{"-global", "--add", "title", "dufus"}, dEnv)
|
||||
|
||||
expectedGlobal := map[string]string{
|
||||
"name": "bheni",
|
||||
@@ -44,7 +46,7 @@ func TestConfig(t *testing.T) {
|
||||
t.Error("config -add did not yield expected global results")
|
||||
}
|
||||
|
||||
ret = Config(ctx, "dolt config", []string{"-local", "--add", "title", "senior dufus"}, dEnv)
|
||||
ret = configCmd.Exec(ctx, "dolt config", []string{"-local", "--add", "title", "senior dufus"}, dEnv)
|
||||
|
||||
expectedLocal := map[string]string{
|
||||
"title": "senior dufus",
|
||||
@@ -58,7 +60,7 @@ func TestConfig(t *testing.T) {
|
||||
t.Error("Unexpected value of \"title\" retrieved from the config hierarchy")
|
||||
}
|
||||
|
||||
ret = Config(ctx, "dolt config", []string{"-global", "--unset", "name"}, dEnv)
|
||||
ret = configCmd.Exec(ctx, "dolt config", []string{"-global", "--unset", "name"}, dEnv)
|
||||
|
||||
expectedGlobal = map[string]string{
|
||||
"title": "dufus",
|
||||
@@ -118,16 +120,17 @@ func TestConfig(t *testing.T) {
|
||||
func TestInvalidConfigArgs(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
dEnv := createTestEnv()
|
||||
configCmd := ConfigCmd{}
|
||||
|
||||
// local and global flags passed together is invalid
|
||||
ret := Config(ctx, "dolt config", []string{"--global", "--local", "--add", "name", "bheni"}, dEnv)
|
||||
ret := configCmd.Exec(ctx, "dolt config", []string{"--global", "--local", "--add", "name", "bheni"}, dEnv)
|
||||
|
||||
if ret == 0 {
|
||||
t.Error("Invalid commands should fail. Command has both local and global")
|
||||
}
|
||||
|
||||
// both -add and -get are used
|
||||
ret = Config(ctx, "dolt config", []string{"-global", "--get", "--add", "title"}, dEnv)
|
||||
ret = configCmd.Exec(ctx, "dolt config", []string{"-global", "--get", "--add", "title"}, dEnv)
|
||||
|
||||
if ret == 0 {
|
||||
t.Error("Invalid commands should fail. Command is missing local/global")
|
||||
|
||||
@@ -18,6 +18,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -31,10 +34,45 @@ var checkShortDesc = "Check authenticating with a credential keypair against a d
|
||||
var checkLongDesc = `Tests calling a doltremoteapi with dolt credentials and reports the authentication result.`
|
||||
var checkSynopsis = []string{"[--endpoint doltremoteapi.dolthub.com:443] [--creds <eak95022q3vskvumn2fcrpibdnheq1dtr8t...>]"}
|
||||
|
||||
func Check(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CheckCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CheckCmd) Name() string {
|
||||
return "check"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CheckCmd) Description() string {
|
||||
return checkShortDesc
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CheckCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, checkShortDesc, checkLongDesc, checkSynopsis, ap)
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd CheckCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CheckCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CREDS_CHECK
|
||||
}
|
||||
|
||||
func (cmd CheckCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString("endpoint", "", "", "API endpoint, otherwise taken from config.")
|
||||
ap.SupportsString("creds", "", "", "Public Key ID or Public Key for credentials, otherwise taken from config.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CheckCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, lsShortDesc, lsLongDesc, lsSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -16,15 +16,14 @@ package credcmds
|
||||
|
||||
import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
)
|
||||
|
||||
var Commands = cli.GenSubCommandHandler([]*cli.Command{
|
||||
{Name: "new", Desc: newShortDesc, Func: New, ReqRepo: false, EventType: eventsapi.ClientEventType_CREDS_NEW},
|
||||
{Name: "rm", Desc: rmShortDesc, Func: Rm, ReqRepo: false, EventType: eventsapi.ClientEventType_CREDS_RM},
|
||||
{Name: "ls", Desc: lsShortDesc, Func: Ls, ReqRepo: false, EventType: eventsapi.ClientEventType_CREDS_LS},
|
||||
var Commands = cli.NewSubCommandHandler("creds", "Commands for managing credentials.", []cli.Command{
|
||||
NewCmd{},
|
||||
RmCmd{},
|
||||
LsCmd{},
|
||||
CheckCmd{},
|
||||
// TODO(aaron): Command to select a credential by public key and update global/repo config
|
||||
// to use it for authentication.
|
||||
//{Name: "use", Desc: useShortDesc, Func: Ls, ReqRepo: false, EventType: eventsapi.ClientEventType_CREDS_USE},
|
||||
{Name: "check", Desc: checkShortDesc, Func: Check, ReqRepo: false, EventType: eventsapi.ClientEventType_CREDS_CHECK},
|
||||
})
|
||||
|
||||
@@ -22,10 +22,12 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/creds"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
var lsShortDesc = "List keypairs available for authenticating with doltremoteapi."
|
||||
@@ -36,9 +38,44 @@ var lsSynopsis = []string{"[-v | --verbose]"}
|
||||
|
||||
var lsVerbose = false
|
||||
|
||||
func Ls(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type LsCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd LsCmd) Name() string {
|
||||
return "ls"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd LsCmd) Description() string {
|
||||
return lsShortDesc
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd LsCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, lsShortDesc, lsLongDesc, lsSynopsis, ap)
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd LsCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd LsCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CREDS_LS
|
||||
}
|
||||
|
||||
func (cmd LsCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag("verbose", "v", "Verbose output, including key id.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd LsCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, lsShortDesc, lsLongDesc, lsSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package credcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
@@ -31,8 +34,43 @@ Prints the public portion of the keypair, which can entered into the credentials
|
||||
settings page of dolthub.`
|
||||
var newSynopsis = []string{}
|
||||
|
||||
func New(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type NewCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd NewCmd) Name() string {
|
||||
return "new"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd NewCmd) Description() string {
|
||||
return newShortDesc
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd NewCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, newShortDesc, newLongDesc, newSynopsis, ap)
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd NewCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd NewCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CREDS_NEW
|
||||
}
|
||||
|
||||
func (cmd NewCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd NewCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, newShortDesc, newLongDesc, newSynopsis, ap)
|
||||
cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -21,17 +21,54 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
var rmShortDesc = "Remove a stored public/private keypair."
|
||||
var rmLongDesc = `Removes an existing keypair from dolt's credential storage.`
|
||||
var rmSynopsis = []string{"<public_key_as_appears_in_ls>"}
|
||||
|
||||
func Rm(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type RmCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd RmCmd) Name() string {
|
||||
return "rm"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd RmCmd) Description() string {
|
||||
return rmShortDesc
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd RmCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, rmShortDesc, rmLongDesc, rmSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd RmCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd RmCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd RmCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_CREDS_RM
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd RmCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, rmShortDesc, rmLongDesc, rmSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
args = apr.Args()
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/diff"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
@@ -42,6 +43,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/fwt"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/nullprinter"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/mathutil"
|
||||
"github.com/liquidata-inc/dolt/go/store/atomicerr"
|
||||
@@ -105,7 +107,30 @@ type diffArgs struct {
|
||||
where string
|
||||
}
|
||||
|
||||
func Diff(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type DiffCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd DiffCmd) Name() string {
|
||||
return "diff"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd DiffCmd) Description() string {
|
||||
return "Diff a table."
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd DiffCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_DIFF
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd DiffCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, diffShortDesc, diffLongDesc, diffSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd DiffCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(DataFlag, "d", "Show only the data changes, do not show the schema changes (Both shown by default).")
|
||||
ap.SupportsFlag(SchemaFlag, "s", "Show only the schema changes, do not show the data changes (Both shown by default).")
|
||||
@@ -113,6 +138,12 @@ func Diff(ctx context.Context, commandStr string, args []string, dEnv *env.DoltE
|
||||
ap.SupportsFlag(SQLFlag, "q", "Output diff as a SQL patch file of INSERT / UPDATE / DELETE statements")
|
||||
ap.SupportsString(whereParam, "", "column", "filters columns based on values in the diff. See dolt diff --help for details.")
|
||||
ap.SupportsInt(limitParam, "", "record_count", "limits to the first N diffs.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd DiffCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, _ := cli.HelpAndUsagePrinters(commandStr, diffShortDesc, diffLongDesc, diffSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
154
go/cmd/dolt/commands/dump_docs.go
Normal file
154
go/cmd/dolt/commands/dump_docs.go
Normal file
@@ -0,0 +1,154 @@
|
||||
// Copyright 2020 Liquidata, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
)
|
||||
|
||||
const (
|
||||
dirParamName = "dir"
|
||||
)
|
||||
|
||||
type DumpDocsCmd struct {
|
||||
DoltCommand cli.SubCommandHandler
|
||||
}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd *DumpDocsCmd) Name() string {
|
||||
return "dump-docs"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd *DumpDocsCmd) Description() string {
|
||||
return "dumps all documentation in md format to a directory"
|
||||
}
|
||||
|
||||
// Hidden should return true if this command should be hidden from the help text
|
||||
func (cmd *DumpDocsCmd) Hidden() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd *DumpDocsCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd *DumpDocsCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd *DumpDocsCmd) Exec(_ context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(dirParamName, "", "dir", "The directory where the md files should be dumped")
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, initShortDesc, initLongDesc, initSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
dirStr := apr.GetValueOrDefault(dirParamName, ".")
|
||||
|
||||
exists, isDir := dEnv.FS.Exists(dirStr)
|
||||
|
||||
if !exists {
|
||||
cli.PrintErrln(dirStr + " does not exist.")
|
||||
usage()
|
||||
return 1
|
||||
} else if !isDir {
|
||||
cli.PrintErrln(dirStr + " is a file, not a directory.")
|
||||
usage()
|
||||
return 1
|
||||
}
|
||||
|
||||
indexPath := filepath.Join(dirStr, "command_line_index.md")
|
||||
idxWr, err := dEnv.FS.OpenForWrite(indexPath)
|
||||
|
||||
if err != nil {
|
||||
verr := errhand.BuildDError("error writing to command_line.md").AddCause(err).Build()
|
||||
cli.PrintErrln(verr.Verbose())
|
||||
return 1
|
||||
}
|
||||
|
||||
defer idxWr.Close()
|
||||
err = iohelp.WriteAll(idxWr, []byte("# Dolt Commands\n"))
|
||||
|
||||
if err != nil {
|
||||
verr := errhand.BuildDError("error writing to command_line.md").AddCause(err).Build()
|
||||
cli.PrintErrln(verr.Verbose())
|
||||
return 1
|
||||
}
|
||||
|
||||
err = cmd.dumpDocs(idxWr, dEnv, dirStr, cmd.DoltCommand.Name(), cmd.DoltCommand.Subcommands)
|
||||
|
||||
if err != nil {
|
||||
verr := errhand.BuildDError("error: Failed to dump docs.").AddCause(err).Build()
|
||||
cli.PrintErrln(verr.Verbose())
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (cmd *DumpDocsCmd) dumpDocs(idxWr io.Writer, dEnv *env.DoltEnv, dirStr, cmdStr string, subCommands []cli.Command) error {
|
||||
for _, curr := range subCommands {
|
||||
var hidden bool
|
||||
if hidCmd, ok := curr.(cli.HiddenCommand); ok {
|
||||
hidden = hidCmd.Hidden()
|
||||
}
|
||||
|
||||
if !hidden {
|
||||
if subCmdHandler, ok := curr.(cli.SubCommandHandler); ok {
|
||||
err := cmd.dumpDocs(idxWr, dEnv, dirStr, cmdStr+" "+subCmdHandler.Name(), subCmdHandler.Subcommands)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
currCmdStr := cmdStr + " " + curr.Name()
|
||||
filename := strings.ReplaceAll(currCmdStr, " ", "_")
|
||||
filename = strings.ReplaceAll(filename, "-", "_")
|
||||
absPath := filepath.Join(dirStr, filename+".md")
|
||||
|
||||
indexLine := fmt.Sprintf("* [%s](%s)\n", currCmdStr, filename)
|
||||
err := iohelp.WriteAll(idxWr, []byte(indexLine))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = curr.CreateMarkdown(dEnv.FS, absPath, currCmdStr)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -17,8 +17,6 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/earl"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
@@ -28,6 +26,8 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/events"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/earl"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
var fetchShortDesc = "Download objects and refs from another repository"
|
||||
@@ -42,7 +42,36 @@ var fetchSynopsis = []string{
|
||||
"[<remote>] [<refspec> ...]",
|
||||
}
|
||||
|
||||
func Fetch(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type FetchCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd FetchCmd) Name() string {
|
||||
return "fetch"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd FetchCmd) Description() string {
|
||||
return "Update the database from a remote data repository."
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd FetchCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_FETCH
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd FetchCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, fetchShortDesc, fetchLongDesc, fetchSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd FetchCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd FetchCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, fetchShortDesc, fetchLongDesc, fetchSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -41,12 +42,43 @@ var initSynopsis = []string{
|
||||
"[<options>] [<path>]",
|
||||
}
|
||||
|
||||
// Init is used by the init command
|
||||
func Init(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type InitCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd InitCmd) Name() string {
|
||||
return "init"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd InitCmd) Description() string {
|
||||
return "Create an empty Dolt data repository."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd InitCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd InitCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
|
||||
return cli.CreateMarkdown(fs, path, commandStr, initShortDesc, initLongDesc, initSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd InitCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(usernameParamName, "", "name", "The name used in commits to this repo. If not provided will be taken from \""+env.UserNameKey+"\" in the global config.")
|
||||
ap.SupportsString(emailParamName, "", "email", "The email address used. If not provided will be taken from \""+env.UserEmailKey+"\" in the global config.")
|
||||
ap.SupportsString(dateParam, "", "date", "Specify the date used in the initial commit. If not specified the current system time is used.")
|
||||
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, initShortDesc, initLongDesc, initSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -116,5 +148,4 @@ func initRepoErrToVerr(err error) errhand.VerboseError {
|
||||
default:
|
||||
return errhand.BuildDError("fatal: " + err.Error()).Build()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestInit(t *testing.T) {
|
||||
gCfg, _ := dEnv.Config.GetConfig(env.GlobalConfig)
|
||||
gCfg.SetStrings(test.GlobalConfig)
|
||||
|
||||
result := Init(context.Background(), "dolt init", test.Args, dEnv)
|
||||
result := InitCmd{}.Exec(context.Background(), "dolt init", test.Args, dEnv)
|
||||
|
||||
if (result == 0) != test.ExpectSuccess {
|
||||
t.Error(test.Name, "- Expected success:", test.ExpectSuccess, "result:", result == 0)
|
||||
@@ -82,13 +82,13 @@ func TestInit(t *testing.T) {
|
||||
|
||||
func TestInitTwice(t *testing.T) {
|
||||
dEnv := createUninitializedEnv()
|
||||
result := Init(context.Background(), "dolt init", []string{"-name", "Bill Billerson", "-email", "bigbillieb@fake.horse"}, dEnv)
|
||||
result := InitCmd{}.Exec(context.Background(), "dolt init", []string{"-name", "Bill Billerson", "-email", "bigbillieb@fake.horse"}, dEnv)
|
||||
|
||||
if result != 0 {
|
||||
t.Error("First init should succeed")
|
||||
}
|
||||
|
||||
result = Init(context.Background(), "dolt init", []string{"-name", "Bill Billerson", "-email", "bigbillieb@fake.horse"}, dEnv)
|
||||
result = InitCmd{}.Exec(context.Background(), "dolt init", []string{"-name", "Bill Billerson", "-email", "bigbillieb@fake.horse"}, dEnv)
|
||||
|
||||
if result == 0 {
|
||||
t.Error("Second init should fail")
|
||||
|
||||
@@ -22,10 +22,12 @@ import (
|
||||
"github.com/fatih/color"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/hash"
|
||||
)
|
||||
|
||||
@@ -78,13 +80,42 @@ func printDesc(cm *doltdb.CommitMeta) {
|
||||
cli.Println(formattedDesc)
|
||||
}
|
||||
|
||||
func Log(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type LogCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd LogCmd) Name() string {
|
||||
return "log"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd LogCmd) Description() string {
|
||||
return "Show commit logs."
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd LogCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_LOG
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd LogCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := createLogArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, logShortDesc, logLongDesc, logSynopsis, ap)
|
||||
}
|
||||
|
||||
func createLogArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsInt(numLinesParam, "n", "num_commits", "Limit the number of commits to output")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd LogCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
return logWithLoggerFunc(ctx, commandStr, args, dEnv, logToStdOutFunc)
|
||||
}
|
||||
|
||||
func logWithLoggerFunc(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, loggerFunc commitLoggerFunc) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsInt(numLinesParam, "n", "num_commits", "Limit the number of commits to output")
|
||||
ap := createLogArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, logShortDesc, logLongDesc, logSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -23,11 +23,13 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
remotesapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/remotesapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/creds"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,9 +42,44 @@ var loginSynopsis = []string{
|
||||
"[<creds>]",
|
||||
}
|
||||
|
||||
func Login(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type LoginCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd LoginCmd) Name() string {
|
||||
return "login"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd LoginCmd) Description() string {
|
||||
return "Login to a dolt remote host."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd LoginCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd LoginCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, loginShortDesc, loginLongDesc, loginSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd LoginCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["creds"] = "A specific credential to use for login."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"creds", "A specific credential to use for login."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd LoginCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_LOGIN
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd LoginCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, loginShortDesc, loginLongDesc, loginSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -32,9 +35,38 @@ var lsSynopsis = []string{
|
||||
"[<commit>]",
|
||||
}
|
||||
|
||||
func Ls(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type LsCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd LsCmd) Name() string {
|
||||
return "ls"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd LsCmd) Description() string {
|
||||
return "List tables in the working set."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd LsCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, lsShortDesc, lsLongDesc, lsSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd LsCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(verboseFlag, "v", "show the hash of the table")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd LsCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_LS
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd LsCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, lsShortDesc, lsLongDesc, lsSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -24,19 +24,21 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/merge"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
const (
|
||||
abortParam = "abort"
|
||||
)
|
||||
|
||||
var mergeShortDest = "Join two or more development histories together"
|
||||
var mergeShortDesc = "Join two or more development histories together"
|
||||
var mergeLongDesc = "Incorporates changes from the named commits (since the time their histories diverged from the " +
|
||||
"current branch) into the current branch.\n" +
|
||||
"\n" +
|
||||
@@ -59,10 +61,39 @@ var abortDetails = "Abort the current conflict resolution process, and try to re
|
||||
"unable to reconstruct these changes. It is therefore recommended to always commit or stash your changes before " +
|
||||
"running git merge."
|
||||
|
||||
func Merge(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type MergeCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd MergeCmd) Name() string {
|
||||
return "merge"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd MergeCmd) Description() string {
|
||||
return "Merge a branch."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd MergeCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, mergeShortDesc, mergeLongDesc, mergeSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd MergeCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(abortParam, "", abortDetails)
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, mergeShortDest, mergeLongDesc, mergeSynopsis, ap)
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd MergeCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_MERGE
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd MergeCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, mergeShortDesc, mergeLongDesc, mergeSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
var verr errhand.VerboseError
|
||||
|
||||
@@ -17,6 +17,9 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
@@ -34,8 +37,37 @@ var pullSynopsis = []string{
|
||||
"<remote>",
|
||||
}
|
||||
|
||||
func Pull(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type PullCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd PullCmd) Name() string {
|
||||
return "pull"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd PullCmd) Description() string {
|
||||
return "Fetch from a dolt remote data repository and merge."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd PullCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, pullShortDesc, pullLongDesc, pullSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd PullCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd PullCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_PULL
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd PullCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, pullShortDesc, pullLongDesc, pullSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
branch := dEnv.RepoState.Head.Ref
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/events"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/earl"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/datas"
|
||||
)
|
||||
|
||||
@@ -59,9 +60,38 @@ var pushSynopsis = []string{
|
||||
"[-u | --set-upstream] [<remote>] [<refspec>]",
|
||||
}
|
||||
|
||||
func Push(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type PushCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd PushCmd) Name() string {
|
||||
return "push"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd PushCmd) Description() string {
|
||||
return "Push to a dolt remote."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd PushCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, pushShortDesc, pushLongDesc, pushSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd PushCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(SetUpstreamFlag, "u", "For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less dolt pull and other commands.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd PushCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_PUSH
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd PushCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, pushShortDesc, pushLongDesc, pushSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -23,16 +23,16 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/config"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/earl"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
var ErrInvalidPort = errors.New("invalid port")
|
||||
@@ -83,16 +83,45 @@ const (
|
||||
var awsParams = []string{dbfactory.AWSRegionParam, dbfactory.AWSCredsTypeParam, dbfactory.AWSCredsFileParam, dbfactory.AWSCredsProfile}
|
||||
var credTypes = []string{dbfactory.RoleCS.String(), dbfactory.EnvCS.String(), dbfactory.FileCS.String()}
|
||||
|
||||
func Remote(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type RemoteCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd RemoteCmd) Name() string {
|
||||
return "remote"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd RemoteCmd) Description() string {
|
||||
return "Manage set of tracked repositories."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd RemoteCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, remoteShortDesc, remoteLongDesc, remoteSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd RemoteCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["region"] = "cloud provider region associated with this remote."
|
||||
ap.ArgListHelp["creds-type"] = "credential type. Valid options are role, env, and file. See the help section for additional details."
|
||||
ap.ArgListHelp["profile"] = "AWS profile to use."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"region", "cloud provider region associated with this remote."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"creds-type", "credential type. Valid options are role, env, and file. See the help section for additional details."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"profile", "AWS profile to use."})
|
||||
ap.SupportsFlag(verboseFlag, "v", "When printing the list of remotes adds additional details.")
|
||||
ap.SupportsString(dbfactory.AWSRegionParam, "", "region", "")
|
||||
ap.SupportsValidatedString(dbfactory.AWSCredsTypeParam, "", "creds-type", "", argparser.ValidatorFromStrList(dbfactory.AWSCredsTypeParam, credTypes))
|
||||
ap.SupportsString(dbfactory.AWSCredsFileParam, "", "file", "AWS credentials file")
|
||||
ap.SupportsString(dbfactory.AWSCredsProfile, "", "profile", "AWS profile to use")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd RemoteCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_REMOTE
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd RemoteCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, remoteShortDesc, remoteLongDesc, remoteSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -53,10 +55,34 @@ var resetSynopsis = []string{
|
||||
"[--hard | --soft]",
|
||||
}
|
||||
|
||||
func Reset(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type ResetCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ResetCmd) Name() string {
|
||||
return "reset"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ResetCmd) Description() string {
|
||||
return "Remove table changes from the list of staged table changes."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ResetCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, resetShortDesc, resetLongDesc, resetSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ResetCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(HardResetParam, "", "Resets the working tables and staged tables. Any changes to tracked tables in the working tree since <commit> are discarded.")
|
||||
ap.SupportsFlag(SoftResetParam, "", "Does not touch the working tables, but removes all tables staged to be committed.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ResetCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, resetShortDesc, resetLongDesc, resetSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -42,13 +45,41 @@ var schAddColSynopsis = []string{
|
||||
"[--default <default_value>] [--not-null] [--tag <tag-number>] <table> <name> <type>",
|
||||
}
|
||||
|
||||
func AddColumn(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type AddColumnCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd AddColumnCmd) Name() string {
|
||||
return "add-column"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd AddColumnCmd) Description() string {
|
||||
return "Adds a column to specified table's schema."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd AddColumnCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, schAddColShortDesc, schAddColLongDesc, schAddColSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd AddColumnCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "table where the new column should be added."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "table where the new column should be added."})
|
||||
ap.SupportsString(defaultParam, "", "default-value", "If provided all existing rows will be given this value as their default.")
|
||||
ap.SupportsUint(tagParam, "", "tag-number", "The numeric tag for the new column.")
|
||||
ap.SupportsFlag(notNullFlag, "", "If provided rows without a value in this column will be considered invalid. If rows already exist and not-null is specified then a default value must be provided.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd AddColumnCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd AddColumnCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, schAddColShortDesc, schAddColLongDesc, schAddColSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package schcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -32,10 +35,38 @@ var schDropColSynopsis = []string{
|
||||
"<table> <column>",
|
||||
}
|
||||
|
||||
func DropColumn(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "table(s) whose schema is being displayed."
|
||||
type DropColumnCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd DropColumnCmd) Name() string {
|
||||
return "drop-column"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd DropColumnCmd) Description() string {
|
||||
return "Removes a column of the specified table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd DropColumnCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, schDropColShortDesc, schDropColLongDesc, schDropColSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd DropColumnCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "table(s) whose schema is being displayed."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd DropColumnCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd DropColumnCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, schDropColShortDesc, schDropColLongDesc, schDropColSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package schcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -32,14 +35,42 @@ var schExportSynopsis = []string{
|
||||
"<table> <file>",
|
||||
}
|
||||
|
||||
func Export(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type ExportCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ExportCmd) Name() string {
|
||||
return "export"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ExportCmd) Description() string {
|
||||
return "Exports a table's schema."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ExportCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, schExportShortDesc, schExportLongDesc, schExportSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ExportCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "table whose schema is being exported."
|
||||
ap.ArgListHelp["commit"] = "commit at which point the schema will be displayed."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "table whose schema is being exported."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"commit", "commit at which point the schema will be displayed."})
|
||||
ap.SupportsString(defaultParam, "", "default-value", "If provided all existing rows will be given this value as their default.")
|
||||
ap.SupportsUint(tagParam, "", "tag-number", "The numeric tag for the new column.")
|
||||
ap.SupportsFlag(notNullFlag, "", "If provided rows without a value in this column will be considered invalid. If rows already exist and not-null is specified then a default value must be provided.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ExportCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ExportCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, schExportShortDesc, schExportLongDesc, schExportSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands/tblcmds"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
@@ -105,11 +106,33 @@ type importArgs struct {
|
||||
inferArgs *actions.InferenceArgs
|
||||
}
|
||||
|
||||
// Import is a schema command that will take a file and infer it's schema, and then create a table matching that schema.
|
||||
func Import(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type ImportCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ImportCmd) Name() string {
|
||||
return "import"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ImportCmd) Description() string {
|
||||
return "Creates a new table with an inferred schema."
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ImportCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ImportCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, schImportShortDesc, schImportLongDesc, schImportSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ImportCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "Name of the table to be created."
|
||||
ap.ArgListHelp["file"] = "The file being used to infer the schema."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "Name of the table to be created."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"file", "The file being used to infer the schema."})
|
||||
ap.SupportsFlag(createFlag, "c", "Create a table with the schema inferred from the <file> provided.")
|
||||
//ap.SupportsFlag(updateFlag, "u", "Update a table to match the inferred schema of the <file> provided")
|
||||
ap.SupportsFlag(replaceFlag, "r", "Replace a table with a new schema that has the inferred schema from the <file> provided. All previous data will be lost.")
|
||||
@@ -120,7 +143,13 @@ func Import(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
ap.SupportsString(mappingParam, "", "mapping-file", "A file that can map a column name in <file> to a new value.")
|
||||
ap.SupportsString(floatThresholdParam, "", "float", "Minimum value at which the fractional component of a value must exceed in order to be considered a float.")
|
||||
ap.SupportsString(delimParam, "", "delimiter", "Specify a delimiter for a csv style file with a non-comma delimiter.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec implements the import schema command that will take a file and infer it's schema, and then create a table matching that schema.
|
||||
// Exec executes the command
|
||||
func (cmd ImportCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, schImportShortDesc, schImportLongDesc, schImportSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package schcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -33,10 +36,38 @@ var schRenameColSynopsis = []string{
|
||||
"<table> <old> <new>",
|
||||
}
|
||||
|
||||
func RenameColumn(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "table being modified."
|
||||
type RenameColumnCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd RenameColumnCmd) Name() string {
|
||||
return "rename-column"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd RenameColumnCmd) Description() string {
|
||||
return "Renames a column of the specified table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd RenameColumnCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, schRenameColShortDesc, schRenameColLongDesc, schRenameColSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd RenameColumnCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "table being modified."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd RenameColumnCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd RenameColumnCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, schRenameColShortDesc, schRenameColLongDesc, schRenameColSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -16,14 +16,13 @@ package schcmds
|
||||
|
||||
import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
)
|
||||
|
||||
var Commands = cli.GenSubCommandHandler([]*cli.Command{
|
||||
{Name: "add-column", Desc: "Adds a column to specified table's schema.", Func: AddColumn, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "drop-column", Desc: "Removes a column of the specified table.", Func: DropColumn, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "export", Desc: "Exports a table's schema.", Func: Export, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "import", Desc: "Creates a new table with an inferred schema.", Func: Import, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "rename-column", Desc: "Renames a column of the specified table.", Func: RenameColumn, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "show", Desc: "Shows the schema of one or more tables.", Func: Show, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
var Commands = cli.NewSubCommandHandler("schema", "Commands for showing, and modifying table schemas.", []cli.Command{
|
||||
AddColumnCmd{},
|
||||
DropColumnCmd{},
|
||||
ExportCmd{},
|
||||
ImportCmd{},
|
||||
RenameColumnCmd{},
|
||||
ShowCmd{},
|
||||
})
|
||||
|
||||
@@ -22,11 +22,13 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sql"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
const ()
|
||||
@@ -42,11 +44,39 @@ var tblSchemaSynopsis = []string{
|
||||
|
||||
var bold = color.New(color.Bold)
|
||||
|
||||
func Show(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "table(s) whose schema is being displayed."
|
||||
ap.ArgListHelp["commit"] = "commit at which point the schema will be displayed."
|
||||
type ShowCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ShowCmd) Name() string {
|
||||
return "show"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ShowCmd) Description() string {
|
||||
return "Shows the schema of one or more tables."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ShowCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, tblSchemaShortDesc, tblSchemaLongDesc, tblSchemaSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ShowCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "table(s) whose schema is being displayed."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"commit", "commit at which point the schema will be displayed."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ShowCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SCHEMA
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ShowCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, tblSchemaShortDesc, tblSchemaLongDesc, tblSchemaSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
if apr.ContainsArg(doltdb.DocTableName) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/events"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
// SendMetricsCommand is the command used for sending metrics
|
||||
@@ -37,8 +38,37 @@ const (
|
||||
sendMetricsShortDec = "Send metrics to the events server or print them to stdout"
|
||||
)
|
||||
|
||||
// SendMetrics is the commandFunc used that flushes the events to the grpc service
|
||||
func SendMetrics(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type SendMetricsCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd SendMetricsCmd) Name() string {
|
||||
return SendMetricsCommand
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd SendMetricsCmd) Description() string {
|
||||
return "Send events logs to server."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd SendMetricsCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Hidden should return true if this command should be hidden from the help text
|
||||
func (cmd SendMetricsCmd) Hidden() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd SendMetricsCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Exec is the implementation of the command that flushes the events to the grpc service
|
||||
// Exec executes the command
|
||||
func (cmd SendMetricsCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsFlag(outputFlag, "o", "Flush events to stdout.")
|
||||
|
||||
|
||||
33
go/cmd/dolt/commands/sql.go
Executable file → Normal file
33
go/cmd/dolt/commands/sql.go
Executable file → Normal file
@@ -34,6 +34,7 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
|
||||
@@ -46,6 +47,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/nullprinter"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/tabular"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/osutil"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
@@ -77,9 +79,38 @@ const (
|
||||
# "exit" or "quit" (or Ctrl-D) to exit.`
|
||||
)
|
||||
|
||||
func Sql(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type SqlCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd SqlCmd) Name() string {
|
||||
return "sql"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd SqlCmd) Description() string {
|
||||
return "Run a SQL query against tables in repository."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd SqlCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, sqlShortDesc, sqlLongDesc, sqlSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd SqlCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(queryFlag, "q", "SQL query to run", "Runs a single query and exits")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd SqlCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SQL
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, sqlShortDesc, sqlLongDesc, sqlSynopsis, ap)
|
||||
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestSqlConsole(t *testing.T) {
|
||||
args := []string{}
|
||||
commandStr := "dolt sql"
|
||||
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, 0, result)
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestSqlSelect(t *testing.T) {
|
||||
args := []string{"-q", test.query}
|
||||
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
})
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func TestSqlShow(t *testing.T) {
|
||||
args := []string{"-q", test.query}
|
||||
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
})
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func TestCreateTable(t *testing.T) {
|
||||
|
||||
args := []string{"-q", test.query}
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
|
||||
working, err = dEnv.WorkingRoot(context.Background())
|
||||
@@ -179,7 +179,7 @@ func TestShowTables(t *testing.T) {
|
||||
|
||||
args := []string{"-q", test.query}
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
})
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func TestAlterTable(t *testing.T) {
|
||||
|
||||
args := []string{"-q", test.query}
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
})
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func TestDropTable(t *testing.T) {
|
||||
|
||||
args := []string{"-q", test.query}
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
})
|
||||
}
|
||||
@@ -349,7 +349,7 @@ func TestInsert(t *testing.T) {
|
||||
args := []string{"-q", test.query}
|
||||
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
|
||||
if result == 0 {
|
||||
@@ -433,7 +433,7 @@ func TestUpdate(t *testing.T) {
|
||||
args := []string{"-q", test.query}
|
||||
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
|
||||
if result == 0 {
|
||||
@@ -512,7 +512,7 @@ func TestDelete(t *testing.T) {
|
||||
args := []string{"-q", test.query}
|
||||
|
||||
commandStr := "dolt sql"
|
||||
result := Sql(context.TODO(), commandStr, args, dEnv)
|
||||
result := SqlCmd{}.Exec(context.TODO(), commandStr, args, dEnv)
|
||||
assert.Equal(t, test.expectedRes, result)
|
||||
|
||||
if result == 0 {
|
||||
|
||||
@@ -18,6 +18,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
@@ -44,13 +47,25 @@ var sqlServerSynopsis = []string{
|
||||
"[-H <host>] [-P <port>] [-u <user>] [-p <password>] [-t <timeout>] [-l <loglevel>] [-r]",
|
||||
}
|
||||
|
||||
func SqlServer(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
return SqlServerImpl(ctx, commandStr, args, dEnv, nil)
|
||||
type SqlServerCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd SqlServerCmd) Name() string {
|
||||
return "sql-server"
|
||||
}
|
||||
|
||||
func SqlServerImpl(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, serverController *ServerController) int {
|
||||
serverConfig := DefaultServerConfig()
|
||||
// Description returns a description of the command
|
||||
func (cmd SqlServerCmd) Description() string {
|
||||
return "Starts a MySQL-compatible server."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd SqlServerCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := createArgParser(DefaultServerConfig())
|
||||
return cli.CreateMarkdown(fs, path, commandStr, sqlServerShortDesc, sqlServerLongDesc, sqlServerSynopsis, ap)
|
||||
}
|
||||
|
||||
func createArgParser(serverConfig *ServerConfig) *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.SupportsString(hostFlag, "H", "Host address", fmt.Sprintf("Defines the host address that the server will run on (default `%v`)", serverConfig.Host))
|
||||
ap.SupportsUint(portFlag, "P", "Port", fmt.Sprintf("Defines the port that the server will run on (default `%v`)", serverConfig.Port))
|
||||
@@ -59,6 +74,24 @@ func SqlServerImpl(ctx context.Context, commandStr string, args []string, dEnv *
|
||||
ap.SupportsInt(timeoutFlag, "t", "Connection timeout", fmt.Sprintf("Defines the timeout, in seconds, used for connections\nA value of `0` represents an infinite timeout (default `%v`)", serverConfig.Timeout))
|
||||
ap.SupportsFlag(readonlyFlag, "r", "Disables modification of the database")
|
||||
ap.SupportsString(logLevelFlag, "l", "Log level", fmt.Sprintf("Defines the level of logging provided\nOptions are: `debug`, `info`, `warning`, `error`, `fatal` (default `%v`)", serverConfig.LogLevel))
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd SqlServerCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_SQL_SERVER
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd SqlServerCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
|
||||
return SqlServerImpl(ctx, commandStr, args, dEnv, nil)
|
||||
}
|
||||
|
||||
func SqlServerImpl(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, serverController *ServerController) int {
|
||||
serverConfig := DefaultServerConfig()
|
||||
|
||||
ap := createArgParser(serverConfig)
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, sqlServerShortDesc, sqlServerLongDesc, sqlServerSynopsis, ap)
|
||||
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env/actions"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
|
||||
)
|
||||
@@ -41,8 +42,32 @@ before running <b>dolt commit</b>.`
|
||||
|
||||
var statusSynopsis = []string{""}
|
||||
|
||||
func Status(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type StatusCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd StatusCmd) Name() string {
|
||||
return "status"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd StatusCmd) Description() string {
|
||||
return "Show the working tree status."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd StatusCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, statusShortDesc, statusLongDesc, statusSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd StatusCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, _ := cli.HelpAndUsagePrinters(commandStr, statusShortDesc, statusLongDesc, statusSynopsis, ap)
|
||||
cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ package tblcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -39,12 +42,41 @@ var tblCpSynopsis = []string{
|
||||
"[-f] [<commit>] <oldtable> <newtable>",
|
||||
}
|
||||
|
||||
func Cp(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CpCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CpCmd) Name() string {
|
||||
return "cp"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CpCmd) Description() string {
|
||||
return "Copies a table"
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CpCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, tblCpShortDesc, tblCpLongDesc, tblCpSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd CpCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["commit"] = "The state at which point the table whill be copied."
|
||||
ap.ArgListHelp["oldtable"] = "The table being copied."
|
||||
ap.ArgListHelp["newtable"] = "The destination where the table is being copied to."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"commit", "The state at which point the table whill be copied."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"oldtable", "The table being copied."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"newtable", "The destination where the table is being copied to."})
|
||||
ap.SupportsFlag(forceParam, "f", "If data already exists in the destination, the Force flag will allow the target to be overwritten.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CpCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_CP
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CpCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, tblCpShortDesc, tblCpLongDesc, tblCpSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -42,12 +45,41 @@ var tblCreateSynopsis = []string{
|
||||
"[-f] -s <schema_file> <table>...",
|
||||
}
|
||||
|
||||
func Create(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type CreateCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd CreateCmd) Name() string {
|
||||
return "create"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd CreateCmd) Description() string {
|
||||
return "Creates or overwrite an existing table with an empty table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd CreateCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, tblCreateShortDesc, tblCreateLongDesc, tblCreateSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd CreateCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
//ap.ArgListHelp["field_descriptor"] = fieldDescriptorHelp
|
||||
ap.ArgListHelp["table"] = "name of the table being created."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "name of the table being created."})
|
||||
ap.SupportsFlag(forceParam, "f", "Force table creation if a table with this name already exists by overwriting it. ")
|
||||
ap.SupportsString(outSchemaParam, "s", "schema_file", "The schema the new table should be created with.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd CreateCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_CREATE
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd CreateCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, tblCreateShortDesc, tblCreateLongDesc, tblCreateSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -22,10 +22,12 @@ import (
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/mvdata"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
)
|
||||
|
||||
@@ -85,17 +87,7 @@ func validateExportArgs(apr *argparser.ArgParseResults, usage cli.UsagePrinter)
|
||||
return tableName, tableLoc, destLoc
|
||||
}
|
||||
|
||||
func parseExportArgs(commandStr string, args []string) (bool, *mvdata.MoveOptions) {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "The table being exported."
|
||||
ap.ArgListHelp["file"] = "The file being output to."
|
||||
ap.SupportsFlag(forceParam, "f", "If data already exists in the destination, the Force flag will allow the target to be overwritten.")
|
||||
ap.SupportsFlag(contOnErrParam, "", "Continue exporting when row export errors are encountered.")
|
||||
ap.SupportsString(outSchemaParam, "s", "schema_file", "The schema for the output data.")
|
||||
ap.SupportsString(mappingFileParam, "m", "mapping_file", "A file that lays out how fields should be mapped from input data to output data.")
|
||||
ap.SupportsString(primaryKeyParam, "pk", "primary_key", "Explicitly define the name of the field in the schema which should be used as the primary key.")
|
||||
ap.SupportsString(fileTypeParam, "", "file_type", "Explicitly define the type of the file if it can't be inferred from the file extension.")
|
||||
|
||||
func parseExportArgs(ap *argparser.ArgParser, commandStr string, args []string) (bool, *mvdata.MoveOptions) {
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, exportShortDesc, exportLongDesc, exportSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
tableName, tableLoc, fileLoc := validateExportArgs(apr, usage)
|
||||
@@ -120,8 +112,46 @@ func parseExportArgs(commandStr string, args []string) (bool, *mvdata.MoveOption
|
||||
}
|
||||
}
|
||||
|
||||
func Export(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
force, mvOpts := parseExportArgs(commandStr, args)
|
||||
type ExportCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ExportCmd) Name() string {
|
||||
return "export"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ExportCmd) Description() string {
|
||||
return "Export a table to a file."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ExportCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, exportShortDesc, exportLongDesc, exportSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ExportCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "The table being exported."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"file", "The file being output to."})
|
||||
ap.SupportsFlag(forceParam, "f", "If data already exists in the destination, the Force flag will allow the target to be overwritten.")
|
||||
ap.SupportsFlag(contOnErrParam, "", "Continue exporting when row export errors are encountered.")
|
||||
ap.SupportsString(outSchemaParam, "s", "schema_file", "The schema for the output data.")
|
||||
ap.SupportsString(mappingFileParam, "m", "mapping_file", "A file that lays out how fields should be mapped from input data to output data.")
|
||||
ap.SupportsString(primaryKeyParam, "pk", "primary_key", "Explicitly define the name of the field in the schema which should be used as the primary key.")
|
||||
ap.SupportsString(fileTypeParam, "", "file_type", "Explicitly define the type of the file if it can't be inferred from the file extension.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ExportCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_EXPORT
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ExportCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
force, mvOpts := parseExportArgs(ap, commandStr, args)
|
||||
|
||||
if mvOpts == nil {
|
||||
return 1
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/mvdata"
|
||||
@@ -31,6 +32,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/pipeline"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
@@ -51,27 +53,30 @@ const (
|
||||
)
|
||||
|
||||
var SchemaFileHelp = "Schema definition files are json files in the format:" + `
|
||||
{
|
||||
"<b>fields</b>": [
|
||||
{"name":"<b>FIELD_NAME</b>", "kind":"<b>KIND</b>", "Required":[true|false]},
|
||||
...
|
||||
],
|
||||
"<b>constraints</b>": [
|
||||
{"constraint_type":"primary_key", "field_indices":[<b>INTEGER_FIELD_INDEX</b>]}
|
||||
]
|
||||
}
|
||||
where "fields" is the array of columns in each row of the table
|
||||
"constraints" is a list of table constraints. (Only primary_key constraint types are supported currently)
|
||||
FIELD_NAME is the name of a column in a row and can be any valid string
|
||||
KIND must be a supported noms kind (bool, string, uuid, uint, int, float)
|
||||
INTEGER_FIELD_INDEX must be the 0 based index of the primary key in the "fields" array
|
||||
|
||||
{
|
||||
"fields": [
|
||||
{"name":"FIELD_NAME", "kind":"KIND", "Required":[true|false]},
|
||||
...
|
||||
],
|
||||
"constraints": [
|
||||
{"constraint_type":"primary_key", "field_indices":[INTEGER_FIELD_INDEX]}
|
||||
]
|
||||
}
|
||||
|
||||
where "fields" is the array of columns in each row of the table
|
||||
"constraints" is a list of table constraints. (Only primary_key constraint types are supported currently)
|
||||
FIELD_NAME is the name of a column in a row and can be any valid string
|
||||
KIND must be a supported noms kind (bool, string, uuid, uint, int, float)
|
||||
INTEGER_FIELD_INDEX must be the 0 based index of the primary key in the "fields" array
|
||||
`
|
||||
|
||||
var MappingFileHelp = "A mapping file is json in the format:" + `
|
||||
{
|
||||
"<b>source_field_name</b>":"<b>dest_field_name</b>"
|
||||
...
|
||||
}
|
||||
|
||||
{
|
||||
"source_field_name":"dest_field_name"
|
||||
...
|
||||
}
|
||||
|
||||
where source_field_name is the name of a field in the file being imported and dest_field_name is the name of a field in the table being imported to.
|
||||
`
|
||||
@@ -219,8 +224,38 @@ func validateImportArgs(apr *argparser.ArgParseResults, usage cli.UsagePrinter)
|
||||
return mvOp, tableLoc, srcLoc, srcOpts
|
||||
}
|
||||
|
||||
func Import(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
force, mvOpts := parseCreateArgs(commandStr, args)
|
||||
type ImportCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd ImportCmd) Name() string {
|
||||
return "import"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd ImportCmd) Description() string {
|
||||
return "Creates, overwrites, replaces, or updates a table from the data in a file."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd ImportCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, importShortDesc, importLongDesc, importSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd ImportCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := createArgParser()
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd ImportCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_IMPORT
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd ImportCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
force, mvOpts := parseCreateArgs(ap, commandStr, args)
|
||||
|
||||
if mvOpts == nil {
|
||||
return 1
|
||||
@@ -239,9 +274,7 @@ func Import(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
return res
|
||||
}
|
||||
|
||||
func parseCreateArgs(commandStr string, args []string) (bool, *mvdata.MoveOptions) {
|
||||
ap := createArgParser()
|
||||
|
||||
func parseCreateArgs(ap *argparser.ArgParser, commandStr string, args []string) (bool, *mvdata.MoveOptions) {
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, importShortDesc, importLongDesc, importSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
moveOp, tableLoc, fileLoc, srcOpts := validateImportArgs(apr, usage)
|
||||
@@ -268,8 +301,8 @@ func parseCreateArgs(commandStr string, args []string) (bool, *mvdata.MoveOption
|
||||
|
||||
func createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp[tableParam] = "The new or existing table being imported to."
|
||||
ap.ArgListHelp[fileParam] = "The file being imported. Supported file types are csv, psv, and nbf."
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{tableParam, "The new or existing table being imported to."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{fileParam, "The file being imported. Supported file types are csv, psv, and nbf."})
|
||||
ap.SupportsFlag(createParam, "c", "Create a new table, or overwrite an existing table (with the -f flag) from the imported data.")
|
||||
ap.SupportsFlag(updateParam, "u", "Update an existing table with the imported data.")
|
||||
ap.SupportsFlag(forceParam, "f", "If a create operation is being executed, data already exists in the destination, the Force flag will allow the target to be overwritten.")
|
||||
|
||||
@@ -17,6 +17,9 @@ package tblcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -39,11 +42,40 @@ var tblMvSynopsis = []string{
|
||||
"[-f] <oldtable> <newtable>",
|
||||
}
|
||||
|
||||
func Mv(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type MvCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd MvCmd) Name() string {
|
||||
return "mv"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd MvCmd) Description() string {
|
||||
return "Moves a table"
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd MvCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, tblMvShortDesc, tblMvLongDesc, tblMvSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd MvCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["oldtable"] = "The table being moved."
|
||||
ap.ArgListHelp["newtable"] = "The new name of the table"
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"oldtable", "The table being moved."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"newtable", "The new name of the table"})
|
||||
ap.SupportsFlag(forceParam, "f", "If data already exists in the destination, the Force flag will allow the target to be overwritten.")
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd MvCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_MV
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd MvCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, tblMvShortDesc, tblMvLongDesc, tblMvSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
|
||||
@@ -30,6 +31,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -49,11 +51,7 @@ type putRowArgs struct {
|
||||
TableName string
|
||||
}
|
||||
|
||||
func parsePutRowArgs(commandStr string, args []string) *putRowArgs {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "The table being inserted into"
|
||||
ap.ArgListHelp["field_name:field_value"] = "There should be a <field_name>:<field_value> pair for each field " +
|
||||
"that you want set on this row. If all required fields are not set, then this command will fail."
|
||||
func parsePutRowArgs(ap *argparser.ArgParser, commandStr string, args []string) *putRowArgs {
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, putRowShortDesc, putRowLongDesc, putRowSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -103,8 +101,43 @@ func parseKVPs(args []string) ([]string, map[string]string, errhand.VerboseError
|
||||
return fieldNames, kvps, nil
|
||||
}
|
||||
|
||||
func PutRow(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
prArgs := parsePutRowArgs(commandStr, args)
|
||||
type PutRowCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd PutRowCmd) Name() string {
|
||||
return "put-row"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd PutRowCmd) Description() string {
|
||||
return "Add a row to a table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd PutRowCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, putRowShortDesc, putRowLongDesc, putRowSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd PutRowCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "The table being inserted into"})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{
|
||||
"field_name:field_value",
|
||||
"There should be a <field_name>:<field_value> pair for each field that you want set on this row. If all " +
|
||||
"required fields are not set, then this command will fail."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd PutRowCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_PUT_ROW
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd PutRowCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
prArgs := parsePutRowArgs(ap, commandStr, args)
|
||||
|
||||
if prArgs == nil {
|
||||
return 1
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestPutRow(t *testing.T) {
|
||||
dEnv := createEnvWithSeedData(t)
|
||||
|
||||
commandStr := "dolt table put-row"
|
||||
result := PutRow(context.TODO(), commandStr, test.args, dEnv)
|
||||
result := PutRowCmd{}.Exec(context.TODO(), commandStr, test.args, dEnv)
|
||||
|
||||
if result != test.expectedRes {
|
||||
commandLine := commandStr + " " + strings.Join(test.args, " ")
|
||||
|
||||
@@ -17,6 +17,9 @@ package tblcmds
|
||||
import (
|
||||
"context"
|
||||
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
@@ -32,9 +35,38 @@ var tblRmSynopsis = []string{
|
||||
"<table>...",
|
||||
}
|
||||
|
||||
func Rm(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type RmCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd RmCmd) Name() string {
|
||||
return "rm"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd RmCmd) Description() string {
|
||||
return "Deletes a table"
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd RmCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_RM
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd RmCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, tblRmShortDesc, tblRmLongDesc, tblRmSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd RmCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "The table to remove"
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "The table to remove"})
|
||||
return ap
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd RmCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, tblRmShortDesc, tblRmLongDesc, tblRmSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
|
||||
@@ -22,9 +22,11 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
|
||||
@@ -39,10 +41,7 @@ type rmRowArgs struct {
|
||||
PKs []string
|
||||
}
|
||||
|
||||
func parseRmRowArgs(commandStr string, args []string) *rmRowArgs {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "The table being edited."
|
||||
ap.ArgListHelp["primary_key"] = "Primary key of the row(s) to delete."
|
||||
func parseRmRowArgs(ap *argparser.ArgParser, commandStr string, args []string) *rmRowArgs {
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, rmRowShortDesc, rmRowLongDesc, rmRowSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
@@ -61,8 +60,40 @@ func parseRmRowArgs(commandStr string, args []string) *rmRowArgs {
|
||||
return &rmRowArgs{tableName, pks}
|
||||
}
|
||||
|
||||
func RmRow(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
rmArgs := parseRmRowArgs(commandStr, args)
|
||||
type RmRowCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd RmRowCmd) Name() string {
|
||||
return "rm-row"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd RmRowCmd) Description() string {
|
||||
return "Remove a row from a table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd RmRowCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := cmd.createArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, rmRowShortDesc, rmRowLongDesc, rmRowSynopsis, ap)
|
||||
}
|
||||
|
||||
func (cmd RmRowCmd) createArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "The table being edited."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"primary_key", "Primary key of the row(s) to delete."})
|
||||
return ap
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd RmRowCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_RM_ROW
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd RmRowCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := cmd.createArgParser()
|
||||
rmArgs := parseRmRowArgs(ap, commandStr, args)
|
||||
|
||||
if rmArgs == nil {
|
||||
return 1
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
|
||||
@@ -35,6 +36,7 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/nullprinter"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/tabular"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/iohelp"
|
||||
"github.com/liquidata-inc/dolt/go/store/types"
|
||||
)
|
||||
@@ -65,7 +67,31 @@ type SelectArgs struct {
|
||||
hideConflicts bool
|
||||
}
|
||||
|
||||
func Select(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
type SelectCmd struct{}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd SelectCmd) Name() string {
|
||||
return "select"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd SelectCmd) Description() string {
|
||||
return "Print a selection of a table."
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd SelectCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
ap := newArgParser()
|
||||
return cli.CreateMarkdown(fs, path, commandStr, selShortDesc, selLongDesc, selSynopsis, ap)
|
||||
}
|
||||
|
||||
// EventType returns the type of the event to log
|
||||
func (cmd SelectCmd) EventType() eventsapi.ClientEventType {
|
||||
return eventsapi.ClientEventType_TABLE_SELECT
|
||||
}
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd SelectCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
ap := newArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(commandStr, selShortDesc, selLongDesc, selSynopsis, ap)
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
@@ -133,8 +159,8 @@ func Select(ctx context.Context, commandStr string, args []string, dEnv *env.Dol
|
||||
|
||||
func newArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParser()
|
||||
ap.ArgListHelp["table"] = "List of tables to be printed."
|
||||
ap.ArgListHelp["column"] = "List of columns to be printed"
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "List of tables to be printed."})
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"column", "List of columns to be printed"})
|
||||
ap.SupportsString(whereParam, "", "column", "")
|
||||
ap.SupportsInt(limitParam, "", "record_count", "")
|
||||
ap.SupportsFlag(hideConflictsFlag, "", "")
|
||||
|
||||
@@ -16,17 +16,16 @@ package tblcmds
|
||||
|
||||
import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
)
|
||||
|
||||
var Commands = cli.GenSubCommandHandler([]*cli.Command{
|
||||
{Name: "import", Desc: "Creates, overwrites, replaces, or updates a table from the data in a file.", Func: Import, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_IMPORT},
|
||||
{Name: "export", Desc: "Export a table to a file.", Func: Export, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_EXPORT},
|
||||
{Name: "create", Desc: "Creates or overwrite an existing table with an empty table.", Func: Create, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_CREATE},
|
||||
{Name: "rm", Desc: "Deletes a table", Func: Rm, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_RM},
|
||||
{Name: "mv", Desc: "Moves a table", Func: Mv, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_MV},
|
||||
{Name: "cp", Desc: "Copies a table", Func: Cp, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_CP},
|
||||
{Name: "select", Desc: "Print a selection of a table.", Func: Select, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_SELECT},
|
||||
{Name: "put-row", Desc: "Add a row to a table.", Func: PutRow, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_PUT_ROW},
|
||||
{Name: "rm-row", Desc: "Remove a row from a table.", Func: RmRow, ReqRepo: true, EventType: eventsapi.ClientEventType_TABLE_RM_ROW},
|
||||
var Commands = cli.NewSubCommandHandler("table", "Commands for creating, reading, updating, and deleting tables.", []cli.Command{
|
||||
ImportCmd{},
|
||||
ExportCmd{},
|
||||
CreateCmd{},
|
||||
RmCmd{},
|
||||
MvCmd{},
|
||||
CpCmd{},
|
||||
SelectCmd{},
|
||||
PutRowCmd{},
|
||||
RmRowCmd{},
|
||||
})
|
||||
|
||||
@@ -17,15 +17,41 @@ package commands
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
)
|
||||
|
||||
// Version displays the version of the running dolt client
|
||||
func Version(version string) cli.CommandFunc {
|
||||
return func(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
cli.Println("dolt version", version)
|
||||
|
||||
return 0
|
||||
}
|
||||
type VersionCmd struct {
|
||||
VersionStr string
|
||||
}
|
||||
|
||||
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
|
||||
func (cmd VersionCmd) Name() string {
|
||||
return "version"
|
||||
}
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd VersionCmd) Description() string {
|
||||
return "Displays the current Dolt cli version."
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
// that it be run from within a data repository directory
|
||||
func (cmd VersionCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
|
||||
func (cmd VersionCmd) CreateMarkdown(fs filesys.Filesys, path, commandStr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Version displays the version of the running dolt client
|
||||
// Exec executes the command
|
||||
func (cmd VersionCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int {
|
||||
cli.Println("dolt version", cmd.VersionStr)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands/schcmds"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands/sqlserver"
|
||||
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands/tblcmds"
|
||||
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
@@ -43,36 +42,42 @@ const (
|
||||
Version = "0.12.0"
|
||||
)
|
||||
|
||||
var doltCommand = cli.GenSubCommandHandler([]*cli.Command{
|
||||
{Name: "init", Desc: "Create an empty Dolt data repository.", Func: commands.Init, ReqRepo: false, EventType: eventsapi.ClientEventType_INIT},
|
||||
{Name: "status", Desc: "Show the working tree status.", Func: commands.Status, ReqRepo: true, EventType: eventsapi.ClientEventType_STATUS},
|
||||
{Name: "add", Desc: "Add table changes to the list of staged table changes.", Func: commands.Add, ReqRepo: true, EventType: eventsapi.ClientEventType_ADD},
|
||||
{Name: "reset", Desc: "Remove table changes from the list of staged table changes.", Func: commands.Reset, ReqRepo: true, EventType: eventsapi.ClientEventType_RESET},
|
||||
{Name: "commit", Desc: "Record changes to the repository.", Func: commands.Commit, ReqRepo: true, EventType: eventsapi.ClientEventType_COMMIT},
|
||||
{Name: "sql", Desc: "Run a SQL query against tables in repository.", Func: commands.Sql, ReqRepo: true, EventType: eventsapi.ClientEventType_SQL},
|
||||
{Name: "sql-server", Desc: "Starts a MySQL-compatible server.", Func: sqlserver.SqlServer, ReqRepo: true, EventType: eventsapi.ClientEventType_SQL_SERVER},
|
||||
{Name: "log", Desc: "Show commit logs.", Func: commands.Log, ReqRepo: true, EventType: eventsapi.ClientEventType_LOG},
|
||||
{Name: "diff", Desc: "Diff a table.", Func: commands.Diff, ReqRepo: true, EventType: eventsapi.ClientEventType_DIFF},
|
||||
{Name: "blame", Desc: "Show what revision and author last modified each row of a table.", Func: commands.Blame, ReqRepo: true, EventType: eventsapi.ClientEventType_BLAME},
|
||||
{Name: "merge", Desc: "Merge a branch.", Func: commands.Merge, ReqRepo: true, EventType: eventsapi.ClientEventType_MERGE},
|
||||
{Name: "branch", Desc: "Create, list, edit, delete branches.", Func: commands.Branch, ReqRepo: true, EventType: eventsapi.ClientEventType_BRANCH},
|
||||
{Name: "checkout", Desc: "Checkout a branch or overwrite a table from HEAD.", Func: commands.Checkout, ReqRepo: true, EventType: eventsapi.ClientEventType_CHECKOUT},
|
||||
{Name: "remote", Desc: "Manage set of tracked repositories.", Func: commands.Remote, ReqRepo: true, EventType: eventsapi.ClientEventType_REMOTE},
|
||||
{Name: "push", Desc: "Push to a dolt remote.", Func: commands.Push, ReqRepo: true, EventType: eventsapi.ClientEventType_PUSH},
|
||||
{Name: "pull", Desc: "Fetch from a dolt remote data repository and merge.", Func: commands.Pull, ReqRepo: true, EventType: eventsapi.ClientEventType_PULL},
|
||||
{Name: "fetch", Desc: "Update the database from a remote data repository.", Func: commands.Fetch, ReqRepo: true, EventType: eventsapi.ClientEventType_FETCH},
|
||||
{Name: "clone", Desc: "Clone from a remote data repository.", Func: commands.Clone, ReqRepo: false, EventType: eventsapi.ClientEventType_CLONE},
|
||||
{Name: "creds", Desc: "Commands for managing credentials.", Func: credcmds.Commands, ReqRepo: false},
|
||||
{Name: "login", Desc: "Login to a dolt remote host.", Func: commands.Login, ReqRepo: false, EventType: eventsapi.ClientEventType_LOGIN},
|
||||
{Name: "version", Desc: "Displays the current Dolt cli version.", Func: commands.Version(Version), ReqRepo: false, EventType: eventsapi.ClientEventType_VERSION},
|
||||
{Name: "config", Desc: "Dolt configuration.", Func: commands.Config, ReqRepo: false},
|
||||
{Name: "ls", Desc: "List tables in the working set.", Func: commands.Ls, ReqRepo: true, EventType: eventsapi.ClientEventType_LS},
|
||||
{Name: "schema", Desc: "Commands for showing, and modifying table schemas.", Func: schcmds.Commands, ReqRepo: true, EventType: eventsapi.ClientEventType_SCHEMA},
|
||||
{Name: "table", Desc: "Commands for creating, reading, updating, and deleting tables.", Func: tblcmds.Commands, ReqRepo: false},
|
||||
{Name: "conflicts", Desc: "Commands for viewing and resolving merge conflicts.", Func: cnfcmds.Commands, ReqRepo: false},
|
||||
{Name: commands.SendMetricsCommand, Desc: "Send events logs to server.", Func: commands.SendMetrics, ReqRepo: false, HideFromHelp: true},
|
||||
var dumpDocsCommand = &commands.DumpDocsCmd{}
|
||||
var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Command{
|
||||
commands.InitCmd{},
|
||||
commands.StatusCmd{},
|
||||
commands.AddCmd{},
|
||||
commands.ResetCmd{},
|
||||
commands.CommitCmd{},
|
||||
commands.SqlCmd{},
|
||||
sqlserver.SqlServerCmd{},
|
||||
commands.LogCmd{},
|
||||
commands.DiffCmd{},
|
||||
commands.BlameCmd{},
|
||||
commands.MergeCmd{},
|
||||
commands.BranchCmd{},
|
||||
commands.CheckoutCmd{},
|
||||
commands.RemoteCmd{},
|
||||
commands.PushCmd{},
|
||||
commands.PullCmd{},
|
||||
commands.FetchCmd{},
|
||||
commands.CloneCmd{},
|
||||
credcmds.Commands,
|
||||
commands.LoginCmd{},
|
||||
commands.VersionCmd{},
|
||||
commands.ConfigCmd{},
|
||||
commands.LsCmd{},
|
||||
schcmds.Commands,
|
||||
tblcmds.Commands,
|
||||
cnfcmds.Commands,
|
||||
commands.SendMetricsCmd{},
|
||||
dumpDocsCommand,
|
||||
})
|
||||
|
||||
func init() {
|
||||
dumpDocsCommand.DoltCommand = doltCommand
|
||||
}
|
||||
|
||||
const chdirFlag = "--chdir"
|
||||
const profFlag = "--prof"
|
||||
const cpuProf = "cpu"
|
||||
@@ -173,16 +178,16 @@ func runMain() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
return doltCommand(context.Background(), "dolt", args, dEnv)
|
||||
return doltCommand.Exec(context.Background(), "dolt", args, dEnv)
|
||||
}
|
||||
|
||||
// processEventsDir runs the dolt send-metrics command in a new process
|
||||
func processEventsDir(args []string, dEnv *env.DoltEnv) error {
|
||||
if len(args) > 0 {
|
||||
ignoreCommands := map[string]struct{}{
|
||||
commands.SendMetricsCommand: struct{}{},
|
||||
"init": struct{}{},
|
||||
"config": struct{}{},
|
||||
commands.SendMetricsCommand: {},
|
||||
"init": {},
|
||||
"config": {},
|
||||
}
|
||||
|
||||
_, ok := ignoreCommands[args[0]]
|
||||
|
||||
@@ -47,14 +47,13 @@ func ValidatorFromStrList(paramName string, validStrList []string) ValidationFun
|
||||
type ArgParser struct {
|
||||
Supported []*Option
|
||||
NameOrAbbrevToOpt map[string]*Option
|
||||
ArgListHelp map[string]string
|
||||
ArgListHelp [][2]string
|
||||
}
|
||||
|
||||
func NewArgParser() *ArgParser {
|
||||
var supported []*Option
|
||||
nameOrAbbrevToOpt := make(map[string]*Option)
|
||||
argListHelp := make(map[string]string)
|
||||
return &ArgParser{supported, nameOrAbbrevToOpt, argListHelp}
|
||||
return &ArgParser{supported, nameOrAbbrevToOpt, nil}
|
||||
}
|
||||
|
||||
// Adds support for a new argument with the option given. Options must have a unique name and abbreviated name.
|
||||
|
||||
@@ -133,7 +133,7 @@ func doltExport(b *testing.B, fs filesys.Filesys, rows int, cols []*SeedColumn,
|
||||
os.Stdin = oldStdin
|
||||
|
||||
args = []string{"-f", "testTable", pathToImportFile}
|
||||
runBenchmark(b, tblcmds.Export, "dolt table export", args, dEnv)
|
||||
runBenchmark(b, tblcmds.ExportCmd{}.Exec, "dolt table export", args, dEnv)
|
||||
}
|
||||
|
||||
func doltSQLSelect(b *testing.B, fs filesys.Filesys, rows int, cols []*SeedColumn, workingDir, format string) {
|
||||
@@ -154,7 +154,7 @@ func doltSQLSelect(b *testing.B, fs filesys.Filesys, rows int, cols []*SeedColum
|
||||
os.Stdin = oldStdin
|
||||
|
||||
args = []string{"-q", fmt.Sprintf("select count(*) from %s", testTable)}
|
||||
runBenchmark(b, commands.Sql, "dolt sql", args, dEnv)
|
||||
runBenchmark(b, commands.SqlCmd{}.Exec, "dolt sql", args, dEnv)
|
||||
}
|
||||
|
||||
func runBenchmark(b *testing.B, commandFunc doltCommandFunc, commandStr string, args []string, dEnv *env.DoltEnv) {
|
||||
@@ -176,12 +176,12 @@ func getBenchmarkingTools(fs filesys.Filesys, rows int, cols []*SeedColumn, work
|
||||
dEnv = setupDEnvImport(fs, sch, workingDir, testTable, "", pathToImportFile)
|
||||
args = []string{"-c", "-f", testTable, pathToImportFile}
|
||||
commandStr = "dolt table import"
|
||||
commandFunc = tblcmds.Import
|
||||
commandFunc = tblcmds.ImportCmd{}.Exec
|
||||
case sqlExt:
|
||||
dEnv = setupDEnvImport(fs, sch, workingDir, testTable, "", pathToImportFile)
|
||||
args = []string{}
|
||||
commandStr = "dolt sql"
|
||||
commandFunc = commands.Sql
|
||||
commandFunc = commands.SqlCmd{}.Exec
|
||||
|
||||
stdin := getStdinForSQLBenchmark(fs, pathToImportFile)
|
||||
os.Stdin = stdin
|
||||
@@ -190,7 +190,7 @@ func getBenchmarkingTools(fs filesys.Filesys, rows int, cols []*SeedColumn, work
|
||||
dEnv = setupDEnvImport(fs, sch, workingDir, testTable, pathToSchemaFile, pathToImportFile)
|
||||
args = []string{"-c", "-f", "-s", pathToSchemaFile, testTable, pathToImportFile}
|
||||
commandStr = "dolt table import"
|
||||
commandFunc = tblcmds.Import
|
||||
commandFunc = tblcmds.ImportCmd{}.Exec
|
||||
default:
|
||||
log.Fatalf("cannot import file, unsupported file format %s \n", format)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user