Skip to content

Commit

Permalink
Merge pull request #8739 from milogreg/dolt-help-table
Browse files Browse the repository at this point in the history
Create dolt_help system table
  • Loading branch information
zachmu authored Jan 21, 2025
2 parents ef64778 + 9892a48 commit 97f8fed
Show file tree
Hide file tree
Showing 13 changed files with 648 additions and 82 deletions.
3 changes: 3 additions & 0 deletions go/cmd/dolt/cli/documentation_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ var CliFormat = docFormat{"<", ">", "<b>", "</b>"}
// Synopsis is an mdx format, but already inside a code block
var SynopsisMarkdownFormat = docFormat{"<", ">", "`", "`"}

// Format that deletes all template options
var EmptyFormat = docFormat{"", "", "", ""}

func transformSynopsisToMarkdown(commandStr string, synopsis []string) string {
if len(synopsis) == 0 {
return ""
Expand Down
50 changes: 32 additions & 18 deletions go/cmd/dolt/cli/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,35 @@ func terminalSize() (width, height int) {
func OptionsUsage(ap *argparser.ArgParser, indent string, lineLen int) string {
var lines []string

for _, kvTuple := range ap.ArgListHelp {
k, v := kvTuple[0], kvTuple[1]
lines = append(lines, "<"+k+">")
l, err := templateDocStringHelper(v, CliFormat)
if err != nil {
panic(err)
}
l = embolden(l)
descLines := toParagraphLines(l, lineLen)
for _, usage := range OptionsUsageList(ap, CliFormat) {
name, description := usage[0], usage[1]

lines = append(lines, name)

descLines := toParagraphLines(description, lineLen)
descLines = indentLines(descLines, " ")
descLines = append(descLines, "")

lines = append(lines, descLines...)
}

lines = indentLines(lines, indent)
return strings.Join(lines, "\n")
}

// OptionsUsageList returns a pair of strings for each option/argument in |ap|, where the first string
// is the name of the option/argument and the second string is the description of the option/argument.
func OptionsUsageList(ap *argparser.ArgParser, docFormat docFormat) [][2]string {
res := [][2]string{}

for _, help := range ap.ArgListHelp {
name, description := help[0], help[1]

nameFormatted := "<" + name + ">"

res = append(res, [2]string{nameFormatted, description})
}

for _, supOpt := range ap.Supported {
argHelpFmt := "--%[2]s"

Expand All @@ -192,22 +206,22 @@ func OptionsUsage(ap *argparser.ArgParser, indent string, lineLen int) string {
argHelpFmt = "--%[2]s=<%[3]s>"
}

lines = append(lines, fmt.Sprintf(argHelpFmt, supOpt.Abbrev, supOpt.Name, supOpt.ValDesc))
nameFormatted := fmt.Sprintf(argHelpFmt, supOpt.Abbrev, supOpt.Name, supOpt.ValDesc)

l, err := templateDocStringHelper(supOpt.Desc, CliFormat)
res = append(res, [2]string{nameFormatted, supOpt.Desc})
}

for i := range res {
descriptionFormatted, err := templateDocStringHelper(res[i][1], docFormat)
if err != nil {
panic(err)
}
l = embolden(l)
descLines := toParagraphLines(l, lineLen)
descLines = indentLines(descLines, " ")
descLines = append(descLines, "")
descriptionFormatted = embolden(descriptionFormatted)

lines = append(lines, descLines...)
res[i][1] = descriptionFormatted
}

lines = indentLines(lines, indent)
return strings.Join(lines, "\n")
return res
}

func ToIndentedParagraph(inStr, indent string, lineLen int) string {
Expand Down
68 changes: 5 additions & 63 deletions go/cmd/dolt/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ import (
"github.com/dolthub/dolt/go/cmd/dolt/commands"
"github.com/dolthub/dolt/go/cmd/dolt/commands/admin"
"github.com/dolthub/dolt/go/cmd/dolt/commands/ci"
"github.com/dolthub/dolt/go/cmd/dolt/commands/cnfcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/credcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/cvcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/docscmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/indexcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/schcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/sqlserver"
"github.com/dolthub/dolt/go/cmd/dolt/commands/stashcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/tblcmds"
"github.com/dolthub/dolt/go/cmd/dolt/doltcmd"
"github.com/dolthub/dolt/go/cmd/dolt/doltversion"
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
"github.com/dolthub/dolt/go/libraries/doltcore/dconfig"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
"github.com/dolthub/dolt/go/libraries/events"
"github.com/dolthub/dolt/go/libraries/utils/argparser"
"github.com/dolthub/dolt/go/libraries/utils/config"
Expand All @@ -71,65 +70,6 @@ import (
var dumpDocsCommand = &commands.DumpDocsCmd{}
var dumpZshCommand = &commands.GenZshCompCmd{}

var doltSubCommands = []cli.Command{
commands.InitCmd{},
commands.StatusCmd{},
commands.AddCmd{},
commands.DiffCmd{},
commands.ResetCmd{},
commands.CleanCmd{},
commands.CommitCmd{},
commands.SqlCmd{VersionStr: doltversion.Version},
admin.Commands,
sqlserver.SqlServerCmd{VersionStr: doltversion.Version},
commands.LogCmd{},
commands.ShowCmd{},
commands.BranchCmd{},
commands.CheckoutCmd{},
commands.MergeCmd{},
cnfcmds.Commands,
commands.CherryPickCmd{},
commands.RevertCmd{},
commands.CloneCmd{},
commands.FetchCmd{},
commands.PullCmd{},
commands.PushCmd{},
commands.ConfigCmd{},
commands.RemoteCmd{},
commands.BackupCmd{},
commands.LoginCmd{},
credcmds.Commands,
commands.LsCmd{},
schcmds.Commands,
tblcmds.Commands,
commands.TagCmd{},
commands.BlameCmd{},
cvcmds.Commands,
commands.SendMetricsCmd{},
commands.MigrateCmd{},
indexcmds.Commands,
commands.ReadTablesCmd{},
commands.GarbageCollectionCmd{},
commands.FsckCmd{},
commands.FilterBranchCmd{},
commands.MergeBaseCmd{},
commands.RootsCmd{},
commands.VersionCmd{VersionStr: doltversion.Version},
commands.DumpCmd{},
commands.InspectCmd{},
dumpDocsCommand,
dumpZshCommand,
docscmds.Commands,
stashcmds.StashCommands,
&commands.Assist{},
commands.ProfileCmd{},
commands.QueryDiff{},
commands.ReflogCmd{},
commands.RebaseCmd{},
commands.ArchiveCmd{},
ci.Commands,
}

var commandsWithoutCliCtx = []cli.Command{
admin.Commands,
commands.CloneCmd{},
Expand Down Expand Up @@ -204,7 +144,7 @@ func needsWriteAccess(commandName string) bool {
return true
}

var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", doltSubCommands)
var doltCommand = doltcmd.DoltCommand
var globalArgParser = cli.CreateGlobalArgParser("dolt")
var globalDocs = cli.CommandDocsForCommandString("dolt", doc, globalArgParser)

Expand All @@ -226,6 +166,8 @@ func init() {
if _, ok := os.LookupEnv(disableEventFlushEnvVar); ok {
eventFlushDisabled = true
}

dtables.DoltCommand = doltCommand
}

const pprofServerFlag = "--pprof-server"
Expand Down
120 changes: 120 additions & 0 deletions go/cmd/dolt/doltcmd/doltcmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright 2025 Dolthub, 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 doltcmd

import (
"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/commands"
"github.com/dolthub/dolt/go/cmd/dolt/commands/admin"
"github.com/dolthub/dolt/go/cmd/dolt/commands/ci"
"github.com/dolthub/dolt/go/cmd/dolt/commands/cnfcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/credcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/cvcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/docscmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/indexcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/schcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/sqlserver"
"github.com/dolthub/dolt/go/cmd/dolt/commands/stashcmds"
"github.com/dolthub/dolt/go/cmd/dolt/commands/tblcmds"
"github.com/dolthub/dolt/go/cmd/dolt/doltversion"
)

var dumpDocsCommand = &commands.DumpDocsCmd{}
var dumpZshCommand = &commands.GenZshCompCmd{}

var doltSubCommands = []cli.Command{
commands.InitCmd{},
commands.StatusCmd{},
commands.AddCmd{},
commands.DiffCmd{},
commands.ResetCmd{},
commands.CleanCmd{},
commands.CommitCmd{},
commands.SqlCmd{VersionStr: doltversion.Version},
admin.Commands,
sqlserver.SqlServerCmd{VersionStr: doltversion.Version},
commands.LogCmd{},
commands.ShowCmd{},
commands.BranchCmd{},
commands.CheckoutCmd{},
commands.MergeCmd{},
cnfcmds.Commands,
commands.CherryPickCmd{},
commands.RevertCmd{},
commands.CloneCmd{},
commands.FetchCmd{},
commands.PullCmd{},
commands.PushCmd{},
commands.ConfigCmd{},
commands.RemoteCmd{},
commands.BackupCmd{},
commands.LoginCmd{},
credcmds.Commands,
commands.LsCmd{},
schcmds.Commands,
tblcmds.Commands,
commands.TagCmd{},
commands.BlameCmd{},
cvcmds.Commands,
commands.SendMetricsCmd{},
commands.MigrateCmd{},
indexcmds.Commands,
commands.ReadTablesCmd{},
commands.GarbageCollectionCmd{},
commands.FsckCmd{},
commands.FilterBranchCmd{},
commands.MergeBaseCmd{},
commands.RootsCmd{},
commands.VersionCmd{VersionStr: doltversion.Version},
commands.DumpCmd{},
commands.InspectCmd{},
dumpDocsCommand,
dumpZshCommand,
docscmds.Commands,
stashcmds.StashCommands,
&commands.Assist{},
commands.ProfileCmd{},
commands.QueryDiff{},
commands.ReflogCmd{},
commands.RebaseCmd{},
commands.ArchiveCmd{},
ci.Commands,
}

var DoltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", doltSubCommands)

var globalArgParser = cli.CreateGlobalArgParser("dolt")

var doc = cli.CommandDocumentationContent{
ShortDesc: "Dolt is git for data",
LongDesc: `Dolt comprises of multiple subcommands that allow users to import, export, update, and manipulate data with SQL.`,

Synopsis: []string{
"[global flags] subcommand [subcommand arguments]",
},
}
var globalDocs = cli.CommandDocsForCommandString("dolt", doc, globalArgParser)

var globalSpecialMsg = `
Dolt subcommands are in transition to using the flags listed below as global flags.
Not all subcommands use these flags. If your command accepts these flags without error, then they are supported.
`

func init() {
dumpDocsCommand.DoltCommand = DoltCommand
dumpDocsCommand.GlobalDocs = globalDocs
dumpDocsCommand.GlobalSpecialMsg = globalSpecialMsg
dumpZshCommand.DoltCommand = DoltCommand
}
10 changes: 10 additions & 0 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var getGeneratedSystemTables = func() []string {
GetCommitAncestorsTableName(),
GetStatusTableName(),
GetRemotesTableName(),
GetHelpTableName(),
}
}

Expand Down Expand Up @@ -380,6 +381,11 @@ var GetTagsTableName = func() string {
return TagsTableName
}

// GetHelpTableName returns the help table name
var GetHelpTableName = func() string {
return HelpTableName
}

const (
// LogTableName is the log system table name
LogTableName = "dolt_log"
Expand Down Expand Up @@ -585,3 +591,7 @@ const (
// was originally defined. Mode settings, such as ANSI_QUOTES, are needed to correctly parse the fragment.
ProceduresTableSqlModeCol = "sql_mode"
)

const (
HelpTableName = "dolt_help"
)
8 changes: 8 additions & 0 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
return nil, false, err
}
dt = NewSchemaTable(backingTable)
case doltdb.GetHelpTableName(), doltdb.HelpTableName:
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewHelpTable(ctx, db.Name(), lwrName), true
}
}

if found {
Expand Down
Loading

0 comments on commit 97f8fed

Please sign in to comment.