shelltoad 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.textile CHANGED
@@ -1,3 +1,12 @@
1
+ h3. 0.4.1
2
+
3
+ * "help" command
4
+
5
+ h3. 0.4.0
6
+
7
+ * Interactive menu for error select support
8
+ * _open_ command to open error page in browser
9
+
1
10
  h3. 0.3.1
2
11
 
3
12
  * Bugfix configuration
data/Readme.textile CHANGED
@@ -8,8 +8,9 @@ Create <pre><code>.shelltoadrc</code></pre> file in your project directory
8
8
  with the application name and access key:
9
9
  <pre><code>account: myapp
10
10
  key: c285743ecbc285743ecbc285743ecbc285743ecb
11
- secure true # https usage. Default: false
12
- project_id: 123456 # see errors only under specified proejct. Default: all projects</code></pre>
11
+ secure: true # https usage. Default: false.
12
+ project_id: 123456 # see errors only under specified proejct. Default: all projects.
13
+ browser: firefox # specify browsers for open errors. Default: sensible-browser or firefox or _etc_ or explorer.</code></pre>
13
14
 
14
15
  h3. Commands
15
16
 
@@ -17,9 +18,11 @@ h3. Commands
17
18
  * error, er [number] - display information about given error. Shortcut: shelltoad [number]
18
19
  * resolve, rv [number] - mark error as resolved in Hoptoad
19
20
  * commit, ci [number] - do commit to vcs with the information on the specified error and mark error resolved in Hoptoad
21
+ * open, op [number] - open error page in browser
20
22
 
21
23
  Shelltoad supports 'magicfind' in all commands:
22
24
  You don't need to type whole error id - just last three numbers is enough.
25
+ Also all error-related commands support interactive menu if number is not specified.
23
26
 
24
27
  h3. Usage
25
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.1
@@ -1,42 +1,88 @@
1
- class Shelltoad::Command
1
+ require "readline"
2
+ class Shelltoad
3
+ class Command
2
4
 
3
- def self.run(command, *args)
4
- case command.to_s
5
- when "errors", "ers", nil, ""
6
- Shelltoad::Error.all.each do |error|
7
- output error.to_s
8
- end
9
- when "error", "er"
10
- magic_find(args.shift) do |error|
11
- output error.view
5
+ class << self
6
+
7
+ #
8
+ # API
9
+ #
10
+
11
+ def run(command, *args)
12
+ case command.to_s
13
+ when "-h", "--help", "help", "h"
14
+ display_help
15
+ when "errors", "ers", nil, ""
16
+ Error.all.each do |error|
17
+ output error.to_s
18
+ end
19
+ when "error", "er"
20
+ magic_find(args.shift) do |error|
21
+ output error.view
22
+ end
23
+ when "commit", "ci"
24
+ commit(args.shift)
25
+ when "resolve", "rv"
26
+ magic_find(args.shift) do |error|
27
+ error.resolve!
28
+ output "Error #{error.id} marked as resolved"
29
+ end
30
+ when "open", "op"
31
+ magic_find(args.shift) do |error|
32
+ open error.url
33
+ end
34
+ when /^[\d]/
35
+ magic_find(command) do |error|
36
+ output error.view
37
+ end
38
+ else
39
+ raise BaseException, "Command not found"
40
+ end
41
+ return 0
42
+ rescue BaseException => e
43
+ output e.message
44
+ return 1
12
45
  end
13
- when "commit", "ci"
14
- magic_find(args.shift) do |error|
15
- output error.commit!
46
+
47
+ #
48
+ # Implementation
49
+ #
50
+
51
+ protected
52
+ def magic_find(*args, &block)
53
+ Error.magic_find(*args, &block)
16
54
  end
17
- when "resolve", "rv"
18
- magic_find(args.shift) do |error|
19
- error.resolve!
20
- output "Error #{error.id} marked as resolved"
55
+
56
+ def output(*args)
57
+ Shelltoad.output(*args)
21
58
  end
22
- when /^[\d]/
23
- magic_find(command) do |error|
24
- output error.view
59
+
60
+ def commit(id)
61
+ magic_find(id) do |error|
62
+ output error.commit!
63
+ end
64
+ end # commit(id, args)
65
+
66
+ def open(url)
67
+ [Configuration.browser, "firefox", "chromium-browser", "start" ].find do |browser|
68
+ system browser, url.to_s
69
+ end
25
70
  end
26
- else
27
- raise Shelltoad::BaseException, "Command not found"
28
- end
29
- return 0
30
- rescue Shelltoad::BaseException => e
31
- output e.message
32
- return 1
33
- end
34
71
 
35
- def self.magic_find(*args, &block)
36
- Shelltoad::Error.magic_find(*args, &block)
37
- end
72
+ def display_help
73
+ output <<-EOI
74
+ Usage: shelltoad command [<args>]
75
+
76
+ Available commands:
38
77
 
39
- def self.output(*args)
40
- Shelltoad.output(*args)
78
+ errors list all unresolved errors, this is the default
79
+ error display information about given error. Shortcut: shelltoad <number>
80
+ resolve mark error as resolved in Hoptoad
81
+ commit do commit to vcs with the information on the specified error and mark error resolved in Hoptoad
82
+ open open error page in browser
83
+ EOI
84
+
85
+ end
86
+ end
41
87
  end
