Sha256: 1b894f34612e7450d84152c7e41641de5ef23678192ef9e03e0a0115666c42d7

Contents?: true

Size: 1010 Bytes

Versions: 23

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

require 'hamster'
require_relative 'utilities'
require_relative 'options'
require_relative 'appliables'

module Lino
  class SubcommandBuilder
    include Lino::Utilities
    include Lino::Options
    include Lino::Appliables

    class << self
      def for_subcommand(subcommand)
        SubcommandBuilder.new(subcommand: subcommand)
      end
    end

    def initialize(subcommand: nil, options: [])
      @subcommand = subcommand
      @options = Hamster::Vector.new(options)
    end

    def build(option_separator, option_quoting)
      components = [
        @subcommand,
        map_and_join(
          @options,
          &(quote_with(option_quoting) >> join_with(option_separator))
        )
      ]
      components.reject(&:empty?).join(' ')
    end

    private

    def with(**replacements)
      SubcommandBuilder.new(**state.merge(replacements))
    end

    def state
      {
        subcommand: @subcommand,
        options: @options
      }
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lino-3.2.0.pre.5 lib/lino/subcommand_builder.rb
lino-3.2.0.pre.4 lib/lino/subcommand_builder.rb
lino-3.2.0.pre.3 lib/lino/subcommand_builder.rb
lino-3.2.0.pre.2 lib/lino/subcommand_builder.rb
lino-3.2.0.pre.1 lib/lino/subcommand_builder.rb
lino-3.1.0 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.18 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.17 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.16 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.15 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.14 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.13 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.12 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.11 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.10 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.9 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.8 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.7 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.6 lib/lino/subcommand_builder.rb
lino-3.1.0.pre.5 lib/lino/subcommand_builder.rb