jolausa

click python

Apr 28th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. root@3286ce0398c4:~/repos/tmp# vi yourscript.py
  2. root@3286ce0398c4:~/repos/tmp# ll
  3. total 20K
  4. -rw-r--r-- 1 root root 434 Apr 28 21:58 1
  5. -rw-r--r-- 1 root root 250 Apr 28 21:11 setup.py
  6. drwxr-xr-x 2 root root 4.0K Apr 28 21:12 yourscript.egg-info
  7. -rw-r--r-- 1 root root 612 Apr 28 22:16 yourscript.py
  8. -rw-r--r-- 1 root root 1.4K Apr 28 22:13 yourscript.pyc
  9. root@3286ce0398c4:~/repos/tmp# cat setup.py
  10.  
  11. from setuptools import setup
  12.  
  13. setup(
  14. name='yourscript',
  15. version='0.1',
  16. py_modules=['yourscript'],
  17. install_requires=[
  18. 'Click',
  19. ],
  20. entry_points='''
  21. [console_scripts]
  22. yourscript=yourscript:cli
  23. ''',
  24. )
  25. root@3286ce0398c4:~/repos/tmp# cat yourscript.
  26. cat: yourscript.: No such file or directory
  27. root@3286ce0398c4:~/repos/tmp# cat yourscript.py
  28. import click
  29.  
  30. CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
  31.  
  32. @click.group(context_settings=CONTEXT_SETTINGS)
  33. @click.version_option(version='opnfv colorado.0.1 ')
  34. def cli():
  35. pass
  36.  
  37.  
  38. @cli.command()
  39. def initdb():
  40. click.echo('Initialized the database')
  41.  
  42. @cli.command()
  43. def dropdb():
  44. click.echo('Dropped the database')
  45.  
  46. @cli.command()
  47. @click.argument('name')
  48. def hello(name):
  49. click.echo('Hello %s!' % name)
  50.  
  51. @cli.command()
  52. @click.argument('option', )
  53. def env(option):
  54. if option == show:
  55. click.echo("env show command")
  56. elif option == status:
  57. click.echo("env status command")
Advertisement
Add Comment
Please, Sign In to add comment