Sutto-marvin 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 0
2
+ patch: 1
3
3
  major: 0
4
4
  minor: 2
data/bin/marvin CHANGED
@@ -44,26 +44,47 @@ class Marvin < Thor
44
44
  end
45
45
  end
46
46
 
47
+ map "cl" => :client, "st" => :status, "rs" => :ring_server,
48
+ "dc" => :distributed_client, "co" => :console
49
+
47
50
  desc "start [PATH]", "starts client at the given path"
51
+ method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean
48
52
  def start(path = ".")
49
53
  @dest = File.expand_path(path)
50
- if File.exist?(source(@dest, "script/client"))
51
- Dir.chdir(@dest) { exec "script/client" }
52
- else
53
- STDOUT.puts "Woops! #{@dest.gsub(" ", "\\ ")} doesn't look to be a marvin directory."
54
- exit!
55
- end
54
+ start_script(:client)
56
55
  end
57
56
 
58
57
  desc "status [PATH]", "shows status of marvin app at a given location"
59
58
  def status(path = ".")
60
59
  @dest = File.expand_path(path)
61
- if File.exist?(source(@dest, "script/status"))
62
- Dir.chdir(@dest) { exec "script/status" }
63
- else
64
- STDOUT.puts "Woops! #{@dest.gsub(" ", "\\ ")} doesn't look to be a marvin directory."
65
- exit!
66
- end
60
+ start_script(:status)
61
+ end
62
+
63
+ desc "client [PATH]", "starts a client instance from the given location"
64
+ method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean
65
+ def client(path = ".")
66
+ @dest = File.expand_path(path)
67
+ start_script(:client)
68
+ end
69
+
70
+ desc "ring_server [PATH]", "starts a ring server from the given location"
71
+ method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean
72
+ def ring_server(path = ".")
73
+ @dest = File.expand_path(path)
74
+ start_script(:ring_server)
75
+ end
76
+
77
+ desc "distributed_client [PATH]", "starts a distributed client from the given location"
78
+ method_options :verbose => :boolean, :daemon => :boolean, :level => :optional, :kill => :boolean
79
+ def distributed_client(path = ".")
80
+ @dest = File.expand_path(path)
81
+ start_script(:distributed_client)
82
+ end
83
+
84
+ desc "console [PATH]", "starts a marvin console from the given location"
85
+ def console(path = ".")
86
+ @dest = File.expand_path(path)
87
+ start_script(:console)
67
88
  end
68
89
 
69
90
  private
@@ -92,8 +113,27 @@ class Marvin < Thor
92
113
  STDOUT.puts text
93
114
  end
94
115
 
116
+ def marvin_repo?(path, type = client)
117
+ File.directory?(source(path, "script")) && File.exist?(source(path, "script/#{type}"))
118
+ end
119
+
120
+ def start_script(name)
121
+ if marvin_repo?(@dest, name)
122
+ extra_args = []
123
+ extra_args << "-k" if options[:kill]
124
+ extra_args << "-v" if options[:verbose]
125
+ extra_args << "-d" if options[:daemon]
126
+ extra_args << "--level=#{options[:level]}" if options[:level]
127
+ Dir.chdir(@dest) { exec("script/#{name}", *extra_args) }
128
+ else
129
+ STDOUT.puts "Woop! #{@dest.gsub(" ", "\\ ")} isn't a marvin app."
130
+ end
131
+ end
132
+
95
133
  end
96
134
 
135
+ STDOUT.puts "Marvin - IRC Library / Framework for Ruby"
136
+
97
137
  # Check if we have arguments, we run the normal
98
138
  # thor task otherwise we just print the help
99
139
  # message.
@@ -41,18 +41,15 @@ module Marvin
41
41
  unless command_name.nil?
42
42
  logger.debug "Command Exists - processing"
43
43
  # Dispatch the command.
44
- self.send(command_name, data.to_a) if self.respond_to?(command_name)
44
+ self.send(command_name, data.split(" ")) if self.respond_to?(command_name)
45
45
  end
46
46
  end
47
47
 
48
48
  def extract_command_name(command)
49
49
  prefix_length = self.command_prefix.to_s.length
50
50
  has_prefix = command[0...prefix_length] == self.command_prefix.to_s
51
- logger.debug "Debugging, prefix is #{prefix_length} characters, has prefix? = #{has_prefix}"
52
51
  if has_prefix
53
- # Normalize the method name
54
52
  method_name = command[prefix_length..-1].to_s.underscore.to_sym
55
- logger.debug "Computed method name is #{method_name.inspect}"
56
53
  return method_name if self.exposed_methods.to_a.include?(method_name)
57
54
  end
58
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Sutto-marvin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darcy Laycock