jaklis new
This commit is contained in:
parent
319447f332
commit
a71c68e75e
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse, sys, os, random, string, getpass
|
import argparse, sys, os, random, string, getpass, json
|
||||||
from os.path import join, dirname
|
from os.path import join, dirname
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
@ -17,12 +17,12 @@ dotenv_path = join(dirname(__file__), '.env')
|
||||||
load_dotenv(dotenv_path)
|
load_dotenv(dotenv_path)
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser(description="Client CLI pour Cesium+ et Ḡchange")
|
||||||
parser.add_argument('-v', '--version', action='store_true', help="Affiche la version actuelle du programme")
|
parser.add_argument('-v', '--version', action='store_true', help="Affiche la version actuelle du programme")
|
||||||
parser.add_argument('-k', '--key', help="Chemin vers mon trousseau de clé (PubSec)")
|
parser.add_argument('-k', '--key', help="Chemin vers mon trousseau de clé (PubSec)")
|
||||||
parser.add_argument('-n', '--node', help="Adresse du noeud Cesium+ ou Gchange à utiliser")
|
parser.add_argument('-n', '--node', help="Adresse du noeud Cesium+ ou Gchange à utiliser")
|
||||||
|
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers(title="Commandes de jaklis", dest="cmd")
|
||||||
read_cmd = subparsers.add_parser('read', help="Lecture des messages")
|
read_cmd = subparsers.add_parser('read', help="Lecture des messages")
|
||||||
send_cmd = subparsers.add_parser('send', help="Envoi d'un message")
|
send_cmd = subparsers.add_parser('send', help="Envoi d'un message")
|
||||||
delete_cmd = subparsers.add_parser('delete', help="Supression d'un message")
|
delete_cmd = subparsers.add_parser('delete', help="Supression d'un message")
|
||||||
|
@ -32,19 +32,6 @@ eraseProfile_cmd = subparsers.add_parser('erase', help="Effacer son profile Cesi
|
||||||
like_cmd = subparsers.add_parser('like', help="Voir les likes d'un profile / Liker un profile (option -s NOTE)")
|
like_cmd = subparsers.add_parser('like', help="Voir les likes d'un profile / Liker un profile (option -s NOTE)")
|
||||||
unlike_cmd = subparsers.add_parser('unlike', help="Supprimer un like")
|
unlike_cmd = subparsers.add_parser('unlike', help="Supprimer un like")
|
||||||
|
|
||||||
if sys.argv[1] in ('-k','-n'):
|
|
||||||
if sys.argv[3] in ('-k','-n'):
|
|
||||||
cmd = sys.argv[5]
|
|
||||||
else:
|
|
||||||
cmd = sys.argv[3]
|
|
||||||
else:
|
|
||||||
cmd = sys.argv[1]
|
|
||||||
|
|
||||||
if len(sys.argv) <= 1 or not cmd in ('read','send','delete','set','get','erase','like','unlike','-v','--version'):
|
|
||||||
sys.stderr.write("Veuillez indiquer une commande valide:\n\n")
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Messages management
|
# Messages management
|
||||||
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
|
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
|
||||||
read_cmd.add_argument('-j', '--json', action='store_true', help="Sort au format JSON")
|
read_cmd.add_argument('-j', '--json', action='store_true', help="Sort au format JSON")
|
||||||
|
@ -77,6 +64,11 @@ like_cmd.add_argument('-s', '--stars', type=int, help="Nombre d'étoile")
|
||||||
unlike_cmd.add_argument('-p', '--profile', help="Profile à déliker")
|
unlike_cmd.add_argument('-p', '--profile', help="Profile à déliker")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
cmd = args.cmd
|
||||||
|
|
||||||
|
if not cmd:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
print(VERSION)
|
print(VERSION)
|
||||||
|
@ -172,4 +164,3 @@ elif cmd == "unlike":
|
||||||
|
|
||||||
if keyPath:
|
if keyPath:
|
||||||
os.remove(keyPath)
|
os.remove(keyPath)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue