forcedotcom / cli

Salesforce CLI
https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/
BSD 3-Clause "New" or "Revised" License
474 stars 77 forks source link

Issue with using org Alias in command #2887

Closed pandayashasvi closed 1 month ago

pandayashasvi commented 1 month ago

Summary

If Alias name of Salesforce org in VS code have space then sf org logout command is not working.

Steps To Reproduce

  1. Authorize an org in VS code and give it alias name "personal org". Look here we have space between personal and org.
  2. Now run command sf org logout --target-org personal org --no-prompt
  3. It will give us error : Error (2): Unexpected argument: org

But if we try same with a alias having no space then it is working correctly. Also it is working correctly if we use username instead of alias.

I think we should either restrict to not have space in alias or resolve this thing.

Expected result

sf org logout --target-org personal org --no-prompt command should run as per documentation we can use alias name for this command.

Actual result

Error (2): Unexpected argument: org

System Information

I am using powershell.

{
  "architecture": "win32-x64",
  "cliVersion": "@salesforce/cli/2.42.6",
  "nodeVersion": "node-v20.12.2",
  "osVersion": "Windows_NT 10.0.22631",
  "rootPath": "C:\\Users\\panda\\AppData\\Local\\sf\\client\\2.42.6-2b3c407",
  "shell": "cmd.exe",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 3.0.18 (core)",
    "@oclif/plugin-commands 3.3.4 (core)",
    "@oclif/plugin-help 6.0.22 (core)",
    "@oclif/plugin-not-found 3.1.9 (core)",
    "@oclif/plugin-plugins 5.0.21 (core)",
    "@oclif/plugin-search 1.0.24 (core)",
    "@oclif/plugin-update 4.2.12 (core)",
    "@oclif/plugin-version 2.1.2 (core)",
    "@oclif/plugin-warn-if-update-available 3.0.19 (core)",
    "@oclif/plugin-which 3.1.10 (core)",
    "@salesforce/cli 2.42.6 (core)",
    "apex 3.1.11 (core)",
    "auth 3.6.11 (core)",
    "data 3.3.5 (core)",
    "deploy-retrieve 3.6.14 (core)",
    "info 3.2.8 (core)",
    "limits 3.3.7 (core)",
    "marketplace 1.2.5 (core)",
    "org 4.1.10 (core)",
    "packaging 2.4.4 (core)",
    "schema 3.3.6 (core)",
    "settings 2.2.6 (core)",
    "sobject 1.4.2 (core)",
    "source 3.3.12 (core)",
    "telemetry 3.3.7 (core)",
    "templates 56.2.7 (core)",
    "trust 3.6.11 (core)",
    "user 3.5.8 (core)",
    "@salesforce/sfdx-scanner 3.24.0 (user) published 28 days ago (Tue Apr 30 2024) (latest is 3.25.0)"
  ]
}

Additional information

image image

github-actions[bot] commented 1 month ago

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

iowillhoit commented 1 month ago

Hey @pandayashasvi, you need to wrap your alias (--target-org) in double quotes. Otherwise it gets parsed as two separate arguments. Like so:

> sf org logout --target-org "test org"
Warning: If you log out of a scratch org without having access to its password, you can't access this org again, either through the CLI or the Salesforce UI.
? Are you sure you want to log out of test-dyptbs11glfe@example.com? yes
Successfully logged out of orgs: test-dyptbs11glfe@example.com

This is an all around best-practice when passing strings with spaces on the command line. To avoid needed quotes, you can use a hyphen instead. For example: --alias personal-org

pandayashasvi commented 1 month ago

@iowillhoit Thanks for this information, i thought it was a bug. But Thank you so much.