Command names

From John's wiki
Revision as of 22:33, 10 June 2020 by Sixsigma (talk | contribs)
Jump to navigation Jump to search

These are my nascent thoughts on naming things, specifically naming Linux commands which will be issued in a console. The "grammar" described here might not yet be sufficiently powerful, this is a work in progress and these are just first thoughts. If you have suggestions for me I would be very pleased to hear them, feel free to get in contact.

Command names must be all lower case and can contain alphanumeric ASCII characters and dash (-) and dot (.), but they must not start or end with dash or dot.

If the command is implemented as a BASH function or a BASH alias then the name has no suffix. Otherwise the command suffix will indicate the implementation with a suffix (file extension) that is typically '.sh' for BASH scripts and '.php' for PHP scripts and so on for your weapon of choice. Yes this leaks an implementation detail into the interface, and yes we're gonna do that anyway.

Commands which are scripts should start with a shebang and be chmoded +x. Use /bin/bash for BASH and /usr/bin/env php for PHP.

If the command operates on only a single "hardcoded" noun then the command name is in the form noun-verb. Otherwise if the command operates on an arbitrary noun taken as a parameter then the command name is in the form verb-noun. If you have a hardcoded noun which you can operated on for a variable noun then the format is noun-verb-noun.

Examples

Database backups

So we have a database server called 'unity' which has a bunch of databases with various names.

The name of the script which can backup any MySQL/MariaDB database server (indicated with a command argument) is called 'backup-mysql.sh'.

The name of the script which backs up 'unity' is 'unity-backup.sh' (because it only operates on 'unity').

The name of the script which can restore a database backup to any MySQL/MariaDB database server is called 'restore-mysql-database.sh', notice that nouns stack "containerwise" (i.e. the "MySQL/MariaDB" server contains the "database", so the container is listed first in the noun list).

The name of the script which can restore a specific database backup to 'unity' is called 'unity-restore.sh'.