<commit_before># command_let.rb: class CommandLet. Command lets are usually in /v/cmdlet/misc/*
#  That is the path

class CommandLet
  def initialize(flags=nil)
    @opts = Hash.new { false }
    @optparse = nil
    unless flags.nil?
      @optparse = OptionParser.new do |p|
        flags.split(',').each do |f|
puts "CommandLet: processing flag: |#{f}"
          if valid_opt?(f)
            p.on("-#{f}", "-#{f} option")
          else
            p.on("-#{f} value", String, "-#{f} <value> option")
          end
        end
      end
    end
  end
  attr_accessor :block, :code
  attr_reader :inp, :out, :err, :args, :locals, :globals, :opts
  def set_block
    @block = self.instance_eval('->() ' + @code)
  end
  def self.valid_flags?(csv)
    !! /([a-zAZ]:?)(,\1)*/.match(csv)
  end
  def self.from_s(code)
    rcode = self.name + '.new ' + code
    return rcode
  end
  def call(*args, env:, frames:)
      set_args args
      set_ios(env: env)
      set_vars(frames: frames)
      set_block
      return @block.call
  rescue => err
    $stderr.puts err.message
  end

  def set_ios(env:)
    self.inp = env[:in]
    self.out = env[:out]
    self.err = env[:err]
  end
  def set_args args
  @optparse.parse!(args, into: @opts) unless @optparse.nil?

    @args = args
  end
  def argc
    @args.length
  end
  def set_vars(frames:)
    @locals = frames
    @globals = frames.first
  end

  def opt
    @options
  end
  def to_s
    @code
  end
  
  private
  def valid_opt?(ch)
    ch.length == 2 && ch[1] == ':'
  end

  def inp=(inp)
    @inp = inp
  end<commit_msg>added vfs and opts to CommandLet can store and retrieve values from VirtualFileSystem. Flags can be passed via a comma separated value list similar to C getopts function. I.e. -f x,y,f:<commit_after># command_let.rb: class CommandLet. Command lets are usually in /v/cmdlet/misc/*
#  That is the path

class CommandLet
  class Vfs
    def initialize vroot
      @vroot = vroot
    end
    attr_reader :vroot
    def [] path
      @vroot[path]
    end
    def []= path, obj
      @vroot.creat(path, obj)
    end
  end
  def initialize(flags=nil)
    @opts = Hash.new { false }
    @optparse = nil
    unless flags.nil?
      @optparse = optparse_from flags
    end
  end
  attr_accessor :block, :code
  attr_reader :inp, :out, :err, :args, :locals, :globals, :opts, :vfs
  def set_vfs(frames:)
    @vfs = Vfs.new(frames[:vroot])
  end
  def set_block
    @block = self.instance_eval('->() ' + @code)
  end
  def self.valid_flags?(csv)
    !! /([a-zAZ]:?)(,\1)*/.match(csv)
  end
  def self.from_s(code)
    rcode = self.name + '.new ' + code
    return rcode
  end
  def call(*args, env:, frames:)
      set_args args
      set_ios(env: env)
      set_vars(frames: frames)
      set_vfs(frames: frames)

      set_block
      return @block.call
  rescue => err
    $stderr.puts err.message
  end

  def set_ios(env:)
    self.inp = env[:in]
    self.out = env[:out]
    self.err = env[:err]
  end
  def set_args args
  @optparse.parse!(args, into: @opts) unless @optparse.nil?

    @args = args
  end
  def argc
    @args.length
  end
  def set_vars(frames:)
    @locals = frames
    @globals = frames.first
  end

  def opt
    @options
  end
  def to_s
    @code
  end
  
  private
  # TODO: remove valid_opt?
  def valid_opt?(ch)
    ch.length == 2 && ch[1] == ':'
  end

  def inp=(inp)
    @inp = inp
  end
{'fraction_non_alphanumeric': 0.13171884229178973, 'fraction_numerical': 0.0017720023626698169, 'mean_word_length': 2.4108761329305137, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2102819', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1263, 'n_words': 343}