<commit_before>module Cucumber
  module Chef

    class CommandError < Error; end

    class Command
      attr_accessor :stdout, :stderr, :stdin

      def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
        @stdout, @stderr, @stdin = stdout, stderr, stdin
        @stdout.sync = true if @stdout.respond_to?(:sync=)

        @knife = (File.exists?("bin/knife") ? "bin/knife" : %x(command -v knife))
      end

      def run(command, exit_code=0)
        command = "#{command} 2>&1"
        output = %x(#{command})

        @stdout.puts("R:[#{command}] (#{$?})")
        @stdout.puts("--------------------------------------------------------------------------------")
        @stdout.puts(output)
        @stdout.puts("--------------------------------------------------------------------------------")

        raise CommandError("run(#{command}) failed! [#{$?}]") if ($? != exit_code)
      end

      def knife(*args)
        knife_rb = Pathname.new(File.join(Dir.pwd, ".cucumber-chef/knife.rb")).expand_path
        run("#{@knife} #{args.join(" ")} -c #{knife_rb}  --color -n")
      end

    end<commit_msg>return output from commands<commit_after>module Cucumber
  module Chef

    class CommandError < Error; end

    class Command
      attr_accessor :stdout, :stderr, :stdin

      def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
        @stdout, @stderr, @stdin = stdout, stderr, stdin
        @stdout.sync = true if @stdout.respond_to?(:sync=)

        @knife = (File.exists?("bin/knife") ? "bin/knife" : %x(command -v knife))
      end

      def run(command, exit_code=0)
        command = "#{command} 2>&1"
        output = %x(#{command})

        @stdout.puts("R:[#{command}] (#{$?})")
        @stdout.puts("--------------------------------------------------------------------------------")
        @stdout.puts(output)
        @stdout.puts("--------------------------------------------------------------------------------")

        raise CommandError("run(#{command}) failed! [#{$?}]") if ($? != exit_code)

        output
      end

      def knife(*args)
        knife_rb = Pathname.new(File.join(Dir.pwd, ".cucumber-chef/knife.rb")).expand_path
        run("#{@knife} #{args.join(" ")} -c #{knife_rb}  --color -n")
      end

    end
{'fraction_non_alphanumeric': 0.29401408450704225, 'fraction_numerical': 0.002640845070422535, 'mean_word_length': 1.636890951276102, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4526027', 'n_tokens_mistral': 706, 'n_tokens_neox': 678, 'n_words': 135}