Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created February 27, 2025 20:12
Show Gist options
  • Save gmolveau/1c602beb59bb10c17fda7201d7e4044f to your computer and use it in GitHub Desktop.
Save gmolveau/1c602beb59bb10c17fda7201d7e4044f to your computer and use it in GitHub Desktop.
cli best practices #linux

CLI best practices

  • use the most common flags

    • the help flag : --help | -h | -?
     $ git --help
     usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
                [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
                [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
                [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
                [--super-prefix=<path>] [--config-env=<name>=<envvar>]
                <command> [<args>]
    
     These are common Git commands used in various situations:
    • the version flag : –-version | -V
     $ docker --version
     Docker version 27.4.0, build bde2b89
    • the verbose flag : --verbose | -v | -v(*N)
     $ git branch
     * main
    
     $ git branch -v
     * main e9c9f79fc3b1 [behind 7] feat: implement `service` factory and refactor services (#193)
  • respect the args/flags syntax in the usage text

    • [...] = optional
    • <...> = mandatory
    • cf. man git
  • trackable errors : https://www.shellcheck.net/wiki/SC2128

  • human-readable errors

$ shellcheck script.sh

In script.sh line 1:
echo "ok"
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

For more information:
  https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell...
  • actionable error codes
$ git pusd
git: 'pusd' is not a git command. See 'git --help'.

The most similar command is
        push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment