Skip to content

Commit 4db1a46

Browse files
committed
add --json to uninstall
1 parent 4047ad5 commit 4db1a46

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

cmd/dbc/completions/dbc.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ _dbc_uninstall_completions() {
8787
esac
8888

8989
if [[ "$cur" == -* ]]; then
90-
COMPREPLY=($(compgen -W "--level -l" -- "$cur"))
90+
COMPREPLY=($(compgen -W "--json --level -l" -- "$cur"))
9191
return 0
9292
fi
9393

cmd/dbc/completions/dbc.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ complete -f -c dbc -n '__fish_dbc_using_subcommand install' -l no-verify -d 'Do
4747
complete -f -c dbc -n '__fish_dbc_using_subcommand install' -l level -s l -d 'Installation level' -xa 'user system'
4848

4949
# uninstall subcommand
50+
complete -f -c dbc -n '__fish_dbc_using_subcommand uninstall' -l json -d 'Print output as JSON instead of plaintext'
5051
complete -f -c dbc -n '__fish_dbc_using_subcommand uninstall' -l level -s l -d 'Installation level' -xa 'user system'
5152

5253
# init subcommand

cmd/dbc/completions/dbc.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function _dbc_uninstall_completions {
8181
_arguments \
8282
'(-l)--level[installation level]: :(user system)' \
8383
'(--level)-l[installation level]: :(user system)' \
84+
'--json[Print output as JSON instead of plaintext]' \
8485
':driver name: '
8586
}
8687

cmd/dbc/uninstall.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ type driverDidUninstallMsg struct{}
2626
type UninstallCmd struct {
2727
Driver string `arg:"positional,required" help:"Driver to uninstall"`
2828
Level config.ConfigLevel `arg:"-l" help:"Config level to uninstall from (user, system)"`
29+
Json bool `arg:"--json" help:"Print output as JSON instead of plaintext"`
2930
}
3031

3132
func (c UninstallCmd) GetModelCustom(baseModel baseModel) tea.Model {
3233
return uninstallModel{
33-
baseModel: baseModel,
34-
Driver: c.Driver,
35-
cfg: getConfig(c.Level),
34+
baseModel: baseModel,
35+
Driver: c.Driver,
36+
cfg: getConfig(c.Level),
37+
jsonOutput: c.Json,
3638
}
3739
}
3840

@@ -42,16 +44,18 @@ func (c UninstallCmd) GetModel() tea.Model {
4244
getDriverRegistry: getDriverRegistry,
4345
downloadPkg: downloadPkg,
4446
},
45-
Driver: c.Driver,
46-
cfg: getConfig(c.Level),
47+
Driver: c.Driver,
48+
cfg: getConfig(c.Level),
49+
jsonOutput: c.Json,
4750
}
4851
}
4952

5053
type uninstallModel struct {
5154
baseModel
5255

53-
Driver string
54-
cfg config.Config
56+
Driver string
57+
cfg config.Config
58+
jsonOutput bool
5559
}
5660

5761
func (m uninstallModel) Init() tea.Cmd {
@@ -64,9 +68,15 @@ func (m uninstallModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6468
case config.DriverInfo:
6569
return m.performUninstall(msg)
6670
case driverDidUninstallMsg:
71+
if m.jsonOutput {
72+
return m, tea.Sequence(tea.Printf("{\"status\": \"success\", \"driver\": \"%s\"}\n", m.Driver), tea.Quit)
73+
}
6774
return m, tea.Sequence(tea.Printf("Driver `%s` uninstalled successfully!\n", m.Driver), tea.Quit)
6875
case error:
6976
m.status = 1
77+
if m.jsonOutput {
78+
return m, tea.Sequence(tea.Printf("{\"status\": \"error\", \"error\": \"%s\"}\n", msg.Error()), tea.Quit)
79+
}
7080
return m, tea.Sequence(
7181
tea.Println(errStyle.Render("Error: "+msg.Error())),
7282
tea.Quit)

docs/reference/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ $ dbc uninstall [OPTIONS] <DRIVER>
132132

133133
<h3>Options</h3>
134134

135+
`--json`
136+
137+
: Print output as JSON instead of plaintext
138+
135139
`--level LEVEL`, `-l LEVEL`
136140

137141
: The configuration level to uninstall the driver from (`user`, or `system`). See [Config Level](config_level.md).

0 commit comments

Comments
 (0)