42
88
  end
@@ -24,6 +24,10 @@ class Shelltoad::Configuration
24
24
  self.instance.account
25
25
  end
26
26
 
27
+ def self.browser
28
+ self.instance.browser
29
+ end
30
+
27
31
  def self.instance
28
32
  @instance ||= self.new
29
33
  end
@@ -56,6 +60,10 @@ class Shelltoad::Configuration
56
60
  @config["secure"] # false by default
57
61
  end
58
62
 
63
+ def browser
64
+ @config["browser"] || "sensible-browser"
65
+ end
66
+
59
67
  end
60
68
 
61
69
  Hoptoad.auth_token = Shelltoad::Configuration.key
@@ -7,18 +7,30 @@ class Shelltoad
7
7
 
8
8
  URL = URI.parse("#{Configuration.secure? ? "https" : "http"}://#{Configuration.account}.hoptoadapp.com:80")
9
9
 
10
+ CACHE = {} # Runtime cache for http queries
11
+
10
12
  #
11
13
  # Class methods
12
14
  #
13
15
 
14
16
  def self.all(options = {})
15
17
  options[:project_id] ||= Configuration.project_id if Configuration.project_id
16
- (Hoptoad::Error.find(:all, options) || []).map! do |attributes|
17
- self.new(attributes)
18
- end
18
+ CACHE[options] ||= (
19
+ (Hoptoad::Error.find(:all, options) || []).map! do |attributes|
20
+ self.new(attributes)
21
+ end
22
+ )
19
23
  end
20
24
 
21
25
  def self.magic_find(id)
26
+ if !id || id.to_s.empty?
27
+ Error.all.each do |error|
28
+ output error.to_s
29
+ end
30
+ output "\n"
31
+ id = Readline.readline("Input error id: ", true)
32
+ end
33
+
22
34
  error = id.to_s.size > 5 ? simple_finder(id) : magic_finder(id)
23
35
  if block_given?
24
36
  return yield(error)
@@ -40,6 +52,10 @@ class Shelltoad
40
52
  self.new(attributes, true)
41
53
  end
42
54
 
55
+ def self.output(*args)
56
+ Shelltoad.output(*args)
57
+ end
58
+
43
59
  #
44
60
  # API
45
61
  #
@@ -59,6 +75,7 @@ class Shelltoad
59
75
 
60
76
  def view
61
77
  <<-EOI
78
+ #{self.url.to_s}
62
79
  #{self.error_message}
63
80
  #{self.lines.join("\n")}
64
81
  EOI
@@ -100,14 +117,12 @@ class Shelltoad
100
117
  @attributes[key] || self.data[key]
101
118
  end
102
119
 
103
- def method_missing(meth, *args, &blk)
104
- if attr = @attributes[meth]
105
- attr
106
- else
107
- super(meth, *args, &blk)
108
- end
120
+ def url(format = nil)
121
+ URI.parse(URL.to_s + path(format))
109
122
  end
110
123
 
124
+
125
+
111
126
  #
112
127
  # Implementation
113
128
  #
@@ -117,8 +132,12 @@ class Shelltoad
117
132
  "/errors/#{self.id}" + (format ? ".#{format}" : "")
118
133
  end
119
134
 
120
- def url(format = nil)
121
- URI.parse(URL.to_s + path(format))
135
+ def method_missing(meth, *args, &blk)
136
+ if attr = @attributes[meth]
137
+ attr
138
+ else
139
+ super(meth, *args, &blk)
140
+ end
122
141
  end
123
142
 
124
143
  end
data/shelltoad.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shelltoad}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-04-06}
12
+ s.date = %q{2011-04-14}
13
13
  s.default_executable = %q{shelltoad}
14
14
  s.description = %q{
15
15
  }
@@ -11,13 +11,30 @@ describe Shelltoad do
11
11
  end
12
12
 
13
13
  describe ".run" do
14
+ subject { Shelltoad.run(*args) }
15
+
16
+
14
17
  [["error", TEST_ERROR], "errors", ["commit", TEST_ERROR], ["resolve", TEST_ERROR]].each do |command|
15
18
  describe "command:#{command.inspect}" do
16
- subject { Shelltoad.run(*Array(command)) }
19
+ let(:args) { Array(command) }
17
20
  it { should == 0 }
18
21
  end
19
22
  end
20
23
 
24
+
25
+ describe "open command" do
26
+ let(:args) { ["open", TEST_ERROR] }
27
+ before(:each) do
28
+ Shelltoad::Configuration.stubs(:browser).returns("true")
29
+ end
30
+ it {should == 0}
31
+
32
+ end
33
+
34
+ describe "help commad" do
35
+ let(:args) { "help" }
36
+ it {should == 0}
37
+ end
21
38
  end
22
39
 
23
40
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelltoad
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 1
10
- version: 0.3.1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-06 00:00:00 +03:00
18
+ date: 2011-04-14 00:00:00 +03:00
19
19
  default_executable: shelltoad
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency