<commit_before>require 'active_support/core_ext/string/inflections'

class PowershellCommand
  attr_accessor :script, :working_directory, :execution_policy, :script_parameters

  def initialize(script = nil)
    @script = script
    @working_directory = '.'
  end

  def parameters
    params = []

    if execution_policy == :remote_signed
      params.push('-ExecutionPolicy', 'RemoteSigned')
    end

    params.join(' ')
  end

  def command
    params = []

    params.push("#{script.gsub(working_directory, '.')}.ps1")

    script_parameters.each do |param, value|
      switch_name = param.to_s.camelize(:upper)

      if !!value == value && value
        params.push("-#{switch_name}")
      end

      if value.instance_of? String
        # The value is wrapped in single quotes. Any single quotes it contains are escaped with another single quote.
        escaped_value = "'#{value.gsub("'", "''")}'"

        params.push("-#{switch_name}", escaped_value)
      end
    end

    params.join(' ')<commit_msg>Let powershell know it's running interactively (so -Confirm, etc don't hang) and handle boolean and nil parameters (more) correctly.<commit_after>require 'active_support/core_ext/string/inflections'

class PowershellCommand
  attr_accessor :script, :working_directory, :execution_policy, :script_parameters

  def initialize(script = nil)
    @script = script
    @working_directory = '.'
  end

  def parameters
    params = %w[-NoLogo -NonInteractive]

    if execution_policy == :remote_signed
      params.push('-ExecutionPolicy', 'RemoteSigned')
    end

    params.join(' ')
  end

  def command
    params = []

    params.push("#{script.gsub(working_directory, '.')}.ps1")

    script_parameters.each do |param, value|
      switch_name = param.to_s.camelize(:upper)

      if !!value == value
        params.push("-#{switch_name}:$#{value}")
      elsif value.nil?
        params.push("-#{switch_name} $null")
      else
        value = value.to_s

        # The value is wrapped in single quotes. Any single quotes it contains are escaped with another single quote.
        escaped_value = "'#{value.gsub("'", "''")}'"

        params.push("-#{switch_name}", escaped_value)
      end
    end

    params.join(' ')
{'fraction_non_alphanumeric': 0.1263392857142857, 'fraction_numerical': 0.0008928571428571428, 'mean_word_length': 3.1576994434137293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1630432', 'n_tokens_mistral': 674, 'n_tokens_neox': 666, 'n_words': 166}