Skip to content

Add bash completion script and automate .cap file lookup for for ocluster-admin #244

@shonfeder

Description

@shonfeder

@mtelvers has a nice setup to streamline the use of the ocluster-admin. As a low priority way to improve operator quality of life and achieve some "documentation by automation" it could be cool to incorporate parts of these into the CLI and installation procedure.

But in the meantime, I'll just include the scripts her shared with me here, as this at least makes them available for others who may find them useful:

To avoid having to supply the path to an admin.cap wile, you can make a runner script like /usr/local/bin/ci3-admin

#!/bin/bash

ocluster-admin -c ~/.config/ocluster/admin.cap "$@"

Then get bash completions with this script added to, e.g., /etc/bash_completion.d/ci3-admin

#/usr/bin/env bash
_ci3-admin_completions()
{
  WORDS=()
  for value in "${COMP_WORDS[@]}"; do
    [[ $value != --* ]] && WORDS+=($value)
  done

  if [ "${#WORDS[@]}" == "2" ]; then
    COMPREPLY=($(compgen -W "$(ci3-admin  2>&1 | head -1 | grep -Po "'\K[^', .]*")" -- "${WORDS[1]}"))
    return
  fi

  if [ "${#WORDS[@]}" == "3" ]; then
    case ${WORDS[1]} in
      show|pause|unpause|exec|forget|set-rate|update)
        COMPREPLY=($(compgen -W "$(ci3-admin show)" -- "${WORDS[2]}"))
        ;;
    esac
    return
  fi

  if [ "${#WORDS[@]}" == "4" ]; then
    case ${WORDS[1]} in
      pause|unpause|forget|update)
        COMPREPLY=($(compgen -W "$(ci3-admin show ${WORDS[2]} --terse)" -- "${WORDS[3]}"))
        ;;
    esac
    return
  fi
}

complete -F _ci3-admin_completions ci3-admin

Including this in the installation and CLI might mean:

  • Extend the CLI so that ocluster-admint looks in particular location for the admin.cap file ("convention over configuration")
  • Add the auto-completion script to the installation recipe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions