MCPcopy Index your code
hub / github.com/nodejs/node / flagsToOptions

Method flagsToOptions

deps/npm/lib/trust-cmd.js:246–325  ·  view source on GitHub ↗
({ positionalArgs, flags, providerHostname })

Source from the content-addressed store, hash-verified

244 }
245
246 async flagsToOptions ({ positionalArgs, flags, providerHostname }) {
247 const { entityKey, name, providerEntity, providerFile } = this.constructor
248 const content = await this.optionalPkgJson()
249 const pkgPositional = positionalArgs[0]
250 const pkgJsonName = content.name
251 const git = this.getRepositoryFromPackageJson(content)
252 // the provided positional matches package.json name or no positional provided
253 const matchPkg = (!pkgPositional || pkgPositional === pkgJsonName)
254 const pkgName = pkgPositional || pkgJsonName
255 const usedPkgNameFromPkgJson = !pkgPositional && Boolean(pkgJsonName)
256 const invalidPkgJsonProviderType = matchPkg && git && git?.type !== name
257
258 let entity
259 let entitySource
260
261 if (flags[entityKey]) {
262 entity = flags[entityKey]
263 entitySource = 'flag'
264 } else if (!invalidPkgJsonProviderType && git?.repository) {
265 entity = git.repository
266 entitySource = 'package.json'
267 }
268 const mismatchPkgJsonRepository = matchPkg && git && entity !== git.repository
269 const usedRepositoryInPkgJson = entitySource === 'package.json'
270
271 const warnings = []
272 if (!pkgName) {
273 throw new Error('Package name must be specified either as an argument or in package.json file')
274 }
275
276 if (!flags.file) {
277 throw new Error(`${providerFile} must be specified with the file option`)
278 }
279 if (!flags.file.endsWith('.yml') && !flags.file.endsWith('.yaml')) {
280 throw new Error(`${providerFile} must end in .yml or .yaml`)
281 }
282
283 this.validateFile?.(flags.file)
284
285 if (invalidPkgJsonProviderType) {
286 const message = this.warnString`Repository in package.json is not a ${providerEntity}`
287 if (!flags[entityKey]) {
288 throw new Error(message)
289 } else {
290 warnings.push(message)
291 }
292 } else {
293 if (mismatchPkgJsonRepository) {
294 warnings.push(this.warnString`Repository in package.json (${git.repository}) differs from provided ${providerEntity} (${entity})`)
295 }
296 }
297
298 if (!entity && matchPkg) {
299 throw new Error(`${providerEntity} must be specified with ${entityKey} option or inferred from the package.json repository field`)
300 }
301 if (!entity) {
302 throw new Error(`${providerEntity} must be specified with ${entityKey} option`)
303 }

Callers 1

createConfigCommandMethod · 0.95

Calls 8

optionalPkgJsonMethod · 0.95
warnStringMethod · 0.95
getFrontendUrlMethod · 0.95
validateFileMethod · 0.45
pushMethod · 0.45
validateEntityMethod · 0.45
getEntityUrlMethod · 0.45

Tested by

no test coverage detected