CF CLI commands are not working for application with name starting with a hyphen
search cancel

CF CLI commands are not working for application with name starting with a hyphen

book

Article ID: 297736

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

Symptoms:
CF CLI commands are not working for applications of which the name starting with hyphen.
ubuntu@opsmgr:~/sandbox/my-php-app$ cat manifest.yml
---
applications:
- name: -my-php-app
  memory: 512M
  buildpack: php_buildpack

ubuntu@opsmgr:~/sandbox/my-php-app$ cf apps
Getting apps in org myorg1 / space myspace1 as admin...
OK

name                       requested state   instances   memory   disk   urls
-my-php-app                started           1/1         512M     1G     my-php-app.example.com
ubuntu@opsmgr:~/sandbox/my-php-app$ cf app "-my-php-app"

Incorrect Usage: unknown flag `m'

Environment


Cause

Currently the CF CLI does not support application names or any name label that starts with a hyphen character (`-`). And it will interpret a leading dash on a label as a command line flag and fail to parse the command.

Resolution

The issue has been reported to engineering and document will be updated first to reflect this limitation.
User should try avoid using hyphen (and other special characters) as first character of application name.
If the first character of application name has to be a special one (like a hyphen), then use "cf curl" instead as illustrated below.


Workaround
1. Add '-v' flag to trace the CLI request for "cf app" command by prefixing '\' character to application name
ubuntu@ops-manager:~/my-php-app$ cf -v app "\-my-php-app" 
...... 
REQUEST: [2018-06-04T12:31:25+08:00] GET /v2/apps?q=name%3A%5C-my-php-app&q=space_guid%3Aaa5e4bf2-d35d-43d9-ab3a-08fa57343490 HTTP/1.1 
......
2. Extract the URL from output and remove '\' (%5C). Then run "cf curl" with modified URL
ubuntu@opsmgr:~/sandbox/my-php-app$ cf curl /v2/apps?q=name%3A-my-php-app&q=space_guid%3Aaa5e4bf2-d35d-43d9-ab3a-08fa57343490
{
   "total_results": 1,
   "total_pages": 1,
   "prev_url": null,
   "next_url": null,
   "resources": [
      {
         "metadata": {
            "guid": "8a2155ee-c1a9-4574-8cda-cb92bc0a7995",
            "url": "/v2/apps/8a2155ee-c1a9-4574-8cda-cb92bc0a7995",
            "created_at": "2018-06-01T13:26:17Z",
            "updated_at": "2018-06-01T13:26:24Z"
         },
......