Skip to content

Commit

Permalink
fix: remove oclif alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
grant0417 committed Mar 11, 2024
1 parent 1e919e8 commit 370791d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 10 deletions.
4 changes: 2 additions & 2 deletions integrations/oclif/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fig/complete-oclif",
"description": "Generate Fig completion spec from oclif",
"version": "2.0.0",
"version": "2.0.1",
"author": "Matt Schrage @mattschrage",
"bugs": "https://github.com/withfig/autocomplete-tools/issues",
"dependencies": {
Expand Down Expand Up @@ -33,7 +33,7 @@
]
},
"scripts": {
"build": "tsc",
"build": "rm -rf lib && tsc",
"postpack": "rm -f oclif.manifest.json",
"prepack": "pnpm build && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md"
Expand Down
11 changes: 3 additions & 8 deletions integrations/oclif/src/commands/generate-fig-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getFigArgs(args: Command.Arg.Cached[]): Fig.Arg[] {
figArgs.push({
name: arg.name,
...(arg.description && { description: arg.description }),
...(arg.default && { default: arg.default }),
...(arg.default && { default: `${arg.default}` }),
...(arg.options?.length && { suggestions: arg.options }),
...(arg.required === false && { isOptional: true }),
});
Expand All @@ -27,7 +27,7 @@ function getFigOptions(options: Command.Flag.Cached[]): Fig.Option[] {
args: {
description: flag.helpValue,
...(flag.options?.length && { suggestions: flag.options }),
...(flag.default && { default: flag.default }),
...(flag.default && { default: `${flag.default}` }),
},
}),
...(flag.required === true && { isRequired: true }),
Expand All @@ -52,13 +52,8 @@ function getFigSubcommands(commands: Command.Loadable[]): Fig.Subcommand[] {
const options: Fig.Option[] = getFigOptions(Object.values(command.flags));
const args: Fig.Arg[] = getFigArgs(Object.values(command.args));

const name =
command.aliases.length > 0
? Array.from(new Set([command.id, ...command.aliases]))
: command.id;

subcommands.push({
name,
name: command.id,
...(command.description && { description: command.description }),
...(options.length && { options }),
...(args.length && { args }),
Expand Down
3 changes: 3 additions & 0 deletions zod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autocomplete Zod Validator

A Zod Validator for the Fig Spec format. This can be used to ensure
20 changes: 20 additions & 0 deletions zod/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "zod",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"author": "",
"license": "ISC",
"dependencies": {
"zod": "^3.22.4"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.3",
"@withfig/autocomplete-types": "workspace:^",
"typescript": "^5.3.3"
}
}
49 changes: 49 additions & 0 deletions zod/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as z from "zod";

type NotOptional<T> = {
[P in keyof T]-?: T[P] | undefined;
};

function singleOrArrayValidator<T>(t: z.ZodType<T>): z.ZodType<Fig.SingleOrArray<T>> {
return z.union([t, z.array(t)]);
}

export const baseSuggestionSchema: z.ZodType<Fig.BaseSuggestion> = z.object({
displayName: z.string().optional(),
insertValue: z.string().optional(),
replaceValue: z.string().optional(),
description: z.string().optional(),
icon: z.string().optional(),
isDangerous: z.boolean().optional(),
priority: z.number().optional(),
hidden: z.boolean().optional(),
deprecated: z.boolean().optional(),
previewComponent: z.string().optional(),
_internal: z.record(z.unknown()),
}) satisfies z.ZodType<Fig.BaseSuggestion>;

baseSubcommandSchema.

export const baseSubcommandSchema: z.ZodType<Fig.Subcommand> = baseSuggestionSchema.and(
z.object({
name: singleOrArrayValidator(z.string()),
requiresSubcommand: z.boolean().optional(),
filterStrategy: z.enum(["fuzzy", "prefix", "default"]),
cache: z.boolean().optional(),
})
) satisfies z.ZodType<NotOptional<Fig.Subcommand>>;

export const optionSchema: z.ZodType<Fig.Option> = z.object({
name: singleOrArrayValidator(z.string()),
isPersistent: z.boolean().optional(),
isRequired: z.boolean().optional(),
requiresEquals: z.boolean().optional(),
requiresSeparator: z.union([z.boolean(), z.string()]).optional(),
isRepeatable: z.union([z.boolean(), z.number()]).optional(),
exclusiveOn: z.array(z.string()).optional(),
dependsOn: z.array(z.string()).optional(),
}) satisfies z.ZodType<Fig.Option>;

export const argSchema: z.ZodType<Fig.Arg> = z.object({
name: z.string().optional(),
}) satisfies z.ZodType<Fig.Arg>;
10 changes: 10 additions & 0 deletions zod/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/recommended",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"types": ["@withfig/autocomplete-types"],
"outDir": "dist"
},
"exclude": ["node_modules/", "dist/", "test/"],
"include": ["./"]
}

0 comments on commit 370791d

Please sign in to comment.