0

I am making a Linux application which synchronizes the User's Desktop data with the cloud. I made a python executable file clouddrive which can launch the application. I copied this file into /usr/local/bin. Now, If I type clouddrive on the terminal, then it opens the application. But I want to add some arguments to that command. Suppose If user type clouddrive --logout, then the user should be logged out. If user type clouddrive --preferences, then preferences panel should be opened. I want to know that how can I add these arguments to that command?

Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
PRATEEK AGRAWAL
  • 319
  • 1
  • 5
  • 17
  • 1
    Possible duplicate of [simple argparse example wanted: 1 argument, 3 results](https://stackoverflow.com/questions/7427101/simple-argparse-example-wanted-1-argument-3-results) – Tom Karzes Oct 11 '17 at 09:35
  • Possible duplicate of [How to read/process command line arguments?](https://stackoverflow.com/questions/1009860/how-to-read-process-command-line-arguments) – Andrejs Cainikovs Oct 11 '17 at 09:42

1 Answers1

3

Use argparse module.

Example:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("echo", help="echo the string you use here")
args = parser.parse_args()
print args.echo

Result:

$ python prog.py -h
usage: prog.py [-h] echo

positional arguments:
  echo        echo the string you use here

optional arguments:
  -h, --help  show this help message and exit
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95