Autocomplete command line arguments.

Use bashrc for sudo autocomplete (argcomplete issue num. 65 on GitHub).

refs: #4454

Change-Id: I4d46cba20d2f046878063e45615c9a8eab41ba5a
diff --git a/INSTALL.md b/INSTALL.md
index e908a8b..69de126 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -12,11 +12,11 @@
 
 If you have all the dependencies (see sections below) installed simply clone this repository and run:
 
-    sudo ./install.sh -i
+    ./install.sh -i
 
 else if you don't have the dependencies, the following command will install them along with Mini-NDN:
 
-    sudo ./install.sh -a
+    ./install.sh -a
 
 else if you want to install the dependencies manually, follow the instructions below:
 
diff --git a/bin/minindn b/bin/minindn
index 84b08d8..2061c73 100755
--- a/bin/minindn
+++ b/bin/minindn
@@ -89,6 +89,11 @@
 from ndn.nlsr import Nlsr, NlsrConfigGenerator
 from ndn.nfd import Nfd
 
+try:
+    import argcomplete
+except ImportError:
+    pass
+
 VERSION_NUMBER = "0.3.0"
 INSTALL_DIR='/usr/local/etc/mini-ndn/'
 
@@ -145,7 +150,7 @@
         os.makedirs(resultDir)
     else:
         print("Results directory (%s) already exists!" % resultDir)
-        sys.exit(1);
+        sys.exit(1)
 
     print("Results will be stored at: %s" % resultDir)
     return resultDir
@@ -160,11 +165,11 @@
     parser.add_argument("--ctime", type=int, default=60,
                         help="Specify convergence time for the topology (Default: 60 seconds)")
 
-    parser.add_argument("--experiment",
+    parser.add_argument("--experiment", choices=[experiment for experiment in ExperimentManager.getExperimentNames()],
                         help="Runs the specified experiment")
 
     parser.add_argument("--faces", type=int, default=3,
-                        help="Specify number of faces 0-60")
+                        help="Specify number of max faces per prefix for NLSR 0-60")
 
     parser.add_argument("--routing", dest="routingType", default='link-state', choices=['link-state', 'hr', 'dry'],
                         help="""choices for routing are 'link-state' for link state, 'hr' for hyperbolic, and 'dry'
@@ -219,6 +224,9 @@
     parser.add_argument("--cs-size", dest='csSize', type=int, default=65536,
                         help="Set CS size in NFD's conf file")
 
+    if "argcomplete" in sys.modules:
+        argcomplete.autocomplete(parser)
+
     args, unknownArgs = parser.parse_known_args()
 
     unknownArgsList = []
diff --git a/docs/GETTING-STARTED.md b/docs/GETTING-STARTED.md
index 12912e4..d15e95f 100644
--- a/docs/GETTING-STARTED.md
+++ b/docs/GETTING-STARTED.md
@@ -61,6 +61,8 @@
 
     sudo minindn --work-dir /home/mydir/test
 
+Autocomplete of command-line options is available for users of Bash and Zsh.
+
 #### Routing options
 
 To run minindn without NLSR, use the `--no-nlsr` parameter:
diff --git a/install.sh b/install.sh
index 9a331a8..a22e22d 100755
--- a/install.sh
+++ b/install.sh
@@ -303,6 +303,24 @@
     cd ..
 }
 
+function argcomplete {
+    if [[ $SHELL == "/bin/bash" ]]; then
+        $install python-argcomplete
+        if ! grep -q 'eval "$(register-python-argcomplete minindn)"' ~/.bashrc; then
+            echo 'eval "$(register-python-argcomplete minindn)"' >> ~/.bashrc
+        fi
+        source ~/.bashrc
+    elif [[ $SHELL == "/bin/zsh" ]] || [[ $SHELL == "/usr/bin/zsh" ]]; then
+        $install python-argcomplete
+        if ! grep -z -q 'autoload bashcompinit\sbashcompinit\seval "$(register-python-argcomplete minindn)"' ~/.zshrc; then
+            echo -e 'autoload bashcompinit\nbashcompinit\neval "$(register-python-argcomplete minindn)"' >> ~/.zshrc
+        fi
+        source ~/.zshrc
+    else
+        echo "Skipping argomplete install..."
+    fi
+}
+
 function commonClientLibraries {
     ndn_cpp
     pyNDN
@@ -315,6 +333,7 @@
 
     printf 'options:\n' >&2
     printf -- ' -a: install all the required dependencies\n' >&2
+    printf -- ' -b: install autocomplete for Bash and Zsh users\n' >&2
     printf -- ' -e: install infoedit\n' >&2
     printf -- ' -f: install NFD\n' >&2
     printf -- ' -i: install mini-ndn\n' >&2
@@ -328,7 +347,7 @@
 if [[ $# -eq 0 ]]; then
     usage
 else
-    while getopts 'aemfrtic' OPTION
+    while getopts 'abemfrtic' OPTION
     do
         case $OPTION in
         a)
@@ -338,9 +357,11 @@
         routing
         tools
         infoedit
+        argcomplete
         commonClientLibraries
         break
         ;;
+        b)    argcomplete;;
         e)    infoedit;;
         f)    forwarder;;
         i)    minindn;;
@@ -352,4 +373,4 @@
         esac
     done
     shift $(($OPTIND - 1))
-fi
+fi
\ No newline at end of file