DEV Community

Sadhan Sarker
Sadhan Sarker

Posted on

Python Custom CLI Guide

CLI Implementation Guide

1.Step: Create inktechs package

create 'init.py' file. it should be empty,
Now, create __main__.py file

def main():
    print('Hello! from inktechs cli')

if __name__ == '__main__':
    main()
Enter fullscreen mode Exit fullscreen mode

2.Step: Then, create setup.py file and define meta for your CLI

from setuptools import setup

setup(
    name='inktechs-cli',
    version='0.1.0',
    packages=['inktechs'],
    author="Md. Sadhan Sarker",
    author_email="cse.sadhan@gmail.com",
    description="This is an Example Package",
    keywords="keyword1 keyword2",
    entry_points={
        'console_scripts': [
            'inktechs = inktechs.__main__:main'
        ]
    })

Enter fullscreen mode Exit fullscreen mode

3.finally create install.sh file

pip install -e .
Enter fullscreen mode Exit fullscreen mode

4.Now, Run CLI, hit your package name from terminal

inktechs -c ./home/file.conf --o ./home/text.file
Enter fullscreen mode Exit fullscreen mode

Output: like below

Hello! from inktechs cli

Update configuration as following: ./home/file.conf

Generate output as following ./home/text.file
Enter fullscreen mode Exit fullscreen mode

5.If you want to uninstall package, base on your cli package name

pip uninstall inktechs-cli
Enter fullscreen mode Exit fullscreen mode




Source Code:

References

Top comments (0)