MCPcopy Create free account
hub / github.com/firebase/firebase-tools / register

Method register

src/command.ts:158–306  ·  view source on GitHub ↗

* Registers the command with the client. This is used to initially set up * all the commands and wraps their functionality with analytics and error * handling. * @param client the client object (from src/index.js).

(client: CLIClient)

Source from the content-addressed store, hash-verified

156 * @param client the client object (from src/index.js).
157 */
158 register(client: CLIClient): void {
159 this.client = client;
160 const program = client.cli;
161 const cmd = program.command(this.cmd);
162 if (this.descriptionText) {
163 cmd.description(this.descriptionText);
164 }
165 if (this.aliases) {
166 cmd.aliases(this.aliases);
167 }
168 this.options.forEach((args) => {
169 const flags = args.shift();
170 cmd.option(flags, ...args);
171 });
172
173 if (this.helpText) {
174 cmd.on("--help", () => {
175 console.log(); // Seperates the help text from global options.
176 console.log(this.helpText);
177 });
178 }
179
180 // See below about using this private property
181 this.positionalArgs = cmd._args;
182
183 // args is an array of all the arguments provided for the command PLUS the
184 // options object as provided by Commander (on the end).
185 // eslint-disable-next-line @typescript-eslint/no-explicit-any
186 cmd.action((...args: any[]) => {
187 const runner = this.runner();
188 const start = process.uptime();
189 const options = last(args);
190 // We do not want to provide more arguments to the action functions than
191 // we are able to - we're not sure what the ripple effects are. Our
192 // action functions are supposed to be of the form (options, ...args)
193 // where `...args` are the <required> and [optional] arguments of the
194 // command. Therefore, if we check the number of arguments we have
195 // against the number of arguments the action function has, we can error
196 // out if we would provide too many.
197 // TODO(bkendall): it would be nice to not depend on this internal
198 // property of Commander, but that's the limitation we have today. What
199 // we would like is the following:
200 // > if (args.length > this.actionFn.length)
201 if (args.length - 1 > cmd._args.length) {
202 if (!getInheritedOption(options, "json") && !options.isMCP) {
203 useConsoleLoggers();
204 }
205 client.errorOut(
206 new FirebaseError(
207 `Too many arguments. Run ${clc.bold(
208 "firebase help " + this.name,
209 )} for usage instructions`,
210 { exit: 1 },
211 ),
212 );
213 return;
214 }
215

Callers 2

loadFunction · 0.80
loadCommandFunction · 0.80

Calls 15

runnerMethod · 0.95
getInheritedOptionFunction · 0.90
useConsoleLoggersFunction · 0.90
trackEmulatorFunction · 0.90
trackGA4Function · 0.90
withTimeoutFunction · 0.90
optionMethod · 0.80
onMethod · 0.80
actionMethod · 0.80
writeMethod · 0.80
allMethod · 0.80
lastFunction · 0.70

Tested by

no test coverage detected