Skip to content

Commit

Permalink
feat: rename a otp name
Browse files Browse the repository at this point in the history
  • Loading branch information
x-ray-s committed May 14, 2024
1 parent 6056f00 commit af1bf00
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "2fa-cmd",
"version": "0.0.3",
"version": "0.0.4",
"description": "A command tool for Google Authenticator",
"author": "x-ray-s",
"email": "[email protected]",
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $ 2fa --help
verify - verify a token
import - Import a secret from url
rename - Rename
get - get one otp
Options
--name <The name of the secret>
Expand All @@ -41,11 +42,13 @@ $ 2fa --help
Examples
$ 2fa
$ 2fa add --name github --secret FCRJQZSGFD3VMZDE
$ 2fa remove --name github
$ 2fa verify --name github --token 643223
$ 2fa add --name <name> --secret FCRJQZSGFD3VMZDE
$ 2fa remove --name <name>
$ 2fa verify --name <name> --token 643223
$ 2fa import --url 'otpauth://totp/...'
$ 2fa rename --name <old> <new>
$ 2fa rename <old> --name <new>
$ 2fa get --name <name>
$ 2fa --name <name> // same as get
```

## TODO
Expand Down
33 changes: 29 additions & 4 deletions source/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import App from './app.js';
import chalk from 'chalk';
import {decode} from './import.js';
import {add, remove, has, find, importGA, rename} from './storage.js';
import {verify} from './2fa.js';
import {verify, generate} from './2fa.js';
const cli = meow(
`
Usage
Expand All @@ -26,11 +26,13 @@ const cli = meow(
Examples
$ 2fa
$ 2fa add --name github --secret FCRJQZSGFD3VMZDE
$ 2fa remove --name github
$ 2fa verify --name github --token 643223
$ 2fa add --name <name> --secret FCRJQZSGFD3VMZDE
$ 2fa remove --name <name>
$ 2fa verify --name <name> --token 643223
$ 2fa import --url 'otpauth://totp/...'
$ 2fa rename <old> --name <new>
$ 2fa find --name <name>
$ 2fa --name <name>
`,
{
importMeta: import.meta,
Expand Down Expand Up @@ -123,6 +125,29 @@ const setError = (msg: string) => {
await rename(old, name);
return process.exit(0);
}

if (cli.input.includes('get')) {
if (!name) {
setError('When get a OTP, name is required');
return process.exit(1);
}
const item = await find(name);
if (!item) {
setError('This name is not found');
return process.exit(1);
}
console.log(generate(item.secret).token);
return process.exit(0);
}
if (cli.input.length === 0 && name) {
const item = await find(name);
if (!item) {
setError('This name is not found');
return process.exit(1);
}
console.log(generate(item.secret).token);
return process.exit(0);
}
})();

const {clear} = render(<App />, {
Expand Down

0 comments on commit af1bf00

Please sign in to comment.