Skip to content

Commit

Permalink
Polish casing, option description, and YargsCheckErrors across CLIs a…
Browse files Browse the repository at this point in the history
…nd commands (#68)
  • Loading branch information
zeyadkhaled authored Feb 15, 2024
1 parent 96085fa commit a58955a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 15 deletions.
6 changes: 6 additions & 0 deletions packages/cli/changelog/@unreleased/pr-68.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Polish casing, option description, and YargsCheckErrors across CLIs
and commands
links:
- https://github.com/palantir/osdk-ts/pull/68
1 change: 1 addition & 0 deletions packages/cli/src/commands/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const site: yargs.CommandModule<CliCommonArgs, CommonAuthArgs> = {
type: "string",
demandOption: true,
alias: "baseUrl", // for backwards compatibility
describe: "URL for the Foundry stack",
},
})
.command(login)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/auth/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const command: CommandModule<
alias: "applicationId", // for backwards compatibility
type: "string",
demandOption: true,
describe: "OAuth client ID for application",
});
},
handler: async (args) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/commands/site/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
SiteConfig,
} from "../../../util/config.js";
import configLoader from "../../../util/configLoader.js";
import { isValidSemver } from "../../../util/isValidSemver.js";
import { YargsCheckError } from "../../../YargsCheckError.js";
import type { CommonSiteArgs } from "../CommonSiteArgs.js";
import { logDeployCommandConfigFileOverride } from "./logDeployCommandConfigFileOverride.js";
Expand Down Expand Up @@ -98,6 +99,12 @@ const command: CommandModule<
);
}

if (args.version != null && !isValidSemver(args.version)) {
throw new YargsCheckError(
`--version "${args.version}" must be a valid SemVer string`,
);
}

const autoVersionType = args.autoVersion ?? autoVersion;
if (autoVersionType !== "git-describe") {
throw new YargsCheckError(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
...foundryUrl
? { default: foundryUrl }
: { demandOption: true },
description: "Foundry URL including protocol",
description: "URL for the Foundry stack",
},
token: {
type: "string",
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/commands/typescript/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import type { CommandModule } from "yargs";
import { isValidSemver } from "../../../util/isValidSemver.js";
import { YargsCheckError } from "../../../YargsCheckError.js";
import type { TypescriptGenerateArgs } from "./TypescriptGenerateArgs.js";

export const command: CommandModule<
Expand All @@ -40,16 +41,15 @@ export const command: CommandModule<
conflicts: ["foundryUrl", "clientId"],
},
foundryUrl: {
description:
"The URL to the foundry stack that contains the ontology",
description: "URL for the foundry stack that contains the ontology",
type: "string",
demandOption: false,
conflicts: "ontologyPath",
implies: "clientId",
alias: "stack", // for backwards compatibility
},
clientId: {
description: "The application's client id",
description: "OAuth client ID for application",
type: "string",
demandOption: false,
conflicts: "ontologyPath",
Expand Down Expand Up @@ -86,14 +86,14 @@ export const command: CommandModule<
.check(
(args) => {
if (!args.ontologyPath && !args.foundryUrl) {
throw new Error(
"Error: Must specify either ontologyPath or foundryUrl and clientId",
throw new YargsCheckError(
"Must specify either ontologyPath or foundryUrl and clientId",
);
}

if (args.version !== "dev" && !isValidSemver(args.version)) {
throw new Error(
"Error: Version must be 'dev' or a valid semver version",
throw new YargsCheckError(
"Version must be 'dev' or a valid semver version",
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { createClientContext, createOpenApiRequest } from "@osdk/shared.net";
import { consola } from "consola";
import * as fs from "node:fs";
import { YargsCheckError } from "../../../YargsCheckError.js";
import invokeLoginFlow from "../../auth/login/loginFlow.js";
import type { TypescriptGenerateArgs } from "./TypescriptGenerateArgs.js";

Expand All @@ -38,7 +39,9 @@ export default async function handleGenerate(args: TypescriptGenerateArgs) {
} else if (args.foundryUrl && args.clientId) {
success = await generateFromStack(args);
} else {
throw new Error("Must have specified ontologyPath or stack and clientId");
throw new YargsCheckError(
"Must have specified ontologyPath or stack and clientId",
);
}

if (success) {
Expand Down
6 changes: 6 additions & 0 deletions packages/create-app/changelog/@unreleased/pr-68.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Polish casing, option description, and YargsCheckErrors across CLIs
and commands
links:
- https://github.com/palantir/osdk-ts/pull/68
13 changes: 7 additions & 6 deletions packages/create-app/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface CliArgs {
export async function cli(args: string[] = process.argv) {
const base: Argv<CliArgs> = yargs(hideBin(args))
.version(process.env.PACKAGE_VERSION ?? "")
.wrap(Math.min(150, yargs().terminalWidth()))
.strict()
.help()
.command(
Expand All @@ -76,15 +77,15 @@ export async function cli(args: string[] = process.argv) {
type: "string",
describe: "Template name to use",
})
.option("foundry-url", {
.option("foundryUrl", {
type: "string",
describe: "URL for the Foundry stack",
})
.option("application-url", {
.option("applicationUrl", {
type: "string",
describe: "URL the production application will be hosted on",
})
.option("skip-application-url", {
.option("skipApplicationUrl", {
type: "boolean",
describe:
"Skip filling in URL the production application will be hosted on",
Expand All @@ -93,15 +94,15 @@ export async function cli(args: string[] = process.argv) {
type: "string",
describe: "Application resource identifier (rid)",
})
.option("client-id", {
.option("clientId", {
type: "string",
describe: "OAuth client ID for application",
})
.option("osdk-package", {
.option("osdkPackage", {
type: "string",
describe: "OSDK package name for application",
})
.option("osdk-registry-url", {
.option("osdkRegistryUrl", {
type: "string",
describe: "URL for NPM registry to install OSDK package",
}),
Expand Down

0 comments on commit a58955a

Please sign in to comment.