CLI Flags: -v, -V, and --v

· 1 min read · 309 Words · -Views -Comments

I’ve been studying CLI tools and keep seeing different flag styles. Here’s what I’ve learned about conventions and differences.

Command structure

First, a common command structure:

cli_structure

A few more points:

  1. 有些命令针对option参数是有长短两种格式的,碰巧图中的b没有对应长格式,但比如f就有-f--force。长短参数作用一致,仅仅是书写上的不同

  2. Short flags can often be combined, but not always. For example, git checkout -b newBranch -f cannot be combined into git checkout -bf newBranch.

  3. Flags are case‑sensitive; some commands use uppercase flags.

  4. Flags may take values using a space or = depending on the CLI. Docker supports both: --name="doc-searcher" equals --name "doc-searcher".

-v, -V, –v

With the structure in mind:

  • -v is a short flag.
  • --v is a long flag (though uncommon — most tools use names like --version).
  • -V is a short flag using uppercase.

Recommendations

Different tools vary, which adds learning cost. When building your own CLI, follow common conventions. See commander.js for a well‑adopted model.

  1. 参数值采用空格方式
  2. 参数采用长短格式,短格式为单个字符,长格式为完整词汇
  3. 子命令/参数采用小写

Final Thoughts

  1. Following CLI conventions improves efficiency and avoids mistakes.
  2. Good CLI design lowers the learning curve.
Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover