Adding a first iteration for a CLI named noid
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
from noid import Minter
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(prog="noid", description="Generate noid, archival persistent identifiers")
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
new_sp = subparsers.add_parser("new")
|
||||
new_sp.add_argument("name")
|
||||
new_sp.add_argument("template")
|
||||
mint_sp = subparsers.add_parser("mint")
|
||||
mint_sp.add_argument("name")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
match args.command:
|
||||
case "new":
|
||||
minter = Minter()
|
||||
if (total := minter.parse_template(args.template)) > 0:
|
||||
minter.initcounters()
|
||||
print(f"The minter is ready. {total} noid are ready to be minted.")
|
||||
else:
|
||||
print("Someting happened, probably a problem with the template: {args.template}")
|
||||
minter.store(f"{args.name}.noid")
|
||||
case "mint":
|
||||
minter = Minter.load(f"{args.name}.noid")
|
||||
print(minter)
|
||||
print(f"New noid: {minter.genid()}")
|
||||
minter.store(f"{args.name}.noid")
|
||||
case _:
|
||||
parser.print_help()
|
||||
|
||||
Reference in New Issue
Block a user