Sub topic 4
Finding help for commands and flags
This chapter assumes you have installed the CLI, can run sf --version, and know that commands follow the pattern sf <topic> <command> --flag. The CLI has hundreds of commands, so you will look things up often. The built-in help is the fastest source and always matches the version you have installed.
Help at each level
You can ask for help at any level of the command structure. Each level shows more detail than the one before.
sf --help
sf org --help
sf org login web --helpsf --helplists the top-level topics, such asorg,project,data, andapex.sf org --helplists the commands and subtopics inside theorgtopic.sf org login web --helpshows the full reference for one command.
The sf help form works the same way. sf help org login web prints the same page as sf org login web --help.
Reading a command's help page
A command's help page has several sections. The names can vary slightly between CLI versions.
- Description: what the command does, sometimes with notes on behavior.
- Usage: the command with its flags in brackets, such as
sf data query [--json] [-o <value>] -q <value>. - Flags: each flag with its short form, long form, and a description. Flags that must be supplied are marked as required.
- Global flags: flags that most commands accept, such as
--json. - Examples: sample invocations you can copy and adapt.
Short forms save typing. For example, the help for sf org login web lists -a as the short form of --alias and -d as the short form of --set-default. These two commands are equivalent:
sf org login web --alias myorg --set-default
sf org login web -a myorg -dUse long flags in scripts and tutorials because they are easier to read. Use short flags when typing interactively.
Listing every command
When you do not know which topic holds a command, list them all and filter the output.
sf commands
sf commands | grep scratchThe first line prints every command available in your installation, including commands added by plugins. The second narrows the list to lines containing scratch, which points you to sf org create scratch. Run sf commands --help to see whether your version offers extra options, such as other output formats.
Common errors
- "command not found" for a topic or command: You probably misspelled it, or the command comes from a plugin that is not installed. Run
sf commandsto check what exists. The CLI often suggests the closest match. - "Missing required flag": Open the command's
--helppage and find the flags marked as required. Add each one. - Old advice that does not work: Many online examples use the older
sfdxcommand with colons, such assfdx force:org:list. Thesfcommand uses spaces instead, as insf org list. Check the help for thesfequivalent instead of copying the old form. - Help that does not match a tutorial: Flags can change between CLI versions. The help on your machine is the reference for your version. Run
sf --versionto see which version that is.
A short lookup routine
When you need a command you have not used before, follow these steps:
- Run
sf --helpand pick the topic that fits your task. - Run
sf <topic> --helpto list its commands. - Run
sf <topic> <command> --helpand read the required flags and examples. - Copy an example, change the values, and run it.
Exercise
You want to create a scratch org, but you don't remember the exact command or the flag that sets how many days it lasts. Which help commands would you run, and where in the output would you look?
Show answer
Run sf commands | grep scratch (or sf org --help) to find sf org create scratch. Then run sf org create scratch --help. In the Flags section, look for the duration flag (--duration-days) and check whether it is marked as required. The Examples section shows a full working command to adapt.
Exercise
A blog post shows sfdx force:org:list. How do you find the current sf equivalent without searching the web?
Show answer
Run sf org --help to list the commands in the org topic and find list. Then run sf org list --help to confirm its flags. The current command is sf org list.