CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
nodetouch.js113 linesDownload Raw Back to bin
1#!/usr/bin/env node2const touch = require("../index.js")3 4const usage = code => {5  console[code ? 'error' : 'log'](6    'usage:\n' +7    'touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...'8  )9  process.exit(code)10}11 12const singleFlags = {13  a: 'atime',14  m: 'mtime',15  c: 'nocreate',16  f: 'force'17}18 19const singleOpts = {20  r: 'ref',21  t: 'time'22}23 24const files = []25const args = process.argv.slice(2)26const options = {}27for (let i = 0; i < args.length; i++) {28  const arg = args[i]29  if (!arg.match(/^-/)) {30    files.push(arg)31    continue32  }33 34  // expand shorthands35  if (arg.charAt(1) !== '-') {36    const expand = []37    for (let f = 1; f < arg.length; f++) {38      const fc = arg.charAt(f)39      const sf = singleFlags[fc]40      const so = singleOpts[fc]41      if (sf)42        expand.push('--' + sf)43      else if (so) {44        const soslice = arg.slice(f + 1)45        const soval = soslice.charAt(0) === '=' ? soslice : '=' + soslice46        expand.push('--' + so + soval)47        f = arg.length48      } else if (arg !== '-' + fc)49        expand.push('-' + fc)50    }51    if (expand.length) {52      args.splice.apply(args, [i, 1].concat(expand))53      i--54      continue55    }56  }57 58  const argsplit = arg.split('=')59  const key = argsplit.shift().replace(/^\-\-/, '')60  const val = argsplit.length ? argsplit.join('=') : null61 62  switch (key) {63    case 'time':64      const timestr = val || args[++i]65      // [-t [[CC]YY]MMDDhhmm[.SS]]66      const parsedtime = timestr.match(67        /^(([0-9]{2})?([0-9]{2}))?([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})(\.([0-9]{2}))?$/68      )69      if (!parsedtime) {70        console.error('touch: out of range or illegal ' +71                      'time specification: ' +72                      '[[CC]YY]MMDDhhmm[.SS]')73        process.exit(1)74      } else {75        const y = +parsedtime[1]76        const year = parsedtime[2] ? y77          : y <= 68 ? 2000 + y78          : 1900 + y79 80        const MM = +parsedtime[4] - 181        const dd = +parsedtime[5]82        const hh = +parsedtime[6]83        const mm = +parsedtime[7]84        const ss = +parsedtime[8]85 86        options.time = new Date(Date.UTC(year, MM, dd, hh, mm, ss))87      }88      continue89 90    case 'ref':91      options.ref = val || args[++i]92      continue93 94    case 'mtime':95    case 'nocreate':96    case 'atime':97    case 'force':98      options[key] = true99      continue100 101    default:102      console.error('touch: illegal option -- ' + arg)103      usage(1)104  }105}106 107if (!files.length)108  usage()109 110process.exitCode = 0111Promise.all(files.map(f => touch(f, options)))112  .catch(er => process.exitCode = 1)113