Skip to content

Commit

Permalink
Merge pull request #203 from mittwald/bugfix/uuid-wo-parentid
Browse files Browse the repository at this point in the history
Add options to use UUIDs for subordinate resources without relying on the parent ID
  • Loading branch information
martin-helmich authored Jan 30, 2024
2 parents 798dc06 + 066d058 commit ee488b3
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/lib/project/flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeProjectIdToUuid } from "../../Helpers.js";
import { isUuid, normalizeProjectIdToUuid } from "../../Helpers.js";
import {
CommandType,
ContextArgs,
Expand All @@ -7,7 +7,7 @@ import {
makeFlagSet,
makeMissingContextInputError,
} from "../context_flags.js";
import { ContextKey, ContextNames } from "../context.js";
import { Context, ContextKey, ContextNames } from "../context.js";
import { AlphabetLowercase } from "@oclif/core/lib/interfaces/index.js";
import { Args, Config, Flags } from "@oclif/core";
import { ArgOutput, FlagOutput } from "@oclif/core/lib/interfaces/parser.js";
Expand Down Expand Up @@ -98,19 +98,27 @@ export function makeProjectFlagSet<TName extends ContextNames>(
args: ArgOutput,
cfg: Config,
): Promise<string> => {
const projectId = await withProjectId(
apiClient,
commandType,
flags,
args,
cfg,
);

const idInput = idFromArgsOrFlag(flags, args);
if (idInput) {
if (isUuid(idInput)) {
return idInput;
}

const projectId = await withProjectId(
apiClient,
commandType,
flags,
args,
cfg,
);
return normalize(apiClient, projectId, idInput);
}

const idFromContext = await new Context(cfg).getContextValue(flagName);
if (idFromContext) {
return idFromContext.value;
}

throw makeMissingContextInputError<TName>(
commandType,
name,
Expand Down

0 comments on commit ee488b3

Please sign in to comment.