Some command-line tools under Linux can “complete at multiple levels”. How is this done? (cmd sub-cmd options)

  linux, question

[Description]
Some can, some cannot
Yes: Yessub-cmd,options,--The beginning, and others

How did it happen?

Take CentOS for example. Bash used by the Shell here is stored in/etc/bash_completion.d/Under the directory

# ls -al /etc/bash_completion.d/
 total 136
 drwxr-xr-x.  2 root root  4096 Jul 21  2015 .
 drwxr-xr-x. 78 root root  4096 Mar 14 15:31   ..
 -rw-r--r--.  1 root root  2379 Nov 11  2010 bzr
 -rwxr-xr-x   1 root root   935 Oct 16  2014 gdbus-bash-completion.sh
 -rw-r--r--.  1 root root 45281 Mar  5  2013 git
 -rw-r--r--.  1 root root 11481 Aug 23  2010 mercurial.sh
 -rw-r--r--   1 root root 39423 May 26  2009 subversion
 -rw-r--r--.  1 root root  8031 Jun 22  2012 yum-utils.bash
 -rw-r--r--.  1 root root 10082 Dec 17  2013 yum.bash