Skip to content

Commit 727f1c5

Browse files
datadersamoeba
andauthored
docs: improve install version constraint guidance (#332)
Closes #331. ## Summary - make `dbc install -h` explicitly mention version constraints and link to the detailed docs - add a regression test for the install help output - add a visible version-constraint callout on the docs home page - make the CLI reference point directly to the version-constraints guide ## Validation - `go test ./...` - `go run ./cmd/dbc install -h` --------- Co-authored-by: Bryce Mecum <petridish@gmail.com>
1 parent 915dd34 commit 727f1c5

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

cmd/dbc/install.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
"path/filepath"
2424
"strings"
2525

26-
"github.com/Masterminds/semver/v3"
2726
"charm.land/bubbles/v2/progress"
2827
"charm.land/bubbles/v2/spinner"
2928
tea "charm.land/bubbletea/v2"
3029
"charm.land/lipgloss/v2"
30+
"github.com/Masterminds/semver/v3"
3131
"github.com/columnar-tech/dbc"
3232
"github.com/columnar-tech/dbc/config"
3333
)
@@ -50,13 +50,19 @@ func parseDriverConstraint(driver string) (string, *semver.Constraints, error) {
5050

5151
type InstallCmd struct {
5252
// URI url.URL `arg:"-u" placeholder:"URL" help:"Base URL for fetching drivers"`
53-
Driver string `arg:"positional,required" help:"Driver to install"`
53+
Driver string `arg:"positional,required" help:"Driver to install, optionally with a version constraint (for example: mysql, mysql=0.1.0, mysql>=1,<2)"`
5454
Level config.ConfigLevel `arg:"-l" help:"Config level to install to (user, system)"`
5555
Json bool `arg:"--json" help:"Output JSON instead of plaintext"`
5656
NoVerify bool `arg:"--no-verify" help:"Allow installation of drivers without a signature file"`
5757
Pre bool `arg:"--pre" help:"Allow implicit installation of pre-release versions"`
5858
}
5959

60+
func (InstallCmd) Description() string {
61+
return "Install a driver.\n\n" +
62+
"`DRIVER` may include a version constraint, for example `dbc install mysql`, `dbc install \"mysql=0.1.0\"`, or `dbc install \"mysql>=1,<2\"`.\n" +
63+
"See https://docs.columnar.tech/dbc/guides/installing/#version-constraints for more on version constraint syntax."
64+
}
65+
6066
func (c InstallCmd) GetModelCustom(baseModel baseModel) tea.Model {
6167
s := spinner.New()
6268
s.Spinner = spinner.MiniDot

cmd/dbc/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"os"
2121
"slices"
2222

23-
"github.com/alexflint/go-arg"
2423
tea "charm.land/bubbletea/v2"
2524
"charm.land/lipgloss/v2"
25+
"github.com/alexflint/go-arg"
2626
"github.com/columnar-tech/dbc"
2727
"github.com/columnar-tech/dbc/auth"
2828
"github.com/columnar-tech/dbc/cmd/dbc/completions"
@@ -177,7 +177,7 @@ func main() {
177177
args cmds
178178
)
179179

180-
p, err := arg.NewParser(arg.Config{Program: "dbc", EnvPrefix: "DBC_"}, &args)
180+
p, err := newParser(&args)
181181
if err != nil {
182182
fmt.Println("Error creating argument parser:", err)
183183
os.Exit(1)
@@ -260,3 +260,7 @@ func main() {
260260
os.Exit(h.Status())
261261
}
262262
}
263+
264+
func newParser(args *cmds) (*arg.Parser, error) {
265+
return arg.NewParser(arg.Config{Program: "dbc", EnvPrefix: "DBC_"}, args)
266+
}

cmd/dbc/main_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,29 @@ import (
2323
"time"
2424

2525
tea "charm.land/bubbletea/v2"
26+
"github.com/alexflint/go-arg"
2627
"github.com/columnar-tech/dbc"
2728
"github.com/stretchr/testify/require"
2829
)
2930

31+
func renderSubcommandHelp(t *testing.T, argv ...string) string {
32+
t.Helper()
33+
34+
var args cmds
35+
p, err := newParser(&args)
36+
require.NoError(t, err)
37+
38+
err = p.Parse(argv)
39+
require.ErrorIs(t, err, arg.ErrHelp)
40+
41+
var out bytes.Buffer
42+
if d, ok := p.Subcommand().(arg.Described); ok {
43+
fmt.Fprintln(&out, d.Description())
44+
}
45+
p.WriteHelpForSubcommand(&out, p.SubcommandNames()...)
46+
return out.String()
47+
}
48+
3049
func TestFormatErr(t *testing.T) {
3150
tests := []struct {
3251
name string
@@ -106,3 +125,12 @@ func TestCmdStatus(t *testing.T) {
106125
})
107126
}
108127
}
128+
129+
func TestInstallHelpMentionsVersionConstraints(t *testing.T) {
130+
out := renderSubcommandHelp(t, "install", "-h")
131+
132+
require.Contains(t, out, "Driver to install, optionally with a version constraint")
133+
require.Contains(t, out, `dbc install "mysql=0.1.0"`)
134+
require.Contains(t, out, `dbc install "mysql>=1,<2"`)
135+
require.Contains(t, out, "https://docs.columnar.tech/dbc/guides/installing/#version-constraints")
136+
}

docs/reference/cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ $ dbc install [OPTIONS] <DRIVER>
9999

100100
`DRIVER`
101101

102-
: Name of the driver to install. Can be a short driver name or a driver name with version requirement. Examples: `bigquery`, `bigquery=1.0.0`, `bigquery>1`. Can also be a path to a local driver archive, see [Installing Drivers: From Local Archive](../guides/installing.md#from-local-archive) for more information.
102+
: Name of the driver to install. This can be a plain driver name like `bigquery`, a driver name with a version constraint like `bigquery=1.0.0` or `bigquery>=1,<2`, or a path to a local driver archive.
103+
104+
For the full version-constraint syntax and more examples, see [Installing Drivers: Version Constraints](../guides/installing.md#version-constraints). For local archives, see [Installing Drivers: From Local Archive](../guides/installing.md#from-local-archive).
103105

104106
<h3>Options</h3>
105107

0 commit comments

Comments
 (0)