Skip to content

profiles fail to be read during bash command completion #97

@loleary

Description

@loleary

When using command completion, errors will appear in bash command completion due to oc-cluster.bash using the absolute and hard coded path from the user who executed oc-cluster completion bash.

For example, as root:

# ./oc-cluster completion bash 
...
  commands="up down destroy list status show ssh console plugin-list plugin-install plugin-uninstall -h --help"

  profiles=$(ls -d /root/.oc/profiles/*/ | xargs -L1 basename)

  boolean_args="--create-machine= --forward-ports= --metrics= --skip-registry-check= --use-existing-config="
...

This is because the assignment of profiles in the heredoc of the completion function uses the following assignment:

profiles=\$(ls -d $OPENSHIFT_PROFILES_DIR/*/ | xargs -L1 basename)

This assignment carries 2 problems.

  1. $OPENSHIFT_PROFILES_DIR/*/ is expanded to the value of the variable as it is defined by the oc-cluster command itself. By default, this is the user's home directory.
  2. If the profiles directory is empty, the ls command will fail and xargs will pass 0 arguments to basename.

The profiles assignment should instead define OPENSHIFT_PROFILES_DIR in the same manner that oc-cluster does so that it is more generic along with setting profiles to an empty string in the event that no profiles are found. For example:

ls -d "\$OPENSHIFT_PROFILES_DIR"/*/ >/dev/null 2>&1 && profiles=\$(ls -d "\$OPENSHIFT_PROFILES_DIR"/*/ | xargs -L1 basename) || profiles=''

I submitted #96 to address both of these problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions