Philosophy about CLI app

Preamble

The CLI App stands for Command Line Interface App , which is the app used on the terminal. Perhaps those who are familiar with the system running on unix will be more familiar with CLI than those who are using window machines. The author is unix user, so the article will be based on concepts that are more or less familiar to those who have been using unix.

Philosophy about CLI app

Unix's built-in tools such as top, find … are all considered CLI apps. To find out how an app runs, you usually use the man command . For example, the result from the man of the top command is the command to find out the parameters related to the system used

Try some other commands like find or awk , you can see some very "homogeneous" features of the CLI app:

  • Only focus on one thing (shown by how always used is very short)
  • Can be used in an " intuitive " way (without much thought from the user)
  • Can link well with other CLI apps (via exporting output to stdout to be able to pipe)
  • Reasonably set default values
  • Can be installed easily (via binary)
  • Can "help" users when they type wrong commands (via help detail)

Standards

Screen Shot 2016-08-10 at 10.54.03 AM

Refer to the example above the grep statement, you can see that a regular CLI app has 3 parts

  • Executable : name binary / executable file to run the app
  • Options : Options (optional) that the app can receive
  • Arguments : The main values ​​that are indispensable for the app to handle

Options usually called flag. Perhaps you have used the CLI app familiarity to know that there is not only one type, there may be "2 bricks" (eg: -xy ), there may be "1 tile" (eg -xy ), yes There can be 2 tiles and there is no value (eg ). You will be confused and do not understand where those writing methods come from.

There is a norm (or more correctly recommended rules) from GNU and POSIX that stipulate the "style" and "meaning" of flags for the CLI app located at:

These standards can be summarized, including

  • The argument is an option (maybe, maybe not) if it starts with
  • Multiple options can be combined (eg -abc will be equivalent to -a -b -c )
  • Option name should be an abc letter
  • Option and argument of that option can be consecutive (eg -o foo and -ofoo are one)
  • Use 2 separate dashes to stop the parse option again. All of the following characters even starting with a dash are not considered options
  • Options can be in any order
  • Use 2 dashes for options with long names (eg –name = value )

Conclude

Maybe a bit of the theory above is enough for you to write a "good" CLI for yourself and for others: D.

Happy hacking

Huydx writer

ITZone via kipalog

Share the news now