-
Notifications
You must be signed in to change notification settings - Fork 1
feat(create-db): Add --ttl, --copy, --quiet, and --open to create-db CLI
#78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd7853b
feat(create-db): add ttl/copy/quiet/open flags with clearer ttl
aidankmcalister 17f33fc
updated package-lock
aidankmcalister 870f41b
version bumps to `1.2.0` from `1.1.4`
aidankmcalister e1d9279
chore(docs): apply coderabbit comments
aidankmcalister ede9789
ttl fixed and added to programmatic import
aidankmcalister 1fc5e84
chore(create-db): coderabbit comments applied
aidankmcalister 29fba37
chore(create-db): update readme table
aidankmcalister f3143b8
refactor(create-db): validate ttl via zod schema
AmanVarshney01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { parseTtlToSeconds } from "../src/utils/ttl.js"; | ||
|
|
||
| describe("parseTtlToSeconds", () => { | ||
| it("parses supported ttl values", () => { | ||
| expect(parseTtlToSeconds("30m")).toBe(1800); | ||
| expect(parseTtlToSeconds("1h")).toBe(3600); | ||
| expect(parseTtlToSeconds("6h")).toBe(21600); | ||
| expect(parseTtlToSeconds("24h")).toBe(86400); | ||
| }); | ||
|
|
||
| it("is case-insensitive", () => { | ||
| expect(parseTtlToSeconds("2H")).toBe(7200); | ||
| expect(parseTtlToSeconds("24H")).toBe(86400); | ||
| }); | ||
|
|
||
| it("rejects values outside the allowed range", () => { | ||
| expect(parseTtlToSeconds("")).toBeNull(); | ||
| expect(parseTtlToSeconds("0h")).toBeNull(); | ||
| expect(parseTtlToSeconds("25h")).toBeNull(); | ||
| expect(parseTtlToSeconds("7d")).toBeNull(); | ||
| expect(parseTtlToSeconds("45s")).toBeNull(); | ||
| expect(parseTtlToSeconds("abc")).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,39 @@ | ||
| import { createDbCli } from "./index.js"; | ||
|
|
||
| createDbCli().run(); | ||
| type OptionLike = { | ||
| flags?: string; | ||
| long?: string; | ||
| }; | ||
|
|
||
| type CommandLike = { | ||
| options?: OptionLike[]; | ||
| commands?: CommandLike[]; | ||
| }; | ||
|
|
||
| function simplifyHelpFlags(command: CommandLike) { | ||
| for (const option of command.options ?? []) { | ||
| if (!option.flags) { | ||
| continue; | ||
| } | ||
|
|
||
| option.flags = option.flags | ||
| .replace(" [boolean]", "") | ||
| .replace(" [string]", " [value]") | ||
| .replace(" <string>", " <value>"); | ||
|
|
||
| if (option.long === "--ttl" || option.flags.includes("--ttl")) { | ||
| option.flags = option.flags | ||
| .replace("<value>", "<duration>") | ||
| .replace("[value]", "[duration]"); | ||
| } | ||
| } | ||
|
|
||
| for (const subcommand of command.commands ?? []) { | ||
| simplifyHelpFlags(subcommand); | ||
| } | ||
| } | ||
|
|
||
| const cli = createDbCli(); | ||
| const program = cli.buildProgram() as unknown as CommandLike; | ||
| simplifyHelpFlags(program); | ||
| void cli.run(undefined, program as never); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.