Class: Seafoam::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/seafoam/commands.rb

Overview

Implementations of the command-line commands that you can run in Seafoam.

Defined Under Namespace

Classes: BGVDebugParser

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Commands

Returns a new instance of Commands.



9
10
11
# File 'lib/seafoam/commands.rb', line 9

def initialize(out)
  @out = out
end

Instance Method Details

#bgv2isabelle(*args) ⇒ Object

Run the bgv2isabelle command.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/seafoam/commands.rb', line 62

def bgv2isabelle(*args)
  case args.first
  when nil, "help", "-h", "--help", "-help"
    args = args.drop(1)
    raise ArgumentError, "unexpected arguments #{args.join(" ")}" unless args.empty?

    @out.puts "bgv2isabelle file.bgv..."
    @out.puts "             --help"
    @out.puts "             --version"
  when "version", "-v", "-version", "--version"
    args = args.drop(1)
    version(*args)
  else
    files = []

    until args.empty?
      arg = args.shift
      if arg.start_with?("-")
        raise ArgumentError, "unknown option #{arg}"
      else
        files.push(arg)
      end
    end

    writer = IsabelleWriter.new(@out)

    files.each do |file|
      parser = Seafoam::BGV::BGVParser.new(file)
      parser.read_file_header
      parser.skip_document_props

      loop do
        index, = parser.read_graph_preheader
        break unless index

        graph_header = parser.read_graph_header
        name = parser.graph_name(graph_header)
        graph = parser.read_graph

        writer.write(index, name, graph)
      end
    end
  end
end

#bgv2json(*args) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/seafoam/commands.rb', line 107

def bgv2json(*args)
  case args.first
  when nil, "help", "-h", "--help", "-help"
    args = args.drop(1)
    raise ArgumentError, "unexpected arguments #{args.join(" ")}" unless args.empty?

    @out.puts "bgv2json file.bgv..."
    @out.puts "         --help"
    @out.puts "         --version"
  when "version", "-v", "-version", "--version"
    args = args.drop(1)
    version(*args)
  else
    files = []

    until args.empty?
      arg = args.shift
      if arg.start_with?("-")
        raise ArgumentError, "unknown option #{arg}"
      else
        files.push(arg)
      end
    end

    writer = JSONWriter.new(@out)

    files.each do |file|
      parser = Seafoam::BGV::BGVParser.new(file)
      parser.read_file_header
      parser.skip_document_props

      loop do
        index, = parser.read_graph_preheader
        break unless index

        graph_header = parser.read_graph_header
        name = parser.graph_name(graph_header)
        graph = parser.read_graph

        writer.write(name, graph)
      end
    end
  end
end

#seafoam(*args) ⇒ Object

Run the general seafoam command.



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
# File 'lib/seafoam/commands.rb', line 14

def seafoam(*args)
  first, *args = args

  if first == "--json"
    formatter_module = Seafoam::Formatters::Json
    first, *args = args
  else
    formatter_module = Seafoam::Formatters::Text
  end

  case first
  when nil, "help", "-h", "--help", "-help"
    raise ArgumentError, "unexpected arguments #{args.join(" ")}" unless args.empty?

    help(*args)
  when "version", "-v", "-version", "--version"
    version(*args)
  else
    name = first
    command, *args = args
    case command
    when nil
      help(*args)
    when "info"
      info(name, formatter_module, *args)
    when "list"
      list(name, formatter_module, *args)
    when "search"
      search(name, *args)
    when "edges"
      edges(name, formatter_module, *args)
    when "props"
      props(name, *args)
    when "source"
      source(name, formatter_module, *args)
    when "render"
      render(name, *args)
    when "debug"
      debug(name, *args)
    when "describe"
      describe(name, formatter_module, *args)
    else
      raise ArgumentError, "unknown command #{command}"
    end
  end
end