aboutsummaryrefslogtreecommitdiff
path: root/cli.py
diff options
context:
space:
mode:
authorLena <lena@omega>2026-03-01 00:00:00 +0000
committerLena <lena@omega>2026-03-01 00:00:00 +0000
commit14c1e3039f80a2fc50194b4da13a4f9964b7a1b3 (patch)
tree3b28cb379bd19456cc166f48ec814c36fb0ecaa0 /cli.py
downloadotp-master.tar.gz
Enter otpHEADmaster
Authenticator codes from the terminal, stdlib only, no phone and no third-party dependency. Secrets are a private plain-text file, or the output of a command so encrypted stores work unchanged.
Diffstat (limited to 'cli.py')
-rwxr-xr-xcli.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/cli.py b/cli.py
new file mode 100755
index 0000000..2ab5369
--- /dev/null
+++ b/cli.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+
+import otp
+
+
+def main():
+ if len(sys.argv) > 2:
+ sys.exit("usage: cli.py [name]")
+ try:
+ entries = otp.load_entries()
+ if len(sys.argv) > 1:
+ name = sys.argv[1]
+ for n, key, period, digits, digest in entries:
+ if n == name:
+ print(otp.totp(key, period, digits, digest))
+ return
+ sys.exit(f"cli: no entry named {name!r}")
+ for name, key, period, digits, digest in entries:
+ print(name, otp.totp(key, period, digits, digest))
+ except otp.SecretsError as error:
+ print(f"cli: {error}", file=sys.stderr)
+ return error.status
+
+
+if __name__ == "__main__":
+ sys.exit(main())