Class: DisavowTool::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/disavow_tool/command_options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_inputsObject



6
7
8
# File 'lib/disavow_tool/command_options.rb', line 6

def self.parse_inputs
   Commands.new.parse(ARGV)
end

Instance Method Details

#check_arguments(options) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/disavow_tool/command_options.rb', line 68

def check_arguments(options)
  raise "You must to specify one disallow file" if options.disavow_files.blank?
  raise "You must to specify one import file" if options.import_files.blank?
  if options.whitelist
    raise "You need to specify at least one white list file" if options.whitelist_files.blank?
  end
end

#parse(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
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
58
59
60
61
62
63
64
65
66
# File 'lib/disavow_tool/command_options.rb', line 10

def parse(args)
  options = OpenStruct.new
  options.library = []
  options.whitelist  = false
  options.verbose = false
  options.hardcore_verbose = false
  options.network_requests = true

  opt_parser = OptionParser.new do |opts|
      opts.banner = "Usage: disavow_tool [options] --disavow file_1,file_2,file_3 --import file_1,file_2,file_3 [--whitelist file1,file2,file3]"
      opts.separator ""
      opts.separator "Requited options:"
      opts.on("-d","--disavow file_1,file_2", Array, "Disavow files as exported from Google Search Console") do |file|
        options.disavow_files = file
      end
      opts.on("-i","--import file_1,file_2", Array, "List of URLS to analyse. The file must have one URL per line") do |file|
        options.import_files = file
      end

      opts.separator ""
      opts.separator "Optional options:"
      opts.on("-w", "--whitelist file1,file2,file3", Array, "Enter any number of whitelisted files",
                                                   "whitelisted files must have one URL per line") do |file|
        options.whitelist  = true
        options.whitelist_files  = file
      end

      opts.on("-v", "--verbose", "Vervose mode") do
        options.verbose = true
      end

      opts.on("-t", "--no-titles", "Don't request tittles from websites thus making the command faster") do
        options.network_requests = false
      end

      opts.on("-V", "--hardcore-vervose", "Print out even your mama") do
        options.hardcore_verbose = true
        options.verbose = true            # Hardcose verbose includes regular verbose
      end

      opts.separator ""
      opts.separator "Common options:"
      # No argument, shows at tail.  This will print an options summary.
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
      opts.on_tail("--version", "Show version") do
        puts VERSION
        exit
      end
  end

  opt_parser.parse!(args)
  check_arguments(options)
  options
end