Skip to content

Overview

RSS-Feeds

Articles

CLI Syntax

xxd - usage - cool-retro-term

This blog article is essentially a repost of a small summary about CLI syntax on Unix and Windows systems. Originally intended it as a chapter for the cli-book I wanted to write. Unfortunately, I never found enough time to keep working on it. However, I still aim to gather more information and knowledge regarding the Terminal, Shells, and various command line tools available. Therefore, I decided to try sharing this information one blog post at a time. Since CLI syntax is crucial for understanding and developing CLI tools, I thought it would be beneficial to share and update the content I had initially written for the book.

Before you start reading this article you may consider reading the POSIX Utility Conventions. It is approximately a 10-20 minute read which will provide a solid base when it comes to CLIs and their syntax.

Let's get some content going

Terminology

If you read about CLIs, you will usually encounter specific terminology:

utility, command, subcommand, argument, option, flag, switch, operand
Still, the meanings may slightly differ depending on the source or context in which a term is mentioned. To ensure we are all on the same page regarding these terms, the table below describes the terms and their meanings in the context of this article and on this blog in general.

Term Meaning on this Blog Names in other Standards/Definitions
command The CLI tool itself utility (Posix)
subcommand A subcommand of a command or of a command group
argument (required/positional) Required or Positional Argument operand (Posix)
option A setting with an additional argument/value (key-value pair) option (Posix)
switch Like an option but with a set of mutually exclusive arguments/values option (Posix)
options Superset of flags + switches + options options (Posix)

Note

With the specification above, there is ambiguity regarding the term options. Here, options could mean either:

  • The plural of an option, a setting with an additional argument
  • options, the superset of flags, switches, and option

Therefore, when referring to the plural of option, one should say "options of type option," and when referring to the superset of all options, switches, and flags, one should simply say "options."

Below, you will find an annotated help example of a CLI, demonstrating where and how the different terms and types find their place.

Unix Syntax

Symbol Element Description
Text text Items you must type as shown
TEXT upper case text Placeholder for which you must supply a value
<name> text in angle brackets Placeholder for which you must supply a value
[] bracket Optional items
{} curly braces Set of mutually exclusive but required items, choose one
() braces Set of mutually exclusive but required items, choose one
| vertical bar Separates mutually exclusive items
ellipsis Indicates that item (flag, option, argument, ...) can be repeated multiple times
- dash Indicates start of short option(s), if it stands alone it is often used as file argument parameter to specify stdin
-- double dash Indicates the start of a long option or if not followed by an option name it indicates the end of the CLI arguments for the command

Windows Syntax

Symbol Element Description
Text Text Items you must type as shown
<Text> Text inside angle brackets Placeholder for which you must supply a value
[Text] Text inside square brackets Optional items
{Text} Text inside braces Set of required items. You must choose one
| Vertical bar Separator for mutually exclusive items. You must choose one
Ellipsis Items that can be repeated and used multiple times

The original source for the table above can be found here.

Examples

Usage Examples

Element Example(s)
Required/Positional Arguments ARGUMENT, <argument>, <ARGUMENT>
Option with value --option=value, --option=VALUE, --option <value>, --option=<value>, --option value, --option VALUE
Switch --light={on | off}, --power {up | down}
Flag --track, --verbose, -V
Optional Items --track, --verbose, -V, [<argument>]
Mutually-Exclusive & Required (--track | --no-track), <FILE> | <PATH>
End of passing CLI arguments user@host ~$ cli foo -b --this -- other args
Repeating Elements <argument>...

Annotated Example Help

Note: Everything following # is a comment

Short description what this command does

usage:

cmd [flags] [options] <username> <password>

arguments:
    <username>  which shall be used for the login             # 1. required/positional-argument
    <password>  associated with the specified username        # 2. required/positional-argument

flags:
    -f, --force                 execute action anyway         # 5. flag
    -h, --help                  show this help message        # 6. flag

