mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-10 18:49:02 -06:00
Fix md docs dump format. Fixed a problem in formatting of reset docs. Tweaked command order.
This commit is contained in:
@@ -25,25 +25,20 @@ import (
|
||||
|
||||
type commandDocumentForMarkdown struct {
|
||||
Command string
|
||||
CommandAndShortDesc string
|
||||
ShortDesc string
|
||||
Synopsis string
|
||||
Description string
|
||||
Options string
|
||||
}
|
||||
|
||||
var cmdMdDocTempl = `## Command
|
||||
{{.CommandAndShortDesc}}
|
||||
|
||||
### Synopsis
|
||||
{{.Synopsis}}
|
||||
|
||||
### Description
|
||||
{{.Description}}
|
||||
|
||||
### Options
|
||||
{{.Options}}
|
||||
|
||||
`
|
||||
var cmdMdDocTempl = "## `{{.Command}}`\n\n" +
|
||||
"{{.ShortDesc}}\n\n" +
|
||||
"### Synopsis\n\n" +
|
||||
"{{.Synopsis}}\n\n" +
|
||||
"### Description\n\n" +
|
||||
"{{.Description}}\n\n" +
|
||||
"### Options\n\n" +
|
||||
"{{.Options}}\n\n"
|
||||
|
||||
func (cmdDoc CommandDocumentation) CmdDocToMd() (string, error) {
|
||||
|
||||
@@ -124,11 +119,11 @@ func (cmdDoc CommandDocumentation) cmdDocToCmdDocMd(options string) (commandDocu
|
||||
}
|
||||
|
||||
return commandDocumentForMarkdown{
|
||||
Command: cmdDoc.CommandStr,
|
||||
CommandAndShortDesc: fmt.Sprintf("`%s` - %s\n\n", cmdDoc.CommandStr, cmdDoc.GetShortDesc()),
|
||||
Synopsis: transformSynopsisToMarkdown(cmdDoc.CommandStr, synopsis),
|
||||
Description: longDesc,
|
||||
Options: options,
|
||||
Command: cmdDoc.CommandStr,
|
||||
ShortDesc: cmdDoc.GetShortDesc(),
|
||||
Synopsis: transformSynopsisToMarkdown(cmdDoc.CommandStr, synopsis),
|
||||
Description: longDesc,
|
||||
Options: options,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -199,16 +194,16 @@ func transformSynopsisToMarkdown(commandStr string, synopsis []string) string {
|
||||
if len(synopsis) == 0 {
|
||||
return ""
|
||||
}
|
||||
synopsisStr := fmt.Sprintf("%s %s<br />\n", commandStr, synopsis[0])
|
||||
synopsisStr := fmt.Sprintf("%s %s\n", commandStr, synopsis[0])
|
||||
if len(synopsis) > 1 {
|
||||
temp := make([]string, len(synopsis)-1)
|
||||
for i, el := range synopsis[1:] {
|
||||
temp[i] = fmt.Sprintf("\t\t\t%s %s<br />\n", commandStr, el)
|
||||
temp[i] = fmt.Sprintf("%s %s\n", commandStr, el)
|
||||
}
|
||||
synopsisStr += strings.Join(temp, "")
|
||||
}
|
||||
|
||||
markdown := "```bash\n%s\n```"
|
||||
markdown := "```bash\n%s```"
|
||||
return fmt.Sprintf(markdown, synopsisStr)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/iohelp"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -68,7 +67,7 @@ func (cmd *DumpDocsCmd) Exec(_ context.Context, commandStr string, args []string
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.GetCommandDocumentation(commandStr, cli.CommandDocumentationContent{}, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
fileStr := apr.GetValueOrDefault(fileParamName, ".")
|
||||
fileStr := apr.GetValueOrDefault(fileParamName, "cli.md")
|
||||
|
||||
exists, _ := dEnv.FS.Exists(fileStr)
|
||||
if exists {
|
||||
@@ -77,7 +76,13 @@ func (cmd *DumpDocsCmd) Exec(_ context.Context, commandStr string, args []string
|
||||
return 1
|
||||
}
|
||||
|
||||
err := cmd.dumpDocs(dEnv, fileStr, cmd.DoltCommand.Name(), cmd.DoltCommand.Subcommands)
|
||||
wr, err := dEnv.FS.OpenForWrite(fileStr, os.ModePerm)
|
||||
if err != nil {
|
||||
cli.PrintErrln(err.Error())
|
||||
return 1
|
||||
}
|
||||
|
||||
err = cmd.dumpDocs(wr, cmd.DoltCommand.Name(), cmd.DoltCommand.Subcommands)
|
||||
|
||||
if err != nil {
|
||||
verr := errhand.BuildDError("error: Failed to dump docs.").AddCause(err).Build()
|
||||
@@ -89,13 +94,7 @@ func (cmd *DumpDocsCmd) Exec(_ context.Context, commandStr string, args []string
|
||||
return 0
|
||||
}
|
||||
|
||||
func (cmd *DumpDocsCmd) dumpDocs(dEnv *env.DoltEnv, fileStr, cmdStr string, subCommands []cli.Command) error {
|
||||
|
||||
wr, err := dEnv.FS.OpenForWrite(fileStr, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (cmd *DumpDocsCmd) dumpDocs(wr io.Writer, cmdStr string, subCommands []cli.Command) error {
|
||||
for _, curr := range subCommands {
|
||||
var hidden bool
|
||||
if hidCmd, ok := curr.(cli.HiddenCommand); ok {
|
||||
@@ -104,7 +103,7 @@ func (cmd *DumpDocsCmd) dumpDocs(dEnv *env.DoltEnv, fileStr, cmdStr string, subC
|
||||
|
||||
if !hidden {
|
||||
if subCmdHandler, ok := curr.(cli.SubCommandHandler); ok {
|
||||
err := cmd.dumpDocs(dEnv, fileStr, cmdStr+" "+subCmdHandler.Name(), subCmdHandler.Subcommands)
|
||||
err := cmd.dumpDocs(wr, cmdStr+" "+subCmdHandler.Name(), subCmdHandler.Subcommands)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -128,5 +127,6 @@ func CreateMarkdown(wr io.Writer, cmdDoc cli.CommandDocumentation) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return iohelp.WriteIfNoErr(wr, []byte(markdownDoc), err)
|
||||
_, err = wr.Write([]byte(markdownDoc))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -35,20 +35,19 @@ const (
|
||||
|
||||
var resetDocContent = cli.CommandDocumentationContent{
|
||||
ShortDesc: "Resets staged tables to their HEAD state",
|
||||
LongDesc: `Sets the state of a table in the staging area to be that table's value at HEAD
|
||||
|
||||
{{.EmphasisLeft}}dolt reset <tables>...{{.EmphasisRight}}"
|
||||
This form resets the values for all staged {{.LessThan}}tables{{.GreaterThan}} to their values at {{.EmphasisLeft}}HEAD{{.EmphasisRight}}. (It does not affect the working tree or
|
||||
the current branch.)
|
||||
|
||||
This means that {{.EmphasisLeft}}dolt reset <tables>{{.EmphasisRight}} is the opposite of {{.EmphasisLeft}}dolt add <tables>{{.EmphasisRight}}.
|
||||
|
||||
After running {{.EmphasisLeft}}dolt reset <tables>{{.EmphasisRight}} to update the staged tables, you can use {{.EmphasisLeft}}dolt checkout{{.EmphasisRight}} to check the
|
||||
contents out of the staged tables to the working tables.
|
||||
|
||||
dolt reset .
|
||||
This form resets {{.EmphasisLeft}}all{{.EmphasisRight}} staged tables to their values at HEAD. It is the opposite of {{.EmphasisLeft}}dolt add .{{.EmphasisRight}}`,
|
||||
|
||||
LongDesc: "Sets the state of a table in the staging area to be that table's value at HEAD\n\n" +
|
||||
"{{.EmphasisLeft}}dolt reset <tables>...{{.EmphasisRight}}" +
|
||||
"\n\n" +
|
||||
"This form resets the values for all staged {{.LessThan}}tables{{.GreaterThan}} to their values at {{.EmphasisLeft}}HEAD{{.EmphasisRight}}. " +
|
||||
"It does not affect the working tree or the current branch." +
|
||||
"\n\n" +
|
||||
"This means that {{.EmphasisLeft}}dolt reset <tables>{{.EmphasisRight}} is the opposite of {{.EmphasisLeft}}dolt add <tables>{{.EmphasisRight}}." +
|
||||
"\n\n" +
|
||||
"After running {{.EmphasisLeft}}dolt reset <tables>{{.EmphasisRight}} to update the staged tables, you can use {{.EmphasisLeft}}dolt checkout{{.EmphasisRight}} to check the contents out of the staged tables to the working tables." +
|
||||
"\n\n" +
|
||||
"{{.EmphasisLeft}}dolt reset .{{.EmphasisRight}}" +
|
||||
"\n\n" +
|
||||
"This form resets {{.EmphasisLeft}}all{{.EmphasisRight}} staged tables to their values at HEAD. It is the opposite of {{.EmphasisLeft}}dolt add .{{.EmphasisRight}}",
|
||||
Synopsis: []string{
|
||||
"{{.LessThan}}tables{{.GreaterThan}}...",
|
||||
"[--hard | --soft]",
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
||||
@@ -46,6 +47,17 @@ const (
|
||||
maxConnectionsFlag = "max-connections"
|
||||
)
|
||||
|
||||
func indentLines(s string) string {
|
||||
sb := strings.Builder{}
|
||||
lines := strings.Split(s, "\n")
|
||||
for _, line := range lines {
|
||||
sb.WriteRune('\t')
|
||||
sb.WriteString(line)
|
||||
sb.WriteRune('\n')
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
var sqlServerDocs = cli.CommandDocumentationContent{
|
||||
ShortDesc: "Start a MySQL-compatible server.",
|
||||
LongDesc: "By default, starts a MySQL-compatible server on the dolt database in the current directory. " +
|
||||
@@ -55,7 +67,7 @@ var sqlServerDocs = cli.CommandDocumentationContent{
|
||||
"the server directly on the command line. If {{.EmphasisLeft}}--config <file>{{.EmphasisRight}} is provided all" +
|
||||
" other command line arguments are ignored.\n\nThis is an example yaml configuration file showing all supported" +
|
||||
" items and their default values:\n\n" +
|
||||
serverConfigAsYAMLConfig(DefaultServerConfig()).String() + "\n\n" + `
|
||||
indentLines(serverConfigAsYAMLConfig(DefaultServerConfig()).String()) + "\n\n" + `
|
||||
SUPPORTED CONFIG FILE FIELDS:
|
||||
|
||||
{{.EmphasisLeft}}vlog_level{{.EmphasisRight}} - Level of logging provided. Options are: {{.EmphasisLeft}}trace{{.EmphasisRight}}, {{.EmphasisLeft}}debug{{.EmphasisRight}}, {{.EmphasisLeft}}info{{.EmphasisRight}}, {{.EmphasisLeft}}warning{{.EmphasisRight}}, {{.EmphasisLeft}}error{{.EmphasisRight}}, and {{.EmphasisLeft}}fatal{{.EmphasisRight}}.
|
||||
|
||||
@@ -57,33 +57,32 @@ var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Co
|
||||
commands.InitCmd{},
|
||||
commands.StatusCmd{},
|
||||
commands.AddCmd{},
|
||||
commands.DiffCmd{},
|
||||
commands.ResetCmd{},
|
||||
commands.CommitCmd{},
|
||||
commands.SqlCmd{VersionStr: Version},
|
||||
sqlserver.SqlServerCmd{VersionStr: Version},
|
||||
sqlserver.SqlClientCmd{},
|
||||
commands.LogCmd{},
|
||||
commands.DiffCmd{},
|
||||
commands.BlameCmd{},
|
||||
commands.MergeCmd{},
|
||||
commands.BranchCmd{},
|
||||
commands.TagCmd{},
|
||||
commands.CheckoutCmd{},
|
||||
commands.MergeCmd{},
|
||||
cnfcmds.Commands,
|
||||
commands.RevertCmd{},
|
||||
commands.CloneCmd{},
|
||||
commands.FetchCmd{},
|
||||
commands.PullCmd{},
|
||||
commands.PushCmd{},
|
||||
commands.ConfigCmd{},
|
||||
commands.RemoteCmd{},
|
||||
commands.BackupCmd{},
|
||||
commands.PushCmd{},
|
||||
commands.PullCmd{},
|
||||
commands.FetchCmd{},
|
||||
commands.CloneCmd{},
|
||||
commands.RevertCmd{},
|
||||
credcmds.Commands,
|
||||
commands.LoginCmd{},
|
||||
commands.VersionCmd{VersionStr: Version},
|
||||
commands.ConfigCmd{},
|
||||
credcmds.Commands,
|
||||
commands.LsCmd{},
|
||||
schcmds.Commands,
|
||||
tblcmds.Commands,
|
||||
cnfcmds.Commands,
|
||||
commands.TagCmd{},
|
||||
commands.BlameCmd{},
|
||||
cvcmds.Commands,
|
||||
commands.SendMetricsCmd{},
|
||||
dumpDocsCommand,
|
||||
@@ -94,6 +93,7 @@ var doltCommand = cli.NewSubCommandHandler("dolt", "it's git for data", []cli.Co
|
||||
commands.FilterBranchCmd{},
|
||||
commands.MergeBaseCmd{},
|
||||
commands.RootsCmd{},
|
||||
commands.VersionCmd{VersionStr: Version},
|
||||
})
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user