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
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ jobs:
sudo apt-get install shellcheck
./run-tests.sh --check-shellcheck

check-shell-completions:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.18.X'

- name: Check shell completions are up-to-date
run: |
./run-tests.sh --check-shell-completions

go-tests:
runs-on: ubuntu-24.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.dll
*.so
*.dylib
reana-client-go
/reana-client-go

# Test binary, built with `go test -c`
*.test
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ researchers to submit, run, and manage their computational workflows.
The detailed information on how to install and use REANA can be found in
[docs.reana.io](https://docs.reana.io).

## Shell completion

The `reana-client-go` supports shell completion for Bash and Zsh. To enable the
auto-completion of commands and options, add the following to your shell
configuration file:

**Bash** (add to `~/.bashrc`):

```bash
source <(reana-client-go completion bash)
```

**Zsh** (add to `~/.zshrc`):

```bash
source <(reana-client-go completion zsh)
compdef _reana-client-go reana-client-go
```

# Useful links

- [REANA project home page](http://www.reana.io/)
Expand Down
85 changes: 85 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
This file is part of REANA.
Copyright (C) 2025 CERN.

REANA is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
*/

package cmd

import (
"os"

"github.com/spf13/cobra"
)

const completionLongDesc = `Generate shell completion scripts for reana-client-go.

To load completions:

Bash:

$ source <(reana-client-go completion bash)

# To load completions for each session, execute once:
# Linux:
$ reana-client-go completion bash > /etc/bash_completion.d/reana-client-go
# macOS:
$ reana-client-go completion bash > $(brew --prefix)/etc/bash_completion.d/reana-client-go

Zsh:

# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, add to your .zshrc:
$ source <(reana-client-go completion zsh)
$ compdef _reana-client-go reana-client-go

# Or install to fpath (requires new shell):
$ reana-client-go completion zsh > "${fpath[1]}/_reana-client-go"

Fish:

$ reana-client-go completion fish | source

# To load completions for each session, execute once:
$ reana-client-go completion fish > ~/.config/fish/completions/reana-client-go.fish

PowerShell:

PS> reana-client-go completion powershell | Out-String | Invoke-Expression

# To load completions for every new session, run:
PS> reana-client-go completion powershell > reana-client-go.ps1
# and source this file from your PowerShell profile.
`

func newCompletionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate shell completion scripts.",
Long: completionLongDesc,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
return cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
return cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
return cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
return nil
},
}

return cmd
}
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type rootOptions struct {
func NewRootCmd() *cobra.Command {
o := &rootOptions{}
cmd := &cobra.Command{
Use: "reana-client",
Use: "reana-client-go",
Short: "REANA client for interacting with REANA server.",
Long: "REANA client for interacting with REANA server.",
SilenceUsage: true,
Expand Down Expand Up @@ -64,6 +64,7 @@ func NewRootCmd() *cobra.Command {
{
Message: "Configuration commands:",
Commands: []*cobra.Command{
newCompletionCmd(),
newInfoCmd(),
newPingCmd(),
newVersionCmd(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/secrets_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSecretsList(t *testing.T) {
},
"unexpected args": {
args: []string{"arg"},
expected: []string{"unknown command \"arg\" for \"reana-client secrets-list\""},
expected: []string{"unknown command \"arg\" for \"reana-client-go secrets-list\""},
wantError: true,
},
"server error": {
Expand Down
Loading
Loading