<commit_before>require 'gitlab'
require 'gitlab/help'
require 'gitlab/cli_helpers'
require 'gitlab/shell_history'
require 'readline'
require 'shellwords'

class Gitlab::Shell
  extend Gitlab::CLI::Helpers

  class << self
    attr_reader :arguments, :command

    def start
      setup

      while buffer = Readline.readline('gitlab> ')
        trap('INT') { quit_shell } # capture ctrl-c
        
        begin
          parse_input buffer

          yaml_load_arguments! @arguments
          @arguments.map! { |arg| symbolize_keys arg }

          case buffer
          when nil, ''
            next
          when 'exit'
            quit_shell
          when /^\bhelp\b+/
            puts help arguments[0]
          else
            history << buffer

            data = execute command, arguments
            output_table command, arguments, data
          end
        rescue => e
          puts e.message
        end
      end
    end

    def parse_input buffer
      buf = Shellwords.shellwords(buffer)

      @command = buf.shift
      @arguments = buf.count > 0 ? buf : []
    end

    def setup
      history.load
<commit_msg>Save shell history when user presses Ctrl-d<commit_after>require 'gitlab'
require 'gitlab/help'
require 'gitlab/cli_helpers'
require 'gitlab/shell_history'
require 'readline'
require 'shellwords'

class Gitlab::Shell
  extend Gitlab::CLI::Helpers

  class << self
    attr_reader :arguments, :command

    def start
      setup

      while buffer = Readline.readline('gitlab> ')
        trap('INT') { quit_shell } # capture ctrl-c
        
        begin
          parse_input buffer

          yaml_load_arguments! @arguments
          @arguments.map! { |arg| symbolize_keys arg }

          case buffer
          when nil, ''
            next
          when 'exit'
            quit_shell
          when /^\bhelp\b+/
            puts help arguments[0]
          else
            history << buffer

            data = execute command, arguments
            output_table command, arguments, data
          end
        rescue => e
          puts e.message
        end
      end

      quit_shell # save history if user presses ctrl-d
    end

    def parse_input buffer
      buf = Shellwords.shellwords(buffer)

      @command = buf.shift
      @arguments = buf.count > 0 ? buf : []
    end

    def setup
      history.load

{'fraction_non_alphanumeric': 0.07832345469940728, 'fraction_numerical': 0.001693480101608806, 'mean_word_length': 1.7734741784037558, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4781143', 'n_tokens_mistral': 663, 'n_tokens_neox': 646, 'n_words': 187}