({
projectId,
project,
rc,
}: {
projectId?: string;
project?: string;
rc?: RC;
})
| 28 | * @returns The projectId |
| 29 | */ |
| 30 | export function needProjectId({ |
| 31 | projectId, |
| 32 | project, |
| 33 | rc, |
| 34 | }: { |
| 35 | projectId?: string; |
| 36 | project?: string; |
| 37 | rc?: RC; |
| 38 | }): string { |
| 39 | if (projectId || project) { |
| 40 | return projectId || project!; |
| 41 | } |
| 42 | |
| 43 | const aliases = rc?.projects || {}; |
| 44 | const aliasCount = Object.keys(aliases).length; |
| 45 | |
| 46 | if (aliasCount === 0) { |
| 47 | throw new FirebaseError( |
| 48 | "No currently active project.\n" + |
| 49 | "To run this command, you need to specify a project. You have two options:\n" + |
| 50 | "- Run this command with " + |
| 51 | clc.bold("--project <alias_or_project_id>") + |
| 52 | ".\n" + |
| 53 | "- Set an active project by running " + |
| 54 | clc.bold("firebase use --add") + |
| 55 | ", then rerun this command.\n" + |
| 56 | "To list all the Firebase projects to which you have access, run " + |
| 57 | clc.bold("firebase projects:list") + |
| 58 | ".\n" + |
| 59 | marked( |
| 60 | "To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases", |
| 61 | ), |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | const aliasList = Object.entries(aliases) |
| 66 | .map(([aname, projectId]) => ` ${aname} (${projectId})`) |
| 67 | .join("\n"); |
| 68 | |
| 69 | throw new FirebaseError( |
| 70 | "No project active, but project aliases are available.\n\nRun " + |
| 71 | clc.bold("firebase use <alias>") + |
| 72 | " with one of these options:\n\n" + |
| 73 | aliasList, |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Fetches the project number, throwing an error if unable to resolve the |
no test coverage detected
searching dependent graphs…