Class: G2R::Util::CommandLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/graph2relational/util-commandline-parser.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandLineParser

Returns a new instance of CommandLineParser.



6
7
8
# File 'lib/graph2relational/util-commandline-parser.rb', line 6

def initialize()
  @valid = true
end

Instance Method Details

#parseObject



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
67
68
69
70
71
# File 'lib/graph2relational/util-commandline-parser.rb', line 10

def parse()
  # default values
  options = {
    :input => nil, :output => nil,
    :additional_base_columns => [], :additional_relationship_columns => [],
    :exclude_labels => [], :exclude_relationships => []
  }

  # display help if no args
  ARGV << '-h' if ARGV.empty?

  # do parsing
  OptionParser.new do |opts|
      opts.banner = "Usage: graph2relational -i <neo4j_connection_url> -o <rdbms_connection_url> [optional_arguments]"

      # input file
      opts.on("-i CONNECTION", "--input CONNECTION", "Neo4J connection URI from where the schema and data will be geberated") do |input_connection|
          options[:input] = input_connection
      end

      # output dir
      opts.on("-o CONNECTION", "--output CONNECTION", "RDBMS connection URI to where the schema and data will be persisted") do |output_connection|
        options[:output] = output_connection
      end

      # base columns to always be created
      opts.on("--additional-base-columns COLUMNS", "Base table columns (separated by comma) that should always be created, even if they are not found in Neo4J schema") do |columns|
        options[:additional_base_columns] = columns.split(",").map{|column| column.strip}
      end

      opts.on("--additional-relationships-columns COLUMNS", "Relationship table columns (separated by comma) that should always be created, even if they are not found in Neo4J schema") do |columns|
        options[:additional_relationship_columns] = columns.split(",").map{|column| column.strip}
      end

      # exclusion
      opts.on("--exclude-labels EXCLUSION", "Neo4J labels (separated by comma) to exclude from the conversion") do |exclude|
        options[:exclude_labels] = exclude.split(",").map{|exclude| exclude.strip}
      end

      opts.on("--exclude-relationships EXCLUSION", "Neo4J relationships (separated by comma) to exclude from the conversion") do |exclude|
        options[:exclude_relationships] = exclude.split(",").map{|exclude| exclude.strip}
      end

      # help
      opts.on_tail("-h", "--help", "Help message") do
        puts opts
        exit
      end
  end.parse!

  # check mandatory args
  if options[:input].nil?
    puts "Missing parameter: specify Neo4J connection URI using -i <connection> parameter"
    exit
  end
  if options[:output].nil?
    puts "Missing parameter: specify RDBMS connection URI using -o <connection> parameter"
    exit
  end

  return options
end