<commit_before># rpc schema - provides various schema operations and output formats

ycc      = require 'yang-cc'
yaml     = require 'js-yaml'
traverse = require 'traverse'
pretty   = require 'prettyjson'
treeify  = require 'treeify'
fs       = require 'fs'

module.exports = (input, output, done) ->
  args = input.get 'arguments'
  opts = input.get 'options'

  ycc = new ycc.Composer ycc # make a fresh copy
  ycc.set basedir: process.cwd()
  ycc.include opts.include
  ycc.link opts.link

  schemas = args.map (x) ->
    if /^[\-\w\.]+$/.test x then fs.readFileSync x, 'utf-8'
    else x
  schemas.push opts.eval if opts.eval?

  schema = schemas.pop()
  obj = switch
    when opts.compile    then ycc.compile schema
    else (ycc.preprocess schema).schema

  obj = (traverse obj).map (x) -> switch
    when x instanceof Function and x.extract?
      o = meta: x.extract()
      delete o.meta.bindings
      @update ycc.copy o, x.get 'bindings'
    when x instanceof Function and opts.format in ['json','pretty']
      if x.func instanceof Function
        @update x.func.toString()
      else
        @update x.toString()

  result = switch opts.format
    when 'json'   then JSON.stringify obj, null, opts.space
    when 'yaml'   then yaml.dump obj, lineWidth: -1
    when 'tree'   then treeify.asTree obj, true
    when 'pretty' then pretty.render obj, opts
    when 'yang'   then ycc.dump obj
    #when 'xml'    then js2xml 'schema', obj, prettyPrinting: indentString: '  '
    else obj

  result = switch opts.encoding
    when 'base64' then (new Buffer result).toString 'base64'
    else result

  unless opts.output?
    output.set result
    return done()<commit_msg>change logic for rpc schema to only expect one schema<commit_after># rpc schema - provides various schema operations and output formats

ycc      = require 'yang-cc'
yaml     = require 'js-yaml'
traverse = require 'traverse'
pretty   = require 'prettyjson'
treeify  = require 'treeify'
fs       = require 'fs'

module.exports = (input, output, done) ->
  args = input.get 'arguments'
  opts = input.get 'options'

  ycc = new ycc.Composer ycc # make a fresh copy
  ycc.set basedir: process.cwd()
  ycc.include opts.include
  ycc.link opts.link

  schema = opts.eval ? fs.readFileSync args[0], 'utf-8'

  obj = switch
    when opts.compile then ycc.compile schema
    else (ycc.preprocess schema).schema

  obj = (traverse obj).map (x) -> switch
    when x instanceof Function and x.extract?
      o = meta: x.extract()
      delete o.meta.bindings
      @update ycc.copy o, x.get 'bindings'
    when x instanceof Function and opts.format in ['json','pretty']
      if x.func instanceof Function
        @update x.func.toString()
      else
        @update x.toString()

  result = switch opts.format
    when 'json'   then JSON.stringify obj, null, opts.space
    when 'yaml'   then yaml.dump obj, lineWidth: -1
    when 'tree'   then treeify.asTree obj, true
    when 'pretty' then pretty.render obj, opts
    when 'yang'   then ycc.dump obj
    #when 'xml'    then js2xml 'schema', obj, prettyPrinting: indentString: '  '
    else obj

  result = switch opts.encoding
    when 'base64' then (new Buffer result).toString 'base64'
    else result

  unless opts.output?
    output.set result
    return done()
{'fraction_non_alphanumeric': 0.10462287104622871, 'fraction_numerical': 0.004562043795620438, 'mean_word_length': 2.8155452436194897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '915468', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1023, 'n_words': 357}