Module: Columbus3::CommandSemantics
- Defined in:
- lib/columbus3/cli/command_semantics.rb
Constant Summary collapse
- APPNAME =
'columbus3'- VERSION =
Columbus3::VERSION
Class Method Summary collapse
- .console(opts, argv = []) ⇒ Object
- .convert(opts, args) ⇒ Object
- .export(opts, args) ⇒ Object
- .graph(opts, args) ⇒ Object
- .help(opts = nil, argv = []) ⇒ Object
- .man(opts = nil, argv = []) ⇒ Object
-
.process(opts, argv) ⇒ Object
APP SPECIFIC COMMANDS.
-
.reps(all_commands, argv) ⇒ Object
read-eval-print step.
- .search(opts, argv) ⇒ Object
- .show(opts, args) ⇒ Object
- .split(opts, args) ⇒ Object
-
.version(opts = nil, argv = []) ⇒ Object
Main App Starts Here!.
Class Method Details
.console(opts, argv = []) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/columbus3/cli/command_semantics.rb', line 41 def self.console opts, argv = [] all_commands = CommandSyntax.commands all_commands.delete(:console) i = 0 while true string = Readline.readline("#{APPNAME}:%03d> " % i, true) string.gsub!(/^#{APPNAME} /, "") # as a courtesy, remove any leading appname string if string == "exit" or string == "quit" or string == "." then exit 0 end reps all_commands, string.split(' ') i = i + 1 end end |
.convert(opts, args) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/columbus3/cli/command_semantics.rb', line 116 def self.convert opts, args force = opts[:force] input_filename = args[0] if input_filename tracks = GPX2V900::gpx2v900 input_filename tracks.each do |track| if File.exist?(track.filename) and not force puts "Error: #{track.filename} already exists (--force to force updating)" else track.save puts "Track #{track.filename} created" end end else puts "Error: please specify a track file" end end |
.export(opts, args) ⇒ Object
139 140 |
# File 'lib/columbus3/cli/command_semantics.rb', line 139 def self.export opts, args end |
.graph(opts, args) ⇒ Object
112 113 114 |
# File 'lib/columbus3/cli/command_semantics.rb', line 112 def self.graph opts, args show_machinery opts, args, Columbus3::FlotRenderer end |
.help(opts = nil, argv = []) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/columbus3/cli/command_semantics.rb', line 25 def self.help opts = nil, argv = [] all_commands = CommandSyntax.commands if argv != [] argv.map { |x| puts all_commands[x.to_sym][2] } else puts "#{APPNAME} command [options] [args]" puts "" puts "Available commands:" puts "" all_commands.keys.each do |key| puts " " + all_commands[key][0]. end end end |
.man(opts = nil, argv = []) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/columbus3/cli/command_semantics.rb', line 18 def self.man opts = nil, argv = [] path = File.join(File.dirname(__FILE__), "/../../../README.md") file = File.open(path, "r") contents = file.read puts contents end |
.process(opts, argv) ⇒ Object
APP SPECIFIC COMMANDS
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/columbus3/cli/command_semantics.rb', line 61 def self.process opts, argv force = opts[:force] argv.each do |arg| track = V900Track.new filename: arg sidecar = Columbus3::Sidecar.new arg if sidecar.exist? and not force puts "Sidecar file for #{track.filename} already exists. Use --force if you want to overwrite it." else backup(sidecar.filename) if sidecar.exist? printf "Processing %s ...", track.filename sidecar. = track. sidecar.save puts " done!" end end end |
.reps(all_commands, argv) ⇒ Object
read-eval-print step
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/columbus3/cli/command_semantics.rb', line 143 def self.reps all_commands, argv if argv == [] or argv[0] == "--help" or argv[0] == "-h" CommandSemantics.help exit 0 else command = argv[0] syntax_and_semantics = all_commands[command.to_sym] if syntax_and_semantics opts = syntax_and_semantics[0] function = syntax_and_semantics[1] begin parser = Slop::Parser.new(opts) result = parser.parse(argv[1..-1]) = result.to_hash arguments = result.arguments eval "CommandSemantics::#{function}(options, arguments)" rescue Slop::Error => e puts "#{APPNAME}: #{e}" rescue Exception => e puts e end else puts "#{APPNAME}: '#{command}' is not a valid command. See '#{APPNAME} help'" end end end |
.search(opts, argv) ⇒ Object
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 |
# File 'lib/columbus3/cli/command_semantics.rb', line 79 def self.search opts, argv debug = opts[:debug] directory = opts[:dir] || "." recurse = opts[:recurse] output_fields = opts[:fields].any? ? opts[:fields].map { |x| x.to_sym } : [:path, :filename, :start_location, :end_location, :start_date, :end_date, :duration, :min_speed, :max_speed, :min_height, :max_height] if recurse then files = Find.find(directory).select { |e| File.extname(e) == ".yaml" } else files = Dir.glob(File.join(directory, "*.yaml")) end query = QueryParser.new.parse(argv.join(" ")) if debug then puts "Searched files: #{files.join(",")}" puts "Searched files count: #{files.size}" puts "Processed query: #{query}" puts "Output Fields: #{fields}" else sidecar_search = Columbus3::SidecarSearch.new sidecar_search.load files match = sidecar_search.search query match.each do |m| string = output_fields.map { |x| "#{m[x]}" }.join("\t") printf "%s\n", string end end end |
.show(opts, args) ⇒ Object
108 109 110 |
# File 'lib/columbus3/cli/command_semantics.rb', line 108 def self.show opts, args show_machinery opts, args, Columbus3::LeafletRenderer end |
.split(opts, args) ⇒ Object
136 137 |
# File 'lib/columbus3/cli/command_semantics.rb', line 136 def self.split opts, args end |
.version(opts = nil, argv = []) ⇒ Object
Main App Starts Here!
14 15 16 |
# File 'lib/columbus3/cli/command_semantics.rb', line 14 def self.version opts = nil, argv = [] puts "#{APPNAME} version #{VERSION}" end |