mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-10 08:49:43 -06:00
Merge pull request #6362 from dolthub/steph/cli-warnings
add warning message for unmigrated cli commands
This commit is contained in:
@@ -266,16 +266,6 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
|
||||
func sqlHandleVErrAndExitCode(queryist cli.Queryist, verr errhand.VerboseError, usage cli.UsagePrinter) int {
|
||||
if verr != nil {
|
||||
if msg := verr.Verbose(); strings.TrimSpace(msg) != "" {
|
||||
if _, ok := queryist.(*engine.SqlEngine); !ok {
|
||||
// We are in a context where we are attempting to connect to a remote database. These errors
|
||||
// are unstructured, so we add some additional context around them.
|
||||
tmpMsg := `You've encountered a new behavior in dolt which is not fully documented yet.
|
||||
A local dolt server is using your dolt data directory, and in an attempt to service your request, we are attempting to
|
||||
connect to it. That has failed. You should stop the server, or reach out to @macneale on https://discord.gg/gqr7K4VNKe
|
||||
for help.`
|
||||
cli.PrintErrln(tmpMsg)
|
||||
msg = fmt.Sprintf("A local server is running, and dolt is failing to connect. Error connecting to remote database: \"%s\".\n", msg)
|
||||
}
|
||||
cli.PrintErrln(msg)
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,20 @@ var commandsWithoutCliCtx = []cli.Command{
|
||||
&commands.Assist{},
|
||||
}
|
||||
|
||||
var commandsWithoutGlobalArgSupport = []cli.Command{
|
||||
commands.InitCmd{},
|
||||
commands.CloneCmd{},
|
||||
docscmds.Commands,
|
||||
commands.MigrateCmd{},
|
||||
commands.ReadTablesCmd{},
|
||||
commands.LoginCmd{},
|
||||
credcmds.Commands,
|
||||
sqlserver.SqlServerCmd{VersionStr: Version},
|
||||
sqlserver.SqlClientCmd{VersionStr: Version},
|
||||
commands.VersionCmd{VersionStr: Version},
|
||||
commands.ConfigCmd{},
|
||||
}
|
||||
|
||||
func initCliContext(commandName string) bool {
|
||||
for _, command := range commandsWithoutCliCtx {
|
||||
if command.Name() == commandName {
|
||||
@@ -161,6 +175,15 @@ func initCliContext(commandName string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func supportsGlobalArgs(commandName string) bool {
|
||||
for _, command := range commandsWithoutGlobalArgSupport {
|
||||
if command.Name() == commandName {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", doltSubCommands)
|
||||
var globalArgParser = buildGlobalArgs()
|
||||
var globalDocs = cli.CommandDocsForCommandString("dolt", doc, globalArgParser)
|
||||
@@ -536,6 +559,19 @@ func runMain() int {
|
||||
cli.PrintErrln(color.RedString("Unexpected Error: %v", err))
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
if args[0] != subcommandName {
|
||||
if supportsGlobalArgs(subcommandName) {
|
||||
cli.PrintErrln(
|
||||
`Global arguments are not supported for this command as it has not yet been migrated to function in a remote context.
|
||||
If you're interested in running this command against a remote host, hit us up on discord (https://discord.gg/gqr7K4VNKe).`)
|
||||
} else {
|
||||
cli.PrintErrln(
|
||||
`This command does not support global arguments. Please try again without the global arguments
|
||||
or check the docs for questions about usage.`)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
ctx, stop := context.WithCancel(ctx)
|
||||
|
||||
@@ -358,10 +358,10 @@ NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository."
|
||||
}
|
||||
|
||||
@test "no-repo: check that we correctly parse args when connecting with a username that matches a subcommand" {
|
||||
run dolt --user ls version
|
||||
run dolt --user ls sql -q "select 1"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "version" ]] || false
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
}
|
||||
|
||||
@test "no-repo: check that we error on commands with no subcommand" {
|
||||
|
||||
@@ -1087,3 +1087,19 @@ SQL
|
||||
|
||||
[[ $output =~ "dolt checkout can not currently be used when there is a local server running. Please stop your dolt sql-server and try again." ]] || false
|
||||
}
|
||||
|
||||
@test "sql-local-remote: verify unmigrated command will fail with warning" {
|
||||
cd altDB
|
||||
start_sql_server altDB
|
||||
run dolt --user dolt log
|
||||
[ $status -eq 1 ]
|
||||
[[ "$output" =~ "Global arguments are not supported for this command" ]]
|
||||
}
|
||||
|
||||
@test "sql-local-remote: verify commands without global arg support will fail with warning" {
|
||||
cd altDB
|
||||
start_sql_server altDB
|
||||
run dolt --user dolt version
|
||||
[ $status -eq 1 ]
|
||||
[[ "$output" =~ "This command does not support global arguments." ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user