<commit_before>require 'stringio'

class Command

  def self.inherited(subclass)
    @@subclasses ||= []
    @@subclasses << subclass unless subclass == DefaultCommand
  end

  def self.commands
    @@subclasses.map do |clazz|
      clazz.new(nil).name
    end.sort
  end

  def self.load(repl, command_line)
    if command_line.start_with?('!')
      # load custom command
      command_parts = command_line[1..-1].split
      command_name = command_parts.first
      command_args = command_parts[1..-1]
      command_class = "#{command_name.capitalize}Command"
      begin
        clazz = Object.const_get(command_class)
        clazz.new(repl, command_args)
      rescue NameError => e
        nil
      end
    else
      DefaultCommand.new(repl, Array(command_line.strip))
    end
  end

  attr_reader :args

  def initialize(repl, args = [])
    @repl = repl
    @args = args
  end

  def name
    "!#{self.class.name.gsub("Command", "").downcase}"
  end

  def execute
    if valid_args?
      run
    else
      puts "Invalid arguments. Ex.: #{usage}"
    end
  end

  private

  def usage
    "#{name} #{sample_args}"
  end

  def sample_args
  end

  def valid_args?
    true
  end

end

class DefaultCommand < Command

  def run
    begin
      cmd = "#{adb} #{args}"

      if interactive?
        system cmd
      else
        if package_dependent?
          cmd << " #{@repl.default_package}" if @repl.default_package
        end
        res = `#{cmd}`
        puts res
        res
      end
    end
  end

  def args
    @args.first
  end

  private

  def adb
    adb = "#{REPL::ADB}"
    adb << " -s #{@repl.default_device}" if @repl.default_device
    adb
  end

  def interactive?
    ["logcat", "shell"].include?(args)
  end

  def package_dependent?
    ["uninstall"].include?(args)
  end<commit_msg>Don't print empty command outputs<commit_after>require 'stringio'

class Command

  def self.inherited(subclass)
    @@subclasses ||= []
    @@subclasses << subclass unless subclass == DefaultCommand
  end

  def self.commands
    @@subclasses.map do |clazz|
      clazz.new(nil).name
    end.sort
  end

  def self.load(repl, command_line)
    if command_line.start_with?('!')
      # load custom command
      command_parts = command_line[1..-1].split
      command_name = command_parts.first
      command_args = command_parts[1..-1]
      command_class = "#{command_name.capitalize}Command"
      begin
        clazz = Object.const_get(command_class)
        clazz.new(repl, command_args)
      rescue NameError => e
        nil
      end
    else
      DefaultCommand.new(repl, Array(command_line.strip))
    end
  end

  attr_reader :args

  def initialize(repl, args = [])
    @repl = repl
    @args = args
  end

  def name
    "!#{self.class.name.gsub("Command", "").downcase}"
  end

  def execute
    if valid_args?
      run
    else
      puts "Invalid arguments. Ex.: #{usage}"
    end
  end

  private

  def usage
    "#{name} #{sample_args}"
  end

  def sample_args
  end

  def valid_args?
    true
  end

end

class DefaultCommand < Command

  def run
    begin
      cmd = "#{adb} #{args}"

      if interactive?
        system cmd
      else
        if package_dependent?
          cmd << " #{@repl.default_package}" if @repl.default_package
        end
        res = `#{cmd}`
        puts res unless res.empty?
        res
      end
    end
  end

  def args
    @args.first
  end

  private

  def adb
    adb = "#{REPL::ADB}"
    adb << " -s #{@repl.default_device}" if @repl.default_device
    adb
  end

  def interactive?
    ["logcat", "shell"].include?(args)
  end

  def package_dependent?
    ["uninstall"].include?(args)
  end
{'fraction_non_alphanumeric': 0.11005434782608696, 'fraction_numerical': 0.002173913043478261, 'mean_word_length': 2.2749110320284696, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, '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': '323031', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1222, 'n_words': 301}