options:
    -i <file>, --input <file>   file which shall be processed # 3. option
    -s <unit>, --speed <unit>   mph, kmh  [default: mph]      # 4. switch

References & Resources

Note

Git is an excellent resource for finding usage examples, seeing the CLI syntax in action, and understanding the nuances (it is well-documented, and there are plenty of answers available on Stack Overflow & Co.). If you ever get stuck figuring out how to structure your CLI, I recommend browsing through some Git commands.

The Learning Python Care Package

Learning Python Care Package

Image created by DALL-E, OpenAI's image generation model.

Over the past year, I've been approached by numerous individuals seeking recommendations for good Python learning resources. So I've decided to compile a somewhat comprehensive list in form of this article. Making it easier for me to share, by simply directing people here. If you've send here by me, I hope these resources meet your needs. If not, please let me know!

Book(s)

Fluent Python

Once you've moved past the very basics (syntax, etc.), this book stands out as the best, in my opinion. Recently, the second edition of this book was published. Despite owning a hard copy, I haven't had the time to read it yet. A short disclaimer: while the first edition is quite substantial, it's still a manageable size for reading as a physical book. However, the same can't be said for the second edition; it's quite hefty, making it more suitable for electronic reading.

(Best Python book in my humble opinion)

Pytest-Book

In my view, pytest is the go-to unit testing framework/library for Python. While I generally advocate for minimizing dependencies, especially when the Python standard library offers robust solutions, it's hard to argue against pytest. Once you grasp its potential and advantages, it is impossible to not go for it.

This book is an excellent resource for testing, particularly with pytest. I highly recommend it for anyone looking to delve deeper into testing and harnessing the power of pytest.

Online Courses

Talk Python to Me Courses

These courses are nicely crafted with love and passion, suitable for beginners to intermediate learners (depending on the topic). The ownership (lifetime access model) is highly appreciated in this world of subscription #%^*@-#. A nice side effect is also that it supports Talk Python To Me and Co. Beginners should definitely explore the courses offered here.

Pluralsight Courses by Austin Bingham and Robert Smallshire

Both authors offer great courses packed with valuable information and are well-crafted. For those inclined towards reading, they have three books catering to different experience levels, covering similar ground:

While I haven't read these books personally, judging from their video courses, they are likely to be of high standard.

Side Note (for Intermediate learners): You may find it beneficial to watch the videos at 1.2 - 1.4x speed, pausing or slowing down at the more "interesting" sections.

Programming Puzzles and Exercises

While preferences for programming puzzles and exercises vary greatly among individuals (personally, I lean towards creating small CLI applications for various purposes), I've also done some puzzles here and there. Below, you'll find a fairly standard list of Python puzzles and exercises that might be interesting to some of you.

Idioms

Inspired by this gist I started collecting python idioms here.

Podcasts

Python Bytes

Python headlines dilivered directly to your earbuds

Python Bytes is an entertaining weekly podcast of roughly 30 minutes. It's fantastic for getting quick updates and discovering new ideas (such as blog posts, new libraries, and frameworks) within the Python space.

Although it's a podcast, the episodes are also live-streamed, allowing listeners to engage in a live chat during the show.

Talk Python To Me

A podcast on Python and related technologies

While the above description is accurate, it understates the true value of this podcast.

My personal TL;DR would be:

An excellent ~60-minute podcast covering various detailed Python-related topics.

While not every episode might align with one's specific interests, they are consistently enjoyable to listen to. Alongside Python Bytes, this podcast offers an ideal way for staying updated on on Python and its community.

Talks

Stop Writing Classes by Jack Diederich

TL;DR: Old but Gold!!

Transforming Code into Beautiful, Idiomatic Python by Raymond Hettinger

TL;DR: Must watch talk on how to improve your python code.

Refactoring Python: Why and how to restructure your code by Brett Slatkin

TL;DR: Must watch talk on how to go about refacotring in python.

Modern Dictionaries by Raymond Hettinger

TL;DR: An interesting and insightful deep dive into dictionaries.