Method: XfOOrth.process_command_line_options

Defined in:
lib/fOOrth/main.rb

.process_command_line_optionsObject

Process the command line arguments. A string is returned containing fOOrth commands to be executed after the dictionary is loaded.
Returns

  • A string of fOOrth commands to be executed after the dictionary is loaded.


Endemic Code Smells

  • :reek:TooManyStatements



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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fOOrth/main.rb', line 69

def self.process_command_line_options
  begin

    defer, found = "", false

    opts = GetoptLong.new(
      [ "--help",  "-h", "-?", GetoptLong::NO_ARGUMENT ],
      [ "--load",  "-l",       GetoptLong::REQUIRED_ARGUMENT ],
      [ "--debug", "-d",       GetoptLong::NO_ARGUMENT ],
      [ "--show",  "-s",       GetoptLong::NO_ARGUMENT ],
      [ "--quit",  "-q",       GetoptLong::NO_ARGUMENT ],
      [ "--words", "-w",       GetoptLong::NO_ARGUMENT ])

    # Translate the parsed options into fOOrth.

    opts.each do |opt, arg|

      unless found
        puts
        found = true
      end

      case opt
      when "--debug"
        defer << ")debug "
      when "--show"
        defer << ")show "
      when "--load"
        defer << ")load#{arg.inspect}"
      when "--quit"
        defer << ")quit "
      when "--words"
        defer << ")words "
      else
        fail SilentExit
      end
    end

    puts if found

  rescue Exception
    puts
    puts "fOOrth available options:"
    puts
    puts "--help  -h  -?          Display this message and exit."
    puts "--load  -l <filename>   Load the specified fOOrth source file."
    puts "--debug -d              Default to debug ON."
    puts "--quit  -q              Quit after processing the command line."
    puts "--show  -s              Default to show results ON."
    puts "--words -w              List the current vocabulary."
    puts
    raise SilentExit
  end

  defer
end