MCPcopy
hub / github.com/mozilla/web-ext / getArguments

Method getArguments

src/program.js:136–202  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134 // Retrieve the yargs argv object and apply any further fix needed
135 // on the output of the yargs options parsing.
136 getArguments() {
137 // To support looking up required parameters via config files, we need to
138 // temporarily disable the requiredArguments validation. Otherwise yargs
139 // would exit early. Validation is enforced by the checkRequiredArguments()
140 // method, after reading configuration files.
141 //
142 // This is an undocumented internal API of yargs! Unit tests to avoid
143 // regressions are located at: tests/functional/test.cli.sign.js
144 //
145 // Replace hack if possible: https://github.com/mozilla/web-ext/issues/1930
146 const validationInstance = this.yargs
147 .getInternalMethods()
148 .getValidationInstance();
149 const { requiredArguments } = validationInstance;
150 // Initialize demandedOptions (which is going to be set to an object with one
151 // property for each mandatory global options, then the arrow function below
152 // will receive as its demandedOptions parameter a new one that also includes
153 // all mandatory options for the sub command selected).
154 this.demandedOptions = this.yargs.getDemandedOptions();
155 validationInstance.requiredArguments = (args, demandedOptions) => {
156 this.demandedOptions = demandedOptions;
157 };
158 let argv;
159 try {
160 argv = this.yargs.argv;
161 } catch (err) {
162 if (
163 err.name === 'YError' &&
164 err.message.startsWith('Unknown argument: ')
165 ) {
166 throw new UsageError(err.message);
167 }
168 throw err;
169 }
170 validationInstance.requiredArguments = requiredArguments;
171
172 // Yargs boolean options doesn't define the no* counterpart
173 // with negate-boolean on Yargs 15. Define as expected by the
174 // web-ext execute method.
175 if (argv.configDiscovery != null) {
176 argv.noConfigDiscovery = !argv.configDiscovery;
177 }
178 if (argv.reload != null) {
179 argv.noReload = !argv.reload;
180 }
181
182 // Yargs doesn't accept --no-input as a valid option if there isn't a
183 // --input option defined to be negated, to fix that the --input is
184 // defined and hidden from the yargs help output and we define here
185 // the negated argument name that we expect to be set in the parsed
186 // arguments (and fix https://github.com/mozilla/web-ext/issues/1860).
187 if (argv.input != null) {
188 argv.noInput = !argv.input;
189 }
190
191 // Replacement for the "requiresArg: true" parameter until the following bug
192 // is fixed: https://github.com/yargs/yargs/issues/1098
193 if (argv.ignoreFiles && !argv.ignoreFiles.length) {

Callers 1

executeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected