Sha256: 1bbd3fce1034a7473456c35330a928eb244b9e14123e8d342900f091b0aa45d5

Contents?: true

Size: 1.55 KB

Versions: 21

Compression:

Stored size: 1.55 KB

Contents

require 'fig/statement'

module Fig; end

# Specifies a default command that will be executed for a given Configuration
# if no command is specified on the command-line.
class Fig::Statement::Command < Fig::Statement
  attr_reader :command

  def self.validate_and_process_escapes_in_argument(
    command_line_argument, &block
  )
    tokenizer = Fig::StringTokenizer.new TOKENIZING_SUBEXPRESSION_MATCHER, '@'

    return tokenizer.tokenize command_line_argument, &block
  end

  def initialize(line_column, source_description, command)
    super(line_column, source_description)

    @command = command
  end

  def statement_type()
    return 'command'
  end

  def deparse_as_version(deparser)
    return deparser.command(self)
  end

  def minimum_grammar_for_emitting_input()
    return minimum_grammar()
  end

  def minimum_grammar_for_publishing()
    return minimum_grammar()
  end

  private

  def minimum_grammar()
    if command.size > 1
      return [1, 'contains multiple components']
    end

    argument = command.first.to_escaped_string

    # Can't have octothorpes anywhere in v0 due to comment stripping via
    # regex.
    if argument =~ /#/
      return [1, 'contains a comment ("#") character']
    end

    if argument =~ /"/
      return [1, %Q<contains a double quote>]
    end

    return [0]
  end

  TOKENIZING_SUBEXPRESSION_MATCHER = [
    {
      :pattern => %r< \@ [a-zA-Z0-9_.-]* >x,
      :action =>
        lambda {
          |subexpression, error_block|

          Fig::TokenizedString::Token.new :package_path, subexpression
        }
    }
  ]
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
fig-1.23.0 lib/fig/statement/command.rb
fig-1.22.1.beta.1 lib/fig/statement/command.rb
fig-1.22.0 lib/fig/statement/command.rb
fig-1.21.1.beta.2 lib/fig/statement/command.rb
fig-1.21.1.beta.1 lib/fig/statement/command.rb
fig-1.21.0 lib/fig/statement/command.rb
fig-1.20.1.beta.1 lib/fig/statement/command.rb
fig-1.20.0 lib/fig/statement/command.rb
fig-1.19.0 lib/fig/statement/command.rb
fig-1.18.0 lib/fig/statement/command.rb
fig-1.17.0 lib/fig/statement/command.rb
fig-1.16.1.beta.1 lib/fig/statement/command.rb
fig-1.16.0 lib/fig/statement/command.rb
fig-1.15.1.beta.2 lib/fig/statement/command.rb
fig-1.15.1.beta.1 lib/fig/statement/command.rb
fig-1.15.0 lib/fig/statement/command.rb
fig-1.14.0 lib/fig/statement/command.rb
fig-1.13.0 lib/fig/statement/command.rb
fig-1.12.0 lib/fig/statement/command.rb
fig-1.11.0 lib/fig/statement/command.rb