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