From 6298b8463032dd899025282186cc562ec1a9daa8 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Mon, 3 Apr 2023 17:36:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20=F0=9F=91=94=20Add=20missing=20v?= =?UTF-8?q?ote=20subcommand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + voting/cli/voting.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4dd055f..aa21e24 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ $> voting --help │ new Create a new voting. │ │ rm Delete a voting. │ │ show Display the results of a voting. │ +│ vote Place a vote. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ $> voting new EXAMPLE_TITLE --quorum A:5 --voters a,b,c,d,e,f,g,h,i,j diff --git a/voting/cli/voting.py b/voting/cli/voting.py index 95c2d51..c8ffe57 100644 --- a/voting/cli/voting.py +++ b/voting/cli/voting.py @@ -1,7 +1,7 @@ import typer from arrow import get as arrow_get -from voting import Quorum, QuorumKind, Result, Voting +from voting import Quorum, QuorumKind, Result, Voting, Vote from voting.storage import Storage app = typer.Typer() @@ -82,3 +82,17 @@ def show(title: str, print(f"{vote} => {voting.votes[vote].name}") else: print(Result(voting)) + + +@app.command() +def vote(title: str, + vote: str = None, + voter: str = typer.Option("", "--voter", "-V", help="Name of the voter"), +): + """Place a vote.""" + with Storage() as store: + voting = store.pop(title) + if not Voting: + return + voting.vote(voter, Vote[vote]) + store.push(voting) \ No newline at end of file