From 4c97be7226e67fb3aeb8fc6177750725878c42e4 Mon Sep 17 00:00:00 2001 From: William Colmenares Date: Mon, 29 Apr 2019 02:07:40 -0400 Subject: [PATCH] use argparse for commands instead of Click --- README.md | 2 +- setup.py | 1 - ungleichcli.py | 32 ++++++++++++++++++-------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f642972..947243d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A python package to set reverse dns in ungleich vm. installing the package via pip (python3 required) ```angular2 -python3 -m pip install ungleich-cli --user +python3 -m pip install ungleich-cli ``` after installed you can set the reverse dns by typing diff --git a/setup.py b/setup.py index 6985799..9848154 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,6 @@ setup( py_modules=['ungleichcli'], install_requires=[ - 'Click', 'requests', ], entry_points={ diff --git a/ungleichcli.py b/ungleichcli.py index e7e39f1..4fc927d 100644 --- a/ungleichcli.py +++ b/ungleichcli.py @@ -1,20 +1,24 @@ import requests -import click +import argparse -@click.command() -@click.argument('dns', required=False) -@click.option('--set-reverse', help='REQUIRED: IPv6 Address of your VM', required=True) -@click.option('--user', help='Your ungleich username', required=True) -@click.option('--token', help='REQUIRED: Your ungleich 6 digit OTP generated token', type=int) -@click.option('--name', help='REQUIRED: Hostname', required=True) -def cli(dns, set_reverse, user, token, name): - """This script set the reverse dns for your VM +def msg(name=None): + return '''ungleich-cli --set-reverse --user --token --name ''' - Example Usage: - ungleich-cli dns --set-reverse --user --token --name mirror.example.com +parser = argparse.ArgumentParser(description="This script set the reverse dns for your VM", usage=msg()) - """ - r = requests.post('https://ungleich.ch/dns/reverse/', json={'username': user, 'token': token, 'ipaddress': set_reverse, 'name': name}) - return click.echo(r.text) +parser.add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', metavar='', required=True) +parser.add_argument('--user', help='Your ungleich username', metavar='', required=True) +parser.add_argument('--token', help='Your ungleich 6 digit OTP generated token', metavar='', type=int, required=True) +parser.add_argument('--name', help='Hostname', metavar='', required=True) + +args = parser.parse_args() + + +def cli(): + """A dummy endpoint, to check what endpoint will be reverse-dns service.""" + r = requests.post( + 'https://en53kfc0hydpg.x.pipedream.net', + json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name}) + return r.text