
Sometimes long-style named arguments may accept or even require to pass a value with an equals sign instead of space in-between, like -block-size=K. Mentioned earlier short flags concatenation may not work, forcing us to provide all flags separately. Differences in argument parsingĭepending on the implementation used to parse command line arguments, the details and flexibility in accepting them may differ. Then there is a subcommand, and arguments specific for this subcommand. First, after the main command, there are its arguments. commit is a subcommand.Ĭommands with subcommands can have two sets of arguments. What about the Git commands, that we use every day? Doesn’t the git commit command break the general rules I mentioned above? $ git commit -m 'My message'Įven if the commit word may look like a positional argument at first, after which the -m named argument should not happen, it’s not a case here. In most cases, everything after the first positional argument is also treated as the next positional arguments. But can we mix those two groups with each other?

We see that order of flags and value arguments does not have a meaning, and the order of positional arguments is important. In the cp (“copy”) command consequences will be greater, as the first argument is a source file, and the second is a target where to put a copy. In the ls command, if we provide multiple paths, their content will be listed in the same order as we gave them. This is true, and their order may, or may not, have consequences. First of all, “positional” means that the position of those arguments matter. Things look differently with positional arguments. Those two calls are correct and equal: $ ls -l -block-size K Which makes sense – we shouldn’t expect the user to remember the order on top of the kind of arguments the executable accepts. Command arguments orderĪs a rule, the command should not expect flags and value arguments to be in any particular order. An example of such flag in ls would be -R / -recursive, which makes ls print also the content of subdirectories, recursively. A short, single letter one for fast of use by experienced users, and a longer, more verbose one for better readability. $ ls -a -lĪlso, some commonly used flags and arguments may have two names. They both list all the files (including hidden) in a current directory in a long format. For example, those two next calls are equal. For example in the wget command, -help is a flag, and -O (shortcut from -output-document) is a named argument requiring a value.Ī single-dash prefix often allows concatenating multiple single-letter flags. They both can be short with a single-letter name or longer. For longer names, we use two dashes.įlags and named arguments are not distinguished by the length of the name. If an argument name is a single letter, it’s standard to prefix it with a single dash.

The way to achieve it is to make usage as standard and as obvious as possible.īasically, we would like to avoid situation like this: $. To use it users should have to remember as little as possible. It means that if our executable expects arguments, it should parse them in a standard way. And there is one important rule we should apply here – predictability and familiarity. Designing for the users, even in a case of a small script taking few arguments, should have the UX at the first place. Whoever will be calling the executable, is your user. It also accepts any number of positional arguments. It tells ls which directory files should be listed.įor ls all arguments are optional. Providing this parameter without a value will raise an error.Īnd finally, ~/Documents is a positional argument. The value must come right after a parameter name. The “K” value changes the format of displayed file sizes from default bytes to Kilobytes. block-size K is a parameter with a value. It makes ls print results in a long format, with every file in a separate line. l is a flag, an argument without a value. It’s installed globally, so we just call it by a name. Let’s take a look at this ls (“list”) command. If in rush, go directly to the end of an article for the summary of CLI arguments rules.
#ULTRACOPIER COMMAND LINE ARGUMENTS HOW TO#
In this post, I analyze the anatomy of CLI arguments and point out how to read them in our own application. And there are so-called positional arguments – parameters given in some order without any extra indications. There are, of course, arguments with values.

There are flags, that are just switches changing command behavior. Many of the scripts and executables allow providing some command line arguments.
