Skip to content
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

Make site commands and docs options kebab-case #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/commands/site/CommonSiteArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ThirdPartyAppRid } from "../../net/ThirdPartyAppRid.js";

export interface CommonSiteArgs extends CliCommonArgs {
application: ThirdPartyAppRid;
foundryUrl: string;
"foundry-url": string;
"token-file"?: string;
token?: string;
tokenFile?: string;
}
6 changes: 3 additions & 3 deletions packages/cli/src/commands/site/deploy/SiteDeployArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { CommonSiteArgs } from "../CommonSiteArgs.js";
export interface SiteDeployArgs extends CommonSiteArgs {
version?: string;
directory: string;
uploadOnly: boolean;
autoVersion?: AutoVersionConfigType;
gitTagPrefix?: string;
"upload-only": boolean;
"auto-version"?: AutoVersionConfigType;
"git-tag-prefix"?: string;
}
20 changes: 10 additions & 10 deletions packages/cli/src/commands/site/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const command: CommandModule<
? { default: directory }
: { demandOption: true },
},
uploadOnly: {
"upload-only": {
type: "boolean",
description: "Upload new site version only without setting as live",
default: false,
Expand All @@ -57,10 +57,10 @@ const command: CommandModule<
type: "string",
description: "New version of site to deploy",
...autoVersion == null
? { conflicts: "autoVersion" }
? { conflicts: "auto-version" }
: {},
},
autoVersion: {
"auto-version": {
coerce: (autoVersion) => autoVersion as AutoVersionConfigType,
type: "string",
choices: ["git-describe"],
Expand All @@ -69,7 +69,7 @@ const command: CommandModule<
? { default: autoVersion.type }
: { conflicts: "version" },
},
gitTagPrefix: {
"git-tag-prefix": {
type: "string",
description:
"Prefix to match git tags on when 'git-describe' auto versioning is used. If not provided, all tags are matched and the prefix 'v' is stripped if present.",
Expand All @@ -79,37 +79,37 @@ const command: CommandModule<
},
})
.group(
["directory", "version", "uploadOnly"],
["directory", "version", "upload-only"],
"Deploy Options",
)
.group(
["autoVersion", "gitTagPrefix"],
["auto-version", "git-tag-prefix"],
"Auto Version Options",
)
.check((args) => {
// This is required because we can't use demandOption with conflicts. conflicts protects us against the case where both are provided.
// This is required because we can't use demandOption with conflicts. Conflicts protect us against the case where both are provided.
// So this case is for when nothing is provided.
if (
autoVersion == null && args.autoVersion == null
&& args.version == null
) {
throw new YargsCheckError(
"One of --version or --autoVersion must be specified",
"One of --version or --auto-version must be specified",
);
}

const autoVersionType = args.autoVersion ?? autoVersion;
if (autoVersionType !== "git-describe") {
throw new YargsCheckError(
`Only 'git-describe' is supported for autoVersion`,
`Only 'git-describe' is supported for --auto-version`,
);
}

const gitTagPrefixValue = args.gitTagPrefix ?? gitTagPrefix;
// Future proofing for when we support other autoVersion types
if (gitTagPrefixValue != null && autoVersionType !== "git-describe") {
throw new YargsCheckError(
`--gitTagPrefix is only supported when --autoVersion=git-describe`,
`--git-tag-prefix is only supported when --auto-version=git-describe`,
);
}

Expand Down
15 changes: 12 additions & 3 deletions packages/cli/src/commands/site/deploy/siteDeployCommand.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ import type { AutoVersionConfig } from "../../../util/config.js";
import { loadToken } from "../../../util/token.js";
import type { SiteDeployArgs } from "./SiteDeployArgs.js";

interface SiteDeployInternalArgs
extends Omit<SiteDeployArgs, "version" | "autoVersion">
interface SiteDeployInternalArgs extends
Omit<
SiteDeployArgs,
| "version"
| "autoVersion"
| "auto-version"
| "foundry-url"
| "token-file"
| "upload-only"
>
{
selectedVersion: string | AutoVersionConfig;
directory: string;
uploadOnly: boolean;
foundryUrl: string;
tokenFile?: string;
}

export default async function siteDeployCommand(
Expand Down
18 changes: 11 additions & 7 deletions packages/cli/src/commands/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import deploy from "./deploy/index.js";
import { logSiteCommandConfigFileOverride } from "./logSiteCommandConfigFileOverride.js";
import version from "./version/index.js";

const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
const command: CommandModule<
CliCommonArgs,
CommonSiteArgs
> = {
command: "site",
describe: "Manage your site",
builder: async (argv) => {
Expand All @@ -42,7 +45,7 @@ const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
: { demandOption: true },
description: "Application resource identifier (rid)",
},
foundryUrl: {
"foundry-url": {
coerce: (foundryUrl) => foundryUrl.replace(/\/$/, ""),
type: "string",
...foundryUrl
Expand All @@ -52,24 +55,25 @@ const command: CommandModule<CliCommonArgs, CommonSiteArgs> = {
},
token: {
type: "string",
conflicts: "tokenFile",
conflicts: "token-file",
description: "Foundry API token",
},
tokenFile: {
"token-file": {
type: "string",
conflicts: "token",
description: "Path to file containing Foundry API token",
},
})
.group(
["application", "foundryUrl", "token", "tokenFile"],
["application", "foundry-url", "token", "token-file"],
"Common Options",
)
.command(version)
.command(deploy)
.check((args) => {
if (!args.foundryUrl.startsWith("https://")) {
throw new YargsCheckError("foundryUrl must start with https://");
// Could also do args["foundry-url"] to not do the type assertion
if (!(args.foundryUrl as string).startsWith("https://")) {
throw new YargsCheckError("foundry-url must start with https://");
}
return true;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js";
import { loadToken } from "../../../../util/token.js";
import type { VersionDeleteArgs } from "./VersionDeleteArgs.js";

interface VersionDeleteInternalArgs extends
Omit<
VersionDeleteArgs,
"foundry-url" | "token-file"
>
{
foundryUrl: string;
tokenFile?: string;
}

export default async function versionDeleteCommand(
{ version, yes, application, foundryUrl, token, tokenFile }:
VersionDeleteArgs,
VersionDeleteInternalArgs,
) {
if (!yes) {
const confirmed = await consola.prompt(
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/commands/site/version/get/versionGetCommand.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ import { consola } from "consola";
import { loadToken } from "../../../../util/token.js";
import type { VersionGetArgs } from "./VersionGetArgs.js";

interface VersionGetInternalArgs extends
Omit<
VersionGetArgs,
"foundry-url" | "token-file"
>
{
foundryUrl: string;
tokenFile?: string;
}

export default async function versionGetCommand(
{ foundryUrl, application, token, tokenFile }: VersionGetArgs,
{ foundryUrl, application, token, tokenFile }: VersionGetInternalArgs,
) {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ import { colorize } from "consola/utils";
import { loadToken } from "../../../../util/token.js";
import type { VersionListArgs } from "./VersionListArgs.js";

interface VersionListInternalArgs
extends Omit<VersionListArgs, "foundry-url" | "token-file">
{
foundryUrl: string;
tokenFile?: string;
}

export default async function versionListCommand(
{ foundryUrl, application, token, tokenFile }: VersionListArgs,
{ foundryUrl, application, token, tokenFile }: VersionListInternalArgs,
) {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
Expand Down
13 changes: 12 additions & 1 deletion packages/cli/src/commands/site/version/set/versionSetCommand.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ import {
import { loadToken } from "../../../../util/token.js";
import type { VersionSetArgs } from "./VersionSetArgs.js";

interface VersionSetInternalArgs extends
Omit<
VersionSetArgs,
"foundry-url" | "token-file"
>
{
foundryUrl: string;
tokenFile?: string;
}

export default async function versionSetCommand(
{ version, application, foundryUrl, token, tokenFile }: VersionSetArgs,
{ version, application, foundryUrl, token, tokenFile }:
VersionSetInternalArgs,
) {
consola.start(`Setting live version`);
const loadedToken = await loadToken(token, tokenFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ import { handlePromptCancel } from "../../../../consola/handlePromptCancel.js";
import { loadToken } from "../../../../util/token.js";
import type { VersionUnsetArgs } from "./VersionUnsetArgs.js";

interface VersionUnsetInternalArgs extends
Omit<
VersionUnsetArgs,
"foundry-url" | "token-file"
>
{
foundryUrl: string;
tokenFile?: string;
}

export default async function versionUnsetCommand(
{ yes, application, foundryUrl, token, tokenFile }: VersionUnsetArgs,
{ yes, application, foundryUrl, token, tokenFile }: VersionUnsetInternalArgs,
) {
if (!yes) {
const confirmed = await consola.prompt(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function loadToken(
if (tokenFile) {
const loadedToken = await loadTokenFile(tokenFile);
consola.debug(
`Using token from --tokenFile=${loadedToken.filePath} option`,
`Using token from --token-file=${loadedToken.filePath} option`,
);
validate(loadedToken.token);
return loadedToken.token;
Expand Down
Loading