Class: ShopifyCLI::Options

Inherits:
Object
  • Object
show all
Includes:
SmartProperties
Defined in:
lib/shopify_cli/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



11
12
13
14
# File 'lib/shopify_cli/options.rb', line 11

def initialize
  @flags = {}
  @help = false
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



9
10
11
# File 'lib/shopify_cli/options.rb', line 9

def flags
  @flags
end

#helpObject (readonly)

Returns the value of attribute help.



9
10
11
# File 'lib/shopify_cli/options.rb', line 9

def help
  @help
end

#subcommandObject (readonly)

Returns the value of attribute subcommand.



9
10
11
# File 'lib/shopify_cli/options.rb', line 9

def subcommand
  @subcommand
end

Instance Method Details

#parse(options_block, args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/shopify_cli/options.rb', line 16

def parse(options_block, args)
  @args = args
  if options_block.respond_to?(:call) && args
    parse_flags(options_block)
  else
    parser.permute!(@args)
  end
  @args
end

#parse_flags(block) ⇒ Object



26
27
28
29
# File 'lib/shopify_cli/options.rb', line 26

def parse_flags(block)
  block.call(parser, @flags)
  parser.permute!(@args)
end

#parserObject



31
32
33
34
35
36
37
38
# File 'lib/shopify_cli/options.rb', line 31

def parser
  @parser ||= begin
    opt = OptionParser.new
    opt.on("--help", "-h", Context.message("core.options.help_text")) do |v|
      @help = v
    end
  end
end