Skip to content

Commit

Permalink
Added limited choices to add command
Browse files Browse the repository at this point in the history
  • Loading branch information
ieedan committed Sep 7, 2024
1 parent 0e80c0f commit 3d6bec2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ npx ts-blocks init

## Setup

Run the `init` command to setup the path where the blocks will be added.
Run the `init` command to setup the `blocks.json` file.

```bash
npx ts-blocks init
Expand All @@ -21,6 +21,8 @@ npx ts-blocks add result

┌ ts-block
◇ Added result
└ All done!
```

Expand Down
2 changes: 1 addition & 1 deletion build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({
entries: [
"src/index",
"src/blocks",
"src/commands/add",
"src/commands/init",
"src/commands/index",
"src/blocks",
"src/config/index",
],
failOnWarn: false,
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
"name": "ts-blocks",
"description": "A CLI to add ts-blocks code to your project.",
"version": "0.0.1",
"author": "",
"repository": {
"type": "git",
"url": "git+https://github.com/ieedan/ts-blocks"
},
"keywords": ["changelog", "date"],
"author": "Aidan Bleser",
"license": "MIT",
"bugs": {
"url": "https://github.com/ieedan/ts-blocks/issues"
},
"homepage": "https://github.com/ieedan/ts-blocks",
"main": "bin.mjs",
"bin": "./bin.mjs",
"type": "module",
Expand All @@ -23,8 +33,6 @@
"ci:release": "unbuild && changeset publish",
"changeset": "changeset"
},
"keywords": [],
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/node": "^22.5.4",
Expand Down
9 changes: 7 additions & 2 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
spinner,
} from "@clack/prompts";
import color from "chalk";
import { Command, program } from "commander";
import { Argument, Command, program } from "commander";
import { Project, type SourceFile } from "ts-morph";
import { type InferInput, boolean, object, parse } from "valibot";
import { WARN } from ".";
Expand All @@ -23,7 +23,12 @@ const schema = object({
type Options = InferInput<typeof schema>;

const add = new Command("add")
.argument("[blocks...]", "Whichever block you want to add to your project.")
.addArgument(
new Argument(
"[blocks...]",
"Whichever block you want to add to your project.",
).choices(Object.entries(blocks).map(([key]) => key)),
)
.option("-y, --yes", "Add and install any required dependencies.", false)
.action(async (blockNames, opts) => {
const options = parse(schema, opts);
Expand Down

0 comments on commit 3d6bec2

Please sign in to comment.