cogy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e15ce0ee4619b458af94f3d11906117e1ef9e987
4
- data.tar.gz: ef84ade1821bde53cbc22578613e0e2cab8475f9
3
+ metadata.gz: 28ec300393c739ebc8a9f7b3d84fb9934e8f9778
4
+ data.tar.gz: b685e1a2685d49340dbadf54550375a9689d2ac8
5
5
  SHA512:
6
- metadata.gz: fbe156629d8120fa161bcc1dcedbb679b3e1574adaacc9d47416d710ed18da24b0b7338888be602ad101c7c09f4151ba4ecb48fc49f00eea23e6120ccaa43b07
7
- data.tar.gz: f6f4665eb0daedb50227c1c3a653918bdbebde758065db578f3b5f4a2c4856f9654e27da096b6d24316a98f9c68545aa282d6e3c95a3b19236a0521ae3bc5e68
6
+ metadata.gz: 90b69b70b3b6a243ff59c6bf7ec4ea8f1c0e8ed6a88a9ea5b0579126c78e34a574379975ebcbdc3ee8a0ff54f40b5609893fcad0ee0bf2b72160712cb6ab7f9e
7
+ data.tar.gz: a944b9dafce7515bdf84a95547228ba832b11dfc1d02ce40ab16c136005ca7be0930f3022fcc2d384ff9c833cf79211b5897ad39afa2d896416083ac3a314643
data/README.md CHANGED
@@ -93,7 +93,7 @@ Cogy.configure do |config|
93
93
  # directory relative to the root of your application.
94
94
  #
95
95
  # Default: ["cogy"]
96
- config.command_load_paths = "cogy_commands/"
96
+ config.command_load_paths = "cogy"
97
97
  end
98
98
 
99
99
  ```
@@ -127,9 +127,27 @@ on "calc",
127
127
  end
128
128
  ```
129
129
 
130
- ## Credits
130
+ ## Error template
131
131
 
132
- TODO
132
+ When a command throws an error, the default error template is rendered, which
133
+ is the following:
134
+
135
+ @<%= @user %>: Command '<%= @cmd %>' returned an error.
136
+
137
+ ```
138
+ <%= @exception.class %>:<%= @exception.message %>
139
+ ```
140
+
141
+ However it can be overriden in the application by creating a view in
142
+ `app/views/cogy/error.text.erb`.
143
+
144
+ ## Authors
145
+
146
+ * [Agis Anastasopoulos](https://github.com/agis-)
147
+
148
+ ## License
149
+
150
+ Cogy is licensed under MIT. See [LICENSE](LICENSE).
133
151
 
134
152
 
135
153
 
@@ -2,7 +2,7 @@ require_dependency "cogy/application_controller"
2
2
 
3
3
  module Cogy
4
4
  class CogyController < ApplicationController
5
- # GET /cmd/:cmd/:user
5
+ # GET <mount_path>/cmd/:cmd/:user
6
6
  def command
7
7
  cmd = params[:cmd]
8
8
  args = request.query_parameters.select { |k,_| k !~ /\Acog_opt_/ }.values
@@ -10,7 +10,14 @@ module Cogy
10
10
  .transform_keys { |k| k.sub("cog_opt_", "") }
11
11
  user = params[:user]
12
12
 
13
- render text: Cogy.commands[cmd].run!(args, opts, user)
13
+ begin
14
+ render text: Cogy.commands[cmd].run!(args, opts, user)
15
+ rescue => e
16
+ @user = user
17
+ @cmd = cmd
18
+ @exception = e
19
+ render "cogy/error"
20
+ end
14
21
  end
15
22
 
16
23
  # GET /inventory
@@ -0,0 +1,5 @@
1
+ @<%= @user %>: Command '<%= @cmd %>' returned an error.
2
+
3
+ ```
4
+ <%= @exception.class %>:<%= @exception.message %>
5
+ ```
data/lib/cogy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cogy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/cogy.rb CHANGED
@@ -59,11 +59,17 @@ module Cogy
59
59
  config["commands"][name] = {
60
60
  "executable" => executable_path,
61
61
  "description" => cmd.desc,
62
- "arguments" => cmd.formatted_args,
63
- "options" => cmd.formatted_opts,
64
62
  "rules" => cmd.rules
65
63
  }
66
64
 
65
+ if !cmd.args.empty?
66
+ config["commands"][name]["arguments"] = cmd.formatted_args
67
+ end
68
+
69
+ if !cmd.opts.empty?
70
+ config["commands"][name]["options"] = cmd.formatted_opts
71
+ end
72
+
67
73
  if cmd.long_desc
68
74
  config["commands"][name]["long_description"] = cmd.long_desc
69
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agis Anastasopoulos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-01 00:00:00.000000000 Z
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,11 +51,11 @@ executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - MIT-LICENSE
55
54
  - README.md
56
55
  - Rakefile
57
56
  - app/controllers/cogy/application_controller.rb
58
57
  - app/controllers/cogy/cogy_controller.rb
58
+ - app/views/cogy/error.text.erb
59
59
  - config/routes.rb
60
60
  - lib/cogy.rb
61
61
  - lib/cogy/command.rb
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2016 Agis Anastasopoulos
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.