docs: function parseRepo(arg, defaultIndex) {
      var info = {};
  
      // Strip off optional leading `INDEX/`, parse it to `info.index` and
      // leave the rest in `remoteName`.
      var remoteName;
      var protoSepIdx = arg.indexOf('://');
      if (protoSepIdx !== -1) {
          // (A) repo with a protocol, e.g. 'https://host/repo'.
          var slashIdx = arg.indexOf('/', protoSepIdx + 3);
          if (slashIdx === -1) {
              throw new Error('invalid repository name, no "/REPO" after ' +
                  'hostame: ' + arg);
          }
          var indexName = arg.slice(0, slashIdx);
          remoteName = arg.slice(slashIdx + 1);
          info.index = parseIndex(indexName);
      } else {
          var parts = strsplit(arg, '/', 2);
          if (parts.length === 1 || (
              /* or if parts[0] doesn't look like a hostname or IP */
              parts[0].indexOf('.') === -1 &&
              parts[0].indexOf(':') === -1 &&
              parts[0] !== 'localhost'))
          {
              // (B) repo without leading 'INDEX/'.
              if (defaultIndex === undefined) {
                  info.index = parseIndex();
              } else if (typeof (defaultIndex) === 'string') {
                  info.index = parseIndex(defaultIndex);
              } else {
                  info.index = defaultIndex;
              }
              remoteName = arg;
          } else {
              // (C) repo with leading 'INDEX/' (without protocol).
              info.index = parseIndex(parts[0]);
              remoteName = parts[1];
          }
      }
  
      // Validate remoteName (docker `validateRemoteName`).
      var nameParts = strsplit(remoteName, '/', 2);
      var ns, name;
      if (nameParts.length === 2) {
          name = nameParts[1];
  
          // Validate ns.
          ns = nameParts[0];
          if (ns.length < 2 || ns.length > 255) {
              throw new Error('invalid repository namespace, must be between ' +
                  '2 and 255 characters: ' + ns);
          }
          if (! VALID_NS.test(ns)) {
              throw new Error('invalid repository namespace, may only contain ' +
                  '[a-z0-9._-] characters: ' + ns);
          }
          if (ns[0] === '-' && ns[ns.length - 1] === '-') {
              throw new Error('invalid repository namespace, cannot start or ' +
                  'end with a hypen: ' + ns);
          }
          if (ns.indexOf('--') !== -1) {
              throw new Error('invalid repository namespace, cannot contain ' +
                  'consecutive hyphens: ' + ns);
          }
      } else {
          name = remoteName;
          if (info.index.official) {
              ns = 'library';
          }
      }
  
      // Validate name.
      if (! VALID_REPO.test(name)) {
          throw new Error('invalid repository name, may only contain ' +
              '[a-z0-9_/.-] characters: ' + name);
      }
  
  
      info.official = false;
      if (info.index.official) {
          info.remoteName = ns + '/' + name;
          if (ns === 'library') {
              info.official = true;
              info.localName = name;
          } else {
              info.localName = info.remoteName;
          }
          info.canonicalName = DEFAULT_INDEX_NAME + '/' + info.localName;
      } else {
          if (ns) {
              info.remoteName = ns + '/' + name;
          } else {
              info.remoteName = name;
          }
          info.localName = info.index.name + '/' + info.remoteName;
          info.canonicalName = info.localName;
      }
  
      return info;
  }