Sha256: efcffcc4fbc240eb60bf101f5f7ef9578f9f6b1ff57e9158297c913a26cfb6ee

Contents?: true

Size: 940 Bytes

Versions: 20

Compression:

Stored size: 940 Bytes

Contents

require 'shopify_cli'

module ShopifyCli
  class Form
    class << self
      def ask(ctx, args, flags)
        attrs = {}
        (@positional_arguments || []).each { |name| attrs[name] = args.shift }
        return nil if attrs.any? { |_k, v| v.nil? }
        (@flag_arguments || []).each { |arg| attrs[arg] = flags[arg] }
        form = new(ctx, args, attrs)
        begin
          form.ask
          form
        rescue ShopifyCli::Abort => err
          ctx.puts(err.message)
          nil
        end
      end

      def positional_arguments(*args)
        @positional_arguments = args
        attr_accessor(*args)
      end

      def flag_arguments(*args)
        @flag_arguments = args
        attr_accessor(*args)
      end
    end

    attr_accessor :ctx, :xargs

    def initialize(ctx, xargs, attributes)
      @ctx = ctx
      @xargs = xargs
      attributes.each { |k, v| send("#{k}=", v) unless v.nil? }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shopify-cli-1.6.0 lib/shopify-cli/form.rb
shopify-cli-1.5.0 lib/shopify-cli/form.rb
shopify-cli-1.4.1 lib/shopify-cli/form.rb
shopify-cli-1.4.0 lib/shopify-cli/form.rb
shopify-cli-1.3.1 lib/shopify-cli/form.rb
shopify-cli-1.3.0 lib/shopify-cli/form.rb
shopify-cli-1.2.0 lib/shopify-cli/form.rb
shopify-cli-1.1.2 lib/shopify-cli/form.rb
shopify-cli-1.1.1 lib/shopify-cli/form.rb
shopify-cli-1.1.0 lib/shopify-cli/form.rb
shopify-cli-1.0.5 lib/shopify-cli/form.rb
shopify-cli-1.0.4 lib/shopify-cli/form.rb
shopify-cli-1.0.3 lib/shopify-cli/form.rb
shopify-cli-1.0.2 lib/shopify-cli/form.rb
shopify-cli-1.0.1 lib/shopify-cli/form.rb
shopify-cli-1.0.0 lib/shopify-cli/form.rb
shopify-cli-0.9.3 lib/shopify-cli/form.rb
shopify-cli-0.9.2 lib/shopify-cli/form.rb
shopify-cli-0.9.1 lib/shopify-cli/form.rb
shopify-cli-0.9.0 lib/shopify-cli/form.rb