Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,28 @@ nfpms:
package_name: dbc
file_name_template: "{{ .ConventionalFileName }}"
if: '{{ eq .Os "linux" }}'
vendor: Columnar
vendor: Columnar Technologies Inc.
homepage: "https://columnar.tech/dbc"
license: Apache-2.0

description: >-
A CLI utility for managing ADBC drivers

formats:
- deb
- rpm
meta: false
priority: extra
contents:
- src: cmd/dbc/completions/dbc.bash
dst: /etc/bash_completion.d/dbc

- src: cmd/dbc/completions/dbc.zsh
dst: /usr/share/zsh/vendor-completions/_dbc

- src: cmd/dbc/completions/dbc.fish
dst: /usr/share/fish/vendor_completions.d/dbc.fish


snapcrafts:
- id: snaps
Expand Down
54 changes: 54 additions & 0 deletions cmd/dbc/completions/bash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2025 Columnar Technologies 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 completions

import _ "embed"

//go:embed dbc.bash
var bashScript string

type Bash struct{}

func (Bash) Description() string {
return `Generate the autocompletion script for the bash shell.

This script depends on the 'bash-completion' package.
If it is not installed already, you can install it via your OS's package manager.

To load completions in your current shell session:

source <(dbc completion bash)

To load completions for every new session, execute once:

echo 'eval "$(dbc completion bash)"' >> ~/.bashrc

To install completions system-wide:

#### Linux:

dbc completion bash > /etc/bash_completion.d/dbc

#### macOS:

dbc completion bash > $(brew --prefix)/etc/bash_completion.d/dbc

You will need to start a new shell for this setup to take effect.
`
}

func (Bash) GetScript() string {
return bashScript
}
30 changes: 30 additions & 0 deletions cmd/dbc/completions/completions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2025 Columnar Technologies 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 completions

type ShellImpl interface {
GetScript() string
}

type Cmd struct {
Bash *Bash `arg:"subcommand" help:"Generate autocompletion script for bash"`
Zsh *Zsh `arg:"subcommand" help:"Generate autocompletion script for zsh"`
Fish *Fish `arg:"subcommand" help:"Generate autocompletion script for fish"`
}

func (Cmd) Description() string {
return "Generate the autocompletion script for dbc for the requested shell.\n" +
"See each sub-command's help for details on how to use the generated script.\n"
}
229 changes: 229 additions & 0 deletions cmd/dbc/completions/dbc.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# bash completion for dbc -*- shell-script -*-

_dbc() {
local cur prev words cword
_init_completion || return

local subcommands="install uninstall init add sync search remove completion"
local global_opts="--help -h --version"

# If we're completing the first argument (subcommand)
if [[ $cword -eq 1 ]]; then
COMPREPLY=($(compgen -W "$subcommands $global_opts" -- "$cur"))
return 0
fi

# Get the subcommand (first argument)
local subcommand="${words[1]}"

case "$subcommand" in
install)
_dbc_install_completions
;;
uninstall)
_dbc_uninstall_completions
;;
init)
_dbc_init_completions
;;
add)
_dbc_add_completions
;;
sync)
_dbc_sync_completions
;;
search)
_dbc_search_completions
;;
remove)
_dbc_remove_completions
;;
completion)
_dbc_completion_completions
;;
*)
COMPREPLY=()
;;
esac
}

_dbc_install_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
--level|-l)
COMPREPLY=($(compgen -W "user system" -- "$cur"))
return 0
;;
esac

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "--no-verify --level -l" -- "$cur"))
return 0
fi

# Driver name completion (no specific completion available)
COMPREPLY=()
}

_dbc_uninstall_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
--level|-l)
COMPREPLY=($(compgen -W "user system" -- "$cur"))
return 0
;;
esac

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "--level -l" -- "$cur"))
return 0
fi

# Driver name completion (no specific completion available)
COMPREPLY=()
}

_dbc_init_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h" -- "$cur"))
return 0
fi

# Complete .toml files
COMPREPLY=($(compgen -f -X '!*.toml' -- "$cur"))
# Add directory completion as well
if [[ -d "$cur" ]]; then
COMPREPLY+=($(compgen -d -- "$cur"))
fi
}

_dbc_add_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
--path|-p)
# Complete .toml files
COMPREPLY=($(compgen -f -X '!*.toml' -- "$cur"))
if [[ -d "$cur" ]]; then
COMPREPLY+=($(compgen -d -- "$cur"))
fi
return 0
;;
esac

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --path -p" -- "$cur"))
return 0
fi

# Driver name completion (no specific completion available)
COMPREPLY=()
}

_dbc_sync_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
--level|-l)
COMPREPLY=($(compgen -W "user system" -- "$cur"))
return 0
;;
--path|-p)
# Complete .toml files
COMPREPLY=($(compgen -f -X '!*.toml' -- "$cur"))
if [[ -d "$cur" ]]; then
COMPREPLY+=($(compgen -d -- "$cur"))
fi
return 0
;;
esac

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --level -l --path -p --no-verify" -- "$cur"))
return 0
fi

COMPREPLY=()
}

_dbc_search_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h -v -n" -- "$cur"))
return 0
fi

# Search term completion (no specific completion available)
COMPREPLY=()
}

_dbc_remove_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

case "$prev" in
--path|-p)
# Complete .toml files
COMPREPLY=($(compgen -f -X '!*.toml' -- "$cur"))
if [[ -d "$cur" ]]; then
COMPREPLY+=($(compgen -d -- "$cur"))
fi
return 0
;;
esac

if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --path -p" -- "$cur"))
return 0
fi

# Driver name completion (no specific completion available)
COMPREPLY=()
}

_dbc_completion_completions() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

# If we're at position 2 (right after "completion"), suggest shell types
if [[ $COMP_CWORD -eq 2 ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --help" -- "$cur"))
else
COMPREPLY=($(compgen -W "bash zsh fish" -- "$cur"))
fi
return 0
fi

# If we've already specified a shell, just offer help
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W "-h --help" -- "$cur"))
return 0
fi

COMPREPLY=()
}

# Register the completion function
complete -F _dbc dbc

# ex: ts=4 sw=4 et filetype=sh
Loading
Loading