Skip to content

Instantly share code, notes, and snippets.

@stenwire
Last active November 12, 2022 19:45
Show Gist options
  • Save stenwire/d524934fdd64519088ab58c47f8a97d9 to your computer and use it in GitHub Desktop.
Save stenwire/d524934fdd64519088ab58c47f8a97d9 to your computer and use it in GitHub Desktop.
POD-CLI_sample(HNG)

POD-CLI_sample

A cli utility made with click library

To setup app

pip install virtualenv

python -m venv venv

./venv/Script/activate

pip install click

make sure you're in the app dirrectory where the setup script is located.

pip install --editable .

Available commands

  • pod-cli-reg
  • pod-cli-bio
  • pod-cli-initdb
  • pod-cli-startapp
"""
A basic cli app with click library
Click documentation: https://click.palletsprojects.com/en/8.1.x/
"""
import click
@click.group()
def cli():
pass
@click.command()
def dropdb():
"""Just to illustrate operation that doesn't require any argument"""
click.echo('Dropped the database')
@click.command()
@click.option('-u', '--user', prompt='Your username', help='Your username')
@click.option('-p', '--pwd', prompt='Your password', help='password.')
def startapp(user, pwd):
"""Startapp as a user"""
click.echo('Initialized the CLI')
click.echo(f"Logged in as {user}!")
@click.command()
@click.option('-a', '--avatar', prompt='Your avatar', help='Your avatar')
@click.option('-n', '--name', prompt='Your name', help='The person to greet.')
def register(avatar, name):
"""Register Avatar"""
click.echo(f"Hello {name} with {avatar} avatar!")
@click.command()
@click.option('-c', '--color', prompt='Your complexion', help='Your complexion')
@click.option('-s', '--sex', prompt='Your sex', help='Your sex')
def add_bio(color, sex):
"""Add Bio"""
click.echo(f"Bio: {color} {sex}!")
# registering the commands
if __name__=='__main__':
cli.add_command(startapp)
cli.add_command(dropdb)
cli.add_command(register)
cli.add_command(add_bio)
cli()
from setuptools import setup
setup(
name='pod_cli',
version='0.1.0',
py_modules=['pod_cli'],
install_requires=[
'Click',
],
entry_points={
'console_scripts': [
'pod-cli-reg = pod_cli:register',
'pod-cli-bio = pod_cli:add_bio',
'pod-cli-dropdb = pod_cli:dropdb',
'pod-cli-startapp = pod_cli:startapp',
],
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment