bin/neat in rubyneat-0.3.5.alpha.2 vs bin/neat in rubyneat-0.3.5.alpha.3
- old
+ new
@@ -1,83 +1,70 @@
#!/usr/bin/env ruby
=begin rdoc
-=RubyNEAT Launcher
+=RubyNEAT Launcher based on thor
=end
+
+require 'thor'
require 'semver'
# Be sure rnlib is added to the library path
%w{ lib neater neater/rnlib }.each do |dir|
$:.unshift File.join([Dir.pwd, dir])
end
NEATER = File.join [Dir.pwd, "neater"]
NEATGLOB = NEATER + '/*_neat.rb'
-require 'slop'
require 'rubyneat'
-def list_neaters
- Dir.glob(NEATGLOB).sort.each do |ne|
- puts 'neat run ' + File.basename(ne).gsub(%r{_neat\.rb}, '')
- end
-end
+module RubyNEAT
+ module Cli
-def list_neurons
- puts NEAT::Neuron.neuron_types.map{|n| n.name }.sort.join "\n"
-end
+ class List < Thor
+ desc 'neaters', 'List all Neaters.'
+ def neaters
+ Dir.glob(NEATGLOB).sort.each do |ne|
+ puts 'neat runeater ' + File.basename(ne).gsub(%r{_neat\.rb}, '')
+ end
+ end
-opts = Slop.parse(strict: true, help: true) do
- banner 'Usage: neat [commands] [options] ...'
-
- on :version, 'Version information' do
- run do |opts, args|
- puts SemVer.find.format "%M.%m.%p%s"
+ desc 'neurons', 'List all Neurons.'
+ def neurons
+ puts NEAT::Neuron.neuron_types.map{|n| n.name }.sort.join "\n"
+ end
end
- end
- command :console do
- banner 'Usage: neat console [options]'
- run do
- # TODO Implement an interactive console
- puts "Interactive Console NIY"
- end
- end
+ class Main < Thor
+ class_option :verbose, type: :string, banner: '[1|2|3]'
- command :list do
- banner 'Usage: neat list options'
- on :n, :neaters, 'list available neaters (default)'
- on :u, :neurons, 'list available Neuron types'
- run do |opts, args|
- opts.to_hash.map { |k, v| k }.reject{ |o| opts[o].nil? }.each do |o|
- case o
- when :neurons
- list_neurons
- when :neaters
- list_neaters
- end
+ desc 'list <type>', 'List the requested type.'
+ subcommand 'list', List
+
+ desc 'version', 'Display RubyNEAT version'
+ def version
+ puts SemVer.find.format "%M.%m.%p%s"
end
- end
- end
+ desc 'console', 'Run RubyNEAT interactively'
+ def console
+ #TODO: Finish the console
+ puts "Not Implemented Yet."
+ end
- command :run do
- banner "Usage: neat run [options] neater_module ...\nFor a list of neater modules: neat list"
- on :log=, 'Debugging level [info|warn|error|debug]'
- on :v, :verbose=, 'Verbose mode', as: Integer
+ desc 'runeater <neater> [<neater> <neater> ...] [OPTS]', 'Run a Neater'
+ option :log, type: :string, banner: 'info|warn|debug|error'
+ def runeater(*neaters)
+ NEAT::controller.verbosity = options[:verbose].to_i if options[:verbose]
+ eval %{$log.level = Logger::#{options[:log].upcase}} if options[:log]
- run do |opts, args|
- NEAT::controller.verbosity = opts[:v].to_i unless opts[:v].nil?
- eval %{$log.level = Logger::#{opts[:log].upcase}} unless opts[:log].nil?
-
- args.map do |proj|
- "#{proj}_neat.rb"
- end.each do |file|
- load file
+ neaters.map do |neater|
+ "#{neater}_neat.rb"
+ end.each do |file|
+ load file
+ end
end
end
end
-
- run do |opts, args|
- puts opts
- end
end
+
+RubyNEAT::Cli::Main.start(ARGV)