Add a qint tool
This commit is contained in:
parent
b49d0b4d40
commit
1d028bbfbf
3 changed files with 44 additions and 0 deletions
|
@ -4,3 +4,14 @@ py_project(
|
||||||
py_requirement("hypothesis"),
|
py_requirement("hypothesis"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
zapp_binary(
|
||||||
|
name = "qint",
|
||||||
|
main = "src/python/proquint/__main__.py",
|
||||||
|
imports = [
|
||||||
|
"src/python",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":proquint",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
33
projects/proquint/src/python/proquint/__main__.py
Normal file
33
projects/proquint/src/python/proquint/__main__.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
"""A CLI program for interacting with proquints."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from secrets import randbits
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from proquint import Proquint
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
g = parser.add_mutually_exclusive_group()
|
||||||
|
g.add_argument("-g", "--generate", dest="generate", default=False, action="store_true")
|
||||||
|
g.add_argument("-p", "--predictable", dest="predictable", default=False, action="store_true")
|
||||||
|
g.add_argument("-d", "--decode", dest="decode", default=False, action="store_true")
|
||||||
|
g.add_argument("-e", "--encode", dest="encode", default=False, action="store_true")
|
||||||
|
parser.add_argument("-w", "--width", dest="width", type=int, default=32)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
opts, args = parser.parse_known_args()
|
||||||
|
|
||||||
|
if opts.generate:
|
||||||
|
print(Proquint.encode(randbits(opts.width), opts.width))
|
||||||
|
elif opts.predictable:
|
||||||
|
print(Proquint.encode(uuid.getnode(), 32))
|
||||||
|
elif opts.encode:
|
||||||
|
print(Proquint.encode(int(args[0]), opts.width))
|
||||||
|
elif opts.decode:
|
||||||
|
print(Proquint.decode(args[0]))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue