Class: Leetcoder::Commands

Inherits:
Object
  • Object
show all
Includes:
Helpers::Utils
Defined in:
lib/leetcoder/leetcoder/commands.rb

Constant Summary collapse

DOWNLOAD_TYPE_ONE =
:one
DOWNLOAD_TYPE_ALL =
:all

Constants included from Helpers::Utils

Helpers::Utils::LANGS_EXT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Utils

#create_directory, #create_file, #lang_to_ext, #store_cookie

Constructor Details

#initialize(options = {}) ⇒ Commands



14
15
16
# File 'lib/leetcoder/leetcoder/commands.rb', line 14

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/leetcoder/leetcoder/commands.rb', line 12

def options
  @options
end

Instance Method Details

#define_commands(parser) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/leetcoder/leetcoder/commands.rb', line 22

def define_commands(parser) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  parser.banner = 'Usage: leetcoder [commands]'
  parser.separator ''
  parser.separator '* indicates default value'
  parser.separator ''
  parser.separator 'commands:'

  parser.on(
    '-d',
    '--download [TYPE]',
    [DOWNLOAD_TYPE_ALL, DOWNLOAD_TYPE_ONE],
    'Specify number of accepted submission to download per problem (*one, all)'
  ) do |type|
    options[:download_type] = type || DOWNLOAD_TYPE_ONE
  end

  parser.on('-c', '--cookie', String, 'Input Leetcode Cookie') do
    store_cookie
    exit
  end

  parser.on('-f', '--folder FOLDER_PATH', String,
            'Specify download folder location (* <current_directory>/leetcode)') do |folder|
    options[:download_folder] = File.expand_path(folder)
  end

  parser.on_tail('-v', '--version', 'Show version') do
    puts Leetcoder::VERSION
    exit
  end

  parser.on_tail('-h', '--help', 'Show available commands') do
    puts parser
    exit
  end
end

#run!Object



18
19
20
# File 'lib/leetcoder/leetcoder/commands.rb', line 18

def run!
  Leetcoder::Download.call(options)
end