krl 0.1.68 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/krl +6 -30
- data/bin/krl-connect +0 -0
- data/lib/apps.rb +1 -3
- data/lib/check.rb +5 -6
- data/lib/checkout.rb +57 -22
- data/lib/cli.rb +229 -0
- data/lib/commit.rb +6 -4
- data/lib/common.rb +20 -9
- data/lib/create.rb +8 -8
- data/lib/deploy.rb +3 -5
- data/lib/generate.rb +71 -47
- data/lib/info.rb +5 -8
- data/lib/note.rb +4 -6
- data/lib/show.rb +3 -4
- data/lib/stats.rb +110 -0
- data/lib/update.rb +13 -5
- data/lib/versions.rb +3 -4
- metadata +42 -10
data/bin/krl
CHANGED
@@ -1,34 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
COMMANDS = {
|
7
|
-
"help" => lambda { |args| require LIB_DIR + 'help'; KRL_CMD::Help.go },
|
8
|
-
"apps" => lambda { |args| require LIB_DIR + 'apps'; KRL_CMD::Apps.go },
|
9
|
-
"checkout" => lambda { |args| require LIB_DIR + 'checkout'; KRL_CMD::Checkout.go(args) },
|
10
|
-
"create" => lambda { |args| require LIB_DIR + 'create'; KRL_CMD::Create.go(args) },
|
11
|
-
"update" => lambda { |args| require LIB_DIR + 'update'; KRL_CMD::Update.go(args) },
|
12
|
-
"versions" => lambda { |args| require LIB_DIR + 'versions'; KRL_CMD::Versions.go(args) },
|
13
|
-
"deploy" => lambda { |args| require LIB_DIR + 'deploy'; KRL_CMD::Deploy.go(args) },
|
14
|
-
"commit" => lambda { |args| require LIB_DIR + 'commit'; KRL_CMD::Commit.go(args) },
|
15
|
-
"show" => lambda { |args| require LIB_DIR + 'show'; KRL_CMD::Show.go(args) },
|
16
|
-
"note" => lambda { |args| require LIB_DIR + 'note'; KRL_CMD::Note.go(args) },
|
17
|
-
"check" => lambda { |args| require LIB_DIR + 'check'; KRL_CMD::Check.go(args) },
|
18
|
-
"generate" => lambda { |args| require LIB_DIR + 'generate'; KRL_CMD::Generate.go(args) },
|
19
|
-
"test" => lambda { |args| require LIB_DIR + 'test'; KRL_CMD::Test.go(args) },
|
20
|
-
"info" => lambda { |args| require LIB_DIR + 'info'; KRL_CMD::Info.go(args) }
|
21
|
-
}
|
3
|
+
require 'thor'
|
4
|
+
require 'kynetx_am_api'
|
5
|
+
require 'ap'
|
22
6
|
|
23
|
-
|
7
|
+
#$DEBUG = true
|
24
8
|
|
25
|
-
|
26
|
-
|
27
|
-
begin
|
28
|
-
COMMANDS[cmd].call(ARGV)
|
29
|
-
rescue Exception => e
|
30
|
-
puts "Error: #{e.message}"
|
31
|
-
end
|
32
|
-
else
|
33
|
-
puts banner
|
34
|
-
end
|
9
|
+
require File.dirname(__FILE__) + "/../lib/cli"
|
10
|
+
KRL_CMD::CLI.start
|
data/bin/krl-connect
CHANGED
File without changes
|
data/lib/apps.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Apps
|
3
3
|
def self.go
|
4
|
-
require LIB_DIR + 'user'
|
5
|
-
require LIB_DIR + 'common'
|
6
4
|
user = User.new
|
7
5
|
KRL_COMMON::pretty_table(user.applications["apps"], [
|
8
6
|
{:field => "Ruleset ID", :value => lambda { |r| r["appid"] }},
|
@@ -11,4 +9,4 @@ module KRL_CMD
|
|
11
9
|
])
|
12
10
|
end
|
13
11
|
end
|
14
|
-
end
|
12
|
+
end
|
data/lib/check.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
+
require 'json'
|
1
2
|
module KRL_CMD
|
2
3
|
class Check
|
3
|
-
def self.go(
|
4
|
-
require LIB_DIR + 'common'
|
5
|
-
require 'json'
|
4
|
+
def self.go(options)
|
6
5
|
app = KRL_COMMON::get_app
|
7
6
|
krl_file = File.join(Dir.pwd, app.application_id + ".krl")
|
8
7
|
raise "Cannot find .krl file." unless File.exists?(krl_file)
|
9
|
-
if
|
10
|
-
apiurl = "
|
8
|
+
if options["parser"]
|
9
|
+
apiurl = options["parser"]
|
11
10
|
else
|
12
|
-
apiurl =
|
11
|
+
apiurl = "http://krl.kobj.net/manage/parse/ruleset"
|
13
12
|
end
|
14
13
|
apiargs = { "krl" => File.open(krl_file, 'r') { |f| f.read } }
|
15
14
|
validateresponse = KRL_COMMON::long_post_form(URI.parse(apiurl), apiargs).body.to_s
|
data/lib/checkout.rb
CHANGED
@@ -1,32 +1,67 @@
|
|
1
|
-
require LIB_DIR + 'user'
|
2
1
|
require 'fileutils'
|
3
2
|
|
4
3
|
module KRL_CMD
|
5
4
|
class Checkout
|
6
|
-
|
7
|
-
|
5
|
+
|
6
|
+
def self.go(ruleset, options)
|
7
|
+
begin
|
8
|
+
c = self.new(ruleset, options)
|
9
|
+
c.checkout
|
10
|
+
rescue Exception => e
|
11
|
+
puts e.message
|
12
|
+
ap e.backtrace if $DEBUG
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(ruleset, options)
|
17
|
+
@user = User.new
|
18
|
+
@ruleset = ruleset
|
19
|
+
@include_title = options["title"]
|
20
|
+
@all = options["all"]
|
8
21
|
app = KRL_COMMON::get_app rescue nil
|
9
|
-
raise "You are already in an application: #{app.application_id}" if app
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
File.open(root_dir + "/.app", "w") { |f| f.print(app_details.to_yaml) }
|
27
|
-
File.open(root_dir + "/#{ruleset_id}.krl", "w") { |f| f.print(app.krl) }
|
22
|
+
raise "You are already in an application directory: #{app.application_id}" if app
|
23
|
+
end
|
24
|
+
|
25
|
+
def checkout
|
26
|
+
|
27
|
+
if @all
|
28
|
+
@user.applications["apps"].each do |app|
|
29
|
+
begin
|
30
|
+
@ruleset = app["appid"]
|
31
|
+
do_checkout
|
32
|
+
rescue => e
|
33
|
+
puts e.message
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
do_checkout
|
38
|
+
end
|
28
39
|
|
29
40
|
|
30
41
|
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def do_checkout
|
46
|
+
app = @user.find_application({:application_id => @ruleset})
|
47
|
+
if app
|
48
|
+
dir_name = @include_title && app.name ? "#{@ruleset}-#{app.name}" : @ruleset
|
49
|
+
puts "Checking out: #{dir_name}"
|
50
|
+
root_dir = Dir.pwd + "/#{dir_name}"
|
51
|
+
raise "Directory already exists (#{root_dir})." if File.exists?(root_dir)
|
52
|
+
|
53
|
+
puts "Creating directory: #{root_dir}"
|
54
|
+
FileUtils.mkdir root_dir
|
55
|
+
app_details = {
|
56
|
+
:name => app.name,
|
57
|
+
:ruleset_id => app.application_id,
|
58
|
+
:role => @user.owns_current? ? "owner" : "developer"
|
59
|
+
}
|
60
|
+
File.open(root_dir + "/.app", "w") { |f| f.print(app_details.to_yaml) }
|
61
|
+
File.open(root_dir + "/#{app.application_id}.krl", "w") { |f| f.print(app.krl) }
|
62
|
+
else
|
63
|
+
puts "Unable to find ruleset #{@ruleset}. You probably don't have permission to check it out."
|
64
|
+
end
|
65
|
+
end
|
31
66
|
end
|
32
67
|
end
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
module KRL_CMD
|
2
|
+
LIB_DIR = File.dirname(__FILE__) + "/../lib/"
|
3
|
+
%w(user apps checkout create update versions deploy
|
4
|
+
commit show note check generate test info stats).each do |cmd|
|
5
|
+
autoload cmd.capitalize.to_sym, LIB_DIR + cmd
|
6
|
+
end
|
7
|
+
autoload :KRL_COMMON, LIB_DIR + 'common'
|
8
|
+
|
9
|
+
|
10
|
+
class CLI < Thor
|
11
|
+
|
12
|
+
desc "apps", "Display a list of apps"
|
13
|
+
def apps
|
14
|
+
KRL_CMD::Apps.go
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "checkout [RULESET]", "Creates a directory structure with the rulesets you have checked out."
|
18
|
+
#method_option :type => :string, :required => true
|
19
|
+
method_option :title, :type => :boolean, :default => false, :aliases => "-t", :banner => "Include the title in the name of the directory."
|
20
|
+
method_option :all, :type => :boolean, :default => false, :aliases => "-a", :banner => "Checkout all of your rulesets into this directory."
|
21
|
+
#method_option :ruleset, :type => :string, :default => false, :aliases => "-r", :banner => "Ruleset ID, example: a1x1"
|
22
|
+
def checkout(ruleset="")
|
23
|
+
if ruleset.empty? && options["all"].nil?
|
24
|
+
say "Please specify either --ruleset or --all", :red
|
25
|
+
say help "checkout"
|
26
|
+
else
|
27
|
+
KRL_CMD::Checkout.go(ruleset, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "create [NAME]", "Creates a new ruleset and checks it out into the the directory."
|
32
|
+
method_option :title, :type => :boolean, :default => false, :aliases => "-t", :banner => "Include the name of the ruleset in the directory name"
|
33
|
+
method_option :description, :type => :string, :required => false, :aliases => "-d", :banner => "Description for the ruleset"
|
34
|
+
def create(name)
|
35
|
+
KRL_CMD::Create.go(name, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "update", "Updates the krl in the ruleset directory to the a specified version."
|
39
|
+
method_option :version, :type => :string, :required => false, :default => "development", :aliases => "-v", :banner => "Version number or 'production' or 'development'"
|
40
|
+
method_option :save, :type => :boolean, :default => false, :aliases => '-s', :banner => "Save a copy of the existing .krl file"
|
41
|
+
def update
|
42
|
+
begin
|
43
|
+
KRL_CMD::Update.go(options)
|
44
|
+
rescue => e
|
45
|
+
say e.message, :red
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "versions", "Displays a list of the ruleset versions."
|
50
|
+
method_option :limit, :type => :numeric, :default => 0, :aliases => "-l", :banner => "Limit the number of versions to show. 0 will show all available versions."
|
51
|
+
def versions
|
52
|
+
begin
|
53
|
+
KRL_CMD::Versions.go(options)
|
54
|
+
rescue => e
|
55
|
+
say e.message, :red
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "deploy", "Deploys a given version to production. If no version is supplied, the latest version is deployed."
|
60
|
+
method_option :version, :type => :numeric, :required => false, :aliases => "-v", :banner => "Version to be deployed."
|
61
|
+
def deploy
|
62
|
+
begin
|
63
|
+
KRL_CMD::Deploy.go(options)
|
64
|
+
rescue => e
|
65
|
+
say e.message, :red
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "commit", "Commits or saves the .krl file to the Kynetx platform."
|
70
|
+
method_option :note, :type => :string, :required => false, :aliases => "-n", :banner => "Add a note to the commit"
|
71
|
+
method_option :deploy, :type => :boolean, :required => false, :aliases => "-d", :banner => "Deploy the ruleset after it has been committed."
|
72
|
+
def commit
|
73
|
+
begin
|
74
|
+
KRL_CMD::Commit.go(options)
|
75
|
+
rescue => e
|
76
|
+
say e.message, :red
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc "show", "Shows the krl for the ruleset for a given version"
|
81
|
+
method_option :version, :type => :string, :default => "development", :aliases => "-v", :banner => "Version of the KRL to show."
|
82
|
+
def show
|
83
|
+
begin
|
84
|
+
KRL_CMD::Show.go(options)
|
85
|
+
rescue => e
|
86
|
+
say e.message, :red
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "note", "Adds a note to a ruleset version"
|
91
|
+
method_option :version, :type => :string, :default => "development", :aliases => "-v", :banner => "Version of the KRL to show."
|
92
|
+
method_option :note, :type => :string, :required => true, :aliases => "-n", :banner => "Note to be added."
|
93
|
+
def note
|
94
|
+
begin
|
95
|
+
KRL_CMD::Note.go(options)
|
96
|
+
rescue => e
|
97
|
+
say e.message, :red
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "check", "Performs a syntax check of your KRL file."
|
102
|
+
method_option :parser, :type => :string, :required => false, :aliases => "-p", :banner => "Full URL to an alternate parser to check the krl against."
|
103
|
+
def check
|
104
|
+
begin
|
105
|
+
KRL_CMD::Check.go(options)
|
106
|
+
rescue => e
|
107
|
+
say e.message, :red
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "generate [ENDPOINT]", "Generates an endpoint from the ruleset. Endpoint must be firefox, chrome, ie, bookmarklet, or infocard."
|
112
|
+
method_option :environment, :type => :string, :default => "prod", :aliases => "-e", :banner => "Environment. Must be either 'prod' or 'dev'."
|
113
|
+
method_option :defaults, :type => :boolean, :default => true, :aliases => "-d", :banner => "Use the defaults and don't prompt for more information."
|
114
|
+
method_option :force, :type => :boolean, :default => false, :aliases => "-f", :banner => "Force a rebuild of the endpoint rather than use the cached copy."
|
115
|
+
long_desc <<-D
|
116
|
+
Generates an endpoint for the ruleset. Endpoints are placed in the ./endpoints directory
|
117
|
+
or ./test directory depending on the environment specified. Current endpoints available are:
|
118
|
+
firefox (Mozilla Firefox), chrome (Google Chrome), ie (Microsoft Internet Explorer), bookmarklet (HTML Bookmarklet),
|
119
|
+
infocard (Info Card, see http://en.wikipedia.org/wiki/Information_Card).
|
120
|
+
Infocards generated here are used in the Azigo Card Selector.
|
121
|
+
See http://www.azigo.com
|
122
|
+
D
|
123
|
+
def generate(endpoint)
|
124
|
+
begin
|
125
|
+
KRL_CMD::Generate.go(endpoint, options)
|
126
|
+
rescue => e
|
127
|
+
say e.message, :red
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
desc "test", "Test has been deprecated, use 'generate -e dev'"
|
132
|
+
def test
|
133
|
+
say "'test' has been deprecated. Use 'generate -e dev'", :red
|
134
|
+
help "generate"
|
135
|
+
end
|
136
|
+
|
137
|
+
desc "info", "Display information about a ruleset"
|
138
|
+
method_option :app, :type => :string, :required => false, :aliases => "-a", :banner => "Ruleset for which to show information"
|
139
|
+
def info
|
140
|
+
begin
|
141
|
+
KRL_CMD::Info.go(options)
|
142
|
+
rescue => e
|
143
|
+
say e.message, :red
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
desc "stats", "Display basic stats for the ruleset. NOTE: You must be the owner of the app to see stats."
|
148
|
+
method_option :range, :type => :string, :default => "previous_day", :aliases => "-r", :banner => "Specify the range for the stats."
|
149
|
+
method_option :format, :type => :string, :default => "table", :aliases => "-f", :banner => "Format of the data. (table, json)"
|
150
|
+
def stats
|
151
|
+
begin
|
152
|
+
KRL_CMD::Stats.kpis(options)
|
153
|
+
rescue => e
|
154
|
+
say e.message, :red
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
desc "stats_interface", "Display the available options for running a stats query."
|
159
|
+
def stats_interface
|
160
|
+
begin
|
161
|
+
KRL_CMD::Stats.interface
|
162
|
+
rescue => e
|
163
|
+
say e.message, :red
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
desc "account_stats", "Display stats for the Kynetx account."
|
168
|
+
method_option :range, :type => :string, :default => "previous_day", :aliases => "-r", :banner => "Specify the range for the stats."
|
169
|
+
method_option :format, :type => :string, :default => "table", :aliases => "-f", :banner => "Format of the data. (table, json)"
|
170
|
+
def account_stats
|
171
|
+
begin
|
172
|
+
KRL_CMD::Stats.account_kpis(options)
|
173
|
+
rescue => e
|
174
|
+
say e.message, :red
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
desc "logging", "Displays values logged with explicit logging for the ruleset"
|
179
|
+
method_option :range, :type => :string, :default => "previous_day", :aliases => "-r", :banner => "Specify the range for the stats."
|
180
|
+
def logging
|
181
|
+
begin
|
182
|
+
KRL_CMD::Stats.logging(options)
|
183
|
+
rescue => e
|
184
|
+
say e.message, :red
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
desc "stats_query", "Build a custom stats query"
|
189
|
+
long_desc <<-D
|
190
|
+
Allows you to create a custom query for stats. Queries can be helpful for pulling
|
191
|
+
custom or ad-hoc data from the Kynetx data warehouse.
|
192
|
+
|
193
|
+
- Dimensions are fields that can be grouped and specified in a condition.
|
194
|
+
|
195
|
+
- KPIs, or sometimes called Facts, are data that is aggregated and cannot be included in a condition
|
196
|
+
|
197
|
+
- Contitions are specified in key value pairs, for example: 'dim:value' separated by a space.
|
198
|
+
|
199
|
+
- Ranges are preset date ranges for the query. All queries have a default range of 'previous_day'.
|
200
|
+
|
201
|
+
All available Dimensions, KPIs, and Ranges can be seen by running 'krl stats_interface'
|
202
|
+
|
203
|
+
Examples:\n
|
204
|
+
krl stats_query -k brse -d ruleset day -r last_thirty_days \n
|
205
|
+
krl stats_query -k rse brse -d am_pm hour interval_15 -r current_month -c hour:00 \n
|
206
|
+
krl stats_query -k rse brse -d am_pm hour interval_15 -r current_month -c hour:00 interval_15:00\n
|
207
|
+
krl stats_query -k brse -d day_of_week day -r current_month -c day_of_week_abbr:Wed
|
208
|
+
|
209
|
+
All data is available as both a table or as JSON. To specify the format, use the --format option.
|
210
|
+
|
211
|
+
D
|
212
|
+
method_option :kpis, :type => :array, :required => true, :aliases => "-k", :banner => ""
|
213
|
+
method_option :dims, :type => :array, :required => true, :aliases => "-d", :banner => ""
|
214
|
+
method_option :conditions, :type => :hash, :required => false, :aliases => "-c", :banner => "Conditions for the query as 'dim:value'."
|
215
|
+
method_option :range, :type => :string, :default => "previous_day", :aliases => "-r", :banner => "Specify the range for the stats."
|
216
|
+
method_option :format, :type => :string, :default => "table", :aliases => "-f", :banner => "Format of the data. (table, json)"
|
217
|
+
def stats_query
|
218
|
+
begin
|
219
|
+
KRL_CMD::Stats.query(options)
|
220
|
+
rescue => e
|
221
|
+
say e.message, :red
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
end
|
data/lib/commit.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Commit
|
3
|
-
def self.go(
|
4
|
-
require LIB_DIR + 'common'
|
3
|
+
def self.go(options)
|
5
4
|
app = KRL_COMMON::get_app
|
6
5
|
krl_file = File.join(Dir.pwd, app.application_id + ".krl")
|
7
6
|
if File.exists?(krl_file)
|
8
7
|
begin
|
9
8
|
app.krl = File.open(krl_file, 'r') { |f| f.read }
|
10
|
-
app.set_version_note(app.version,
|
11
|
-
puts "Committed version #{app.version}"
|
9
|
+
app.set_version_note(app.version, options["note"]) if options["note"]
|
10
|
+
puts "Committed version: #{app.version}"
|
11
|
+
if options["deploy"]
|
12
|
+
KRL_CMD::Deploy.go({"version" => app.version})
|
13
|
+
end
|
12
14
|
rescue KRLParseError => e
|
13
15
|
puts "Unable to parse your krl."
|
14
16
|
puts "Errors:"
|
data/lib/common.rb
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
require 'terminal-table/import'
|
2
2
|
require 'net/http'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
5
|
module KRL_COMMON
|
5
|
-
def self.pretty_table(collection, fields, limit=0)
|
6
|
+
def self.pretty_table(collection, fields, limit=0, limit_last=false)
|
7
|
+
raise "Nothing to present" if collection.empty?
|
6
8
|
ptable = table do |t|
|
7
9
|
|
8
10
|
t.headings = fields.collect{ |h| h[:field] }
|
9
11
|
counter = 0
|
10
12
|
collection.each do |c|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
show_row = true
|
14
|
+
|
15
|
+
if limit_last && limit > 0
|
16
|
+
# This will make it so that the last items in the table are
|
17
|
+
# shown rather than the first when a limit is specified.
|
18
|
+
show_row = (counter + 1) > (collection.length - limit)
|
19
|
+
end
|
20
|
+
|
21
|
+
if show_row
|
22
|
+
row = []
|
23
|
+
fields.each do |f|
|
24
|
+
row << f[:value].call(c) if show_row
|
25
|
+
end
|
26
|
+
t << row
|
14
27
|
end
|
15
|
-
t << row
|
16
28
|
counter += 1
|
17
|
-
break if limit > 0 && limit == counter
|
29
|
+
break if limit > 0 && limit == counter && ! limit_last
|
18
30
|
end
|
19
31
|
|
20
32
|
end
|
@@ -22,10 +34,9 @@ module KRL_COMMON
|
|
22
34
|
end
|
23
35
|
|
24
36
|
def self.get_app(version="development")
|
25
|
-
require LIB_DIR + "user"
|
26
37
|
begin
|
27
38
|
root_dir = Dir.pwd
|
28
|
-
raise "Please re-checkout your
|
39
|
+
raise "Please re-checkout your ruleset or make sure you are in the root directory of a ruleset." unless File.exists?(File.join(root_dir, ".app"))
|
29
40
|
config_file = File.join(root_dir, '.app')
|
30
41
|
raise "Unable to get the app information. You need to recheckout your app." unless File.exists?(config_file)
|
31
42
|
config = YAML::load_file(config_file)
|
@@ -33,7 +44,7 @@ module KRL_COMMON
|
|
33
44
|
app = user.find_application(:application_id => config[:ruleset_id], :version => version)
|
34
45
|
return app
|
35
46
|
rescue Exception => e
|
36
|
-
raise "Unable to get
|
47
|
+
raise "Unable to get ruleset information. #{e.message}"
|
37
48
|
end
|
38
49
|
|
39
50
|
end
|
data/lib/create.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Create
|
3
|
-
def self.go(
|
4
|
-
|
5
|
-
name = args.first
|
6
|
-
desc = args.last # if description wasn't specified, set it to the name
|
7
|
-
require LIB_DIR + 'user'
|
8
|
-
require LIB_DIR + 'checkout'
|
3
|
+
def self.go(name, options)
|
4
|
+
desc = options["description"] ? options["description"] : name
|
9
5
|
user = KRL_CMD::User.new
|
10
6
|
new_app = user.create_application(name, desc)
|
11
|
-
|
7
|
+
checkout_opts = {
|
8
|
+
"ruleset" => new_app.application_id,
|
9
|
+
"title" => options["title"]
|
10
|
+
}
|
11
|
+
KRL_CMD::Checkout.go(checkout_opts)
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
data/lib/deploy.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Deploy
|
3
|
-
def self.go(
|
4
|
-
require LIB_DIR + 'common'
|
3
|
+
def self.go(options)
|
5
4
|
app = KRL_COMMON::get_app
|
6
|
-
prod_version =
|
5
|
+
prod_version = options["version"] ? options["version"] : app.version
|
7
6
|
app.production_version = prod_version
|
8
7
|
puts "Deployed version: #{app.production_version}"
|
9
|
-
|
10
8
|
end
|
11
9
|
end
|
12
|
-
end
|
10
|
+
end
|
data/lib/generate.rb
CHANGED
@@ -7,48 +7,68 @@ require 'launchy'
|
|
7
7
|
|
8
8
|
module KRL_CMD
|
9
9
|
class Generate
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
include Thor::Shell
|
11
|
+
def self.go(endpoint, options)
|
12
|
+
g = self.new(endpoint,options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(endpoint, options)
|
16
|
+
@shell = Basic.new
|
17
|
+
@endpoint = endpoint
|
18
|
+
@environment = options["environment"]
|
19
|
+
@use_defaults = options["defaults"]
|
20
|
+
@force = options["force"]
|
21
|
+
@app = KRL_COMMON::get_app
|
22
|
+
@user = KRL_CMD::User.new
|
13
23
|
endpoints = {
|
14
|
-
"firefox" => lambda {gen_extension
|
15
|
-
"chrome" => lambda {gen_extension
|
16
|
-
"ie" => lambda {gen_extension
|
17
|
-
"bookmarklet" => lambda {gen_bookmarklet
|
18
|
-
"infocard" => lambda {gen_infocard
|
24
|
+
"firefox" => lambda {gen_extension},
|
25
|
+
"chrome" => lambda {gen_extension},
|
26
|
+
"ie" => lambda {gen_extension},
|
27
|
+
"bookmarklet" => lambda {gen_bookmarklet},
|
28
|
+
"infocard" => lambda {gen_infocard}
|
19
29
|
}
|
20
|
-
if endpoints[
|
21
|
-
endpoints[
|
30
|
+
if endpoints[@endpoint]
|
31
|
+
endpoints[@endpoint].call
|
22
32
|
else
|
23
|
-
raise "Unknown endpoint specified (#{
|
33
|
+
raise "Unknown endpoint specified (#{@endpoint})"
|
24
34
|
end
|
35
|
+
|
25
36
|
|
26
37
|
end
|
27
38
|
|
28
|
-
def
|
29
|
-
puts "Generating Extension (#{
|
30
|
-
|
31
|
-
|
39
|
+
def gen_extension
|
40
|
+
puts "Generating Extension (#{@endpoint} - #{@environment})"
|
41
|
+
|
42
|
+
if @use_defaults
|
43
|
+
extname, extauthor, extdesc = "", "", ""
|
44
|
+
else
|
45
|
+
extname = @shell.ask("Name of the extension (#{@app.name}):")
|
46
|
+
extauthor = @shell.ask("Name of the author (#{@user.name}):")
|
47
|
+
extdesc = @shell.ask("Description:")
|
48
|
+
end
|
32
49
|
|
33
50
|
opts = {}
|
34
|
-
opts[:extname] =
|
35
|
-
opts[:extauthor] =
|
36
|
-
opts[:extdesc] =
|
37
|
-
opts[:env] =
|
51
|
+
opts[:extname] = extname unless extname.empty?
|
52
|
+
opts[:extauthor] = extauthor unless extauthor.empty?
|
53
|
+
opts[:extdesc] = extdesc unless extdesc.empty?
|
54
|
+
opts[:env] = @environment
|
55
|
+
opts[:force_build] = @force ? "Y" : "N"
|
38
56
|
opts[:format] = 'url'
|
39
57
|
|
40
|
-
ext = app.endpoint(
|
41
|
-
write_file(ext
|
58
|
+
ext = @app.endpoint(@endpoint, opts)
|
59
|
+
write_file(ext)
|
42
60
|
end
|
43
61
|
|
44
|
-
def
|
45
|
-
puts "Generating Bookmarklet (#{
|
62
|
+
def gen_bookmarklet
|
63
|
+
puts "Generating Bookmarklet (#{@environment})"
|
46
64
|
bm = ""
|
47
65
|
opts = {}
|
48
|
-
opts[:env] =
|
49
|
-
|
66
|
+
opts[:env] = @environment
|
67
|
+
if ! @use_defaults
|
68
|
+
opts[:runtime] = @shell.ask("Runtime to use for the bookmarklet (blank for default):")
|
69
|
+
end
|
50
70
|
|
51
|
-
endpoint = app.endpoint(:bookmarklet, opts)
|
71
|
+
endpoint = @app.endpoint(:bookmarklet, opts)
|
52
72
|
|
53
73
|
if endpoint["errors"].empty?
|
54
74
|
bm = endpoint["data"]
|
@@ -56,10 +76,10 @@ module KRL_CMD
|
|
56
76
|
raise "Invalid bookmark generated. \n#{endpoint.errors.join("\n")}"
|
57
77
|
end
|
58
78
|
|
59
|
-
bm_file = File.join(get_endpoint_dir
|
79
|
+
bm_file = File.join(get_endpoint_dir, @environment + "_bookmarklet.html")
|
60
80
|
File.open(bm_file, 'w') do |f|
|
61
81
|
f.print("<textarea rows='5' cols='100'>#{bm}</textarea><br><br>")
|
62
|
-
link =
|
82
|
+
link = @environment == "prod" ? @app.name : @environment + "_" + @app.name
|
63
83
|
f.print("<a href=\"#{bm.gsub('"', '"')}\">#{link}</a>")
|
64
84
|
end
|
65
85
|
puts "BOOKMARKLET:"
|
@@ -69,36 +89,40 @@ module KRL_CMD
|
|
69
89
|
Launchy::Browser.run('file://' + bm_file)
|
70
90
|
end
|
71
91
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
92
|
+
def gen_infocard
|
93
|
+
puts "Generating Infocard (#{@environment})"
|
94
|
+
|
95
|
+
if @use_defaults
|
96
|
+
extname = ""
|
97
|
+
datasets = ""
|
98
|
+
else
|
99
|
+
extname = @shell.ask("Name of the infocard (#{@app.name}):")
|
100
|
+
datasets = @shell.ask("Datasets:")
|
101
|
+
end
|
102
|
+
|
75
103
|
opts = {}
|
76
|
-
opts[:extname] =
|
77
|
-
opts[:datasets] =
|
78
|
-
opts[:env] =
|
104
|
+
opts[:extname] = extname unless extname.empty?
|
105
|
+
opts[:datasets] = datasets unless datasets.empty?
|
106
|
+
opts[:env] = @environment
|
79
107
|
opts[:format] = 'url'
|
80
108
|
|
81
|
-
icard = app.endpoint(:info_card, opts)
|
82
|
-
write_file(icard
|
109
|
+
icard = @app.endpoint(:info_card, opts)
|
110
|
+
write_file(icard)
|
83
111
|
end
|
84
112
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
return @@app
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.get_endpoint_dir(env)
|
93
|
-
dir_name = env == "prod" ? "/endpoints" : "/test"
|
113
|
+
private
|
114
|
+
|
115
|
+
def get_endpoint_dir
|
116
|
+
dir_name = @environment == "prod" ? "/endpoints" : "/test"
|
94
117
|
endpoint_dir = Dir.pwd + dir_name
|
95
118
|
FileUtils.mkdir(endpoint_dir) unless File.directory?(endpoint_dir)
|
96
119
|
return endpoint_dir
|
97
120
|
end
|
98
121
|
|
99
|
-
|
122
|
+
|
123
|
+
def write_file(ext)
|
100
124
|
if ext["errors"].empty?
|
101
|
-
endpoint_dir = get_endpoint_dir
|
125
|
+
endpoint_dir = get_endpoint_dir
|
102
126
|
ext_file_name = File.join(endpoint_dir, ext["file_name"])
|
103
127
|
url = URI.parse(ext["data"])
|
104
128
|
|
data/lib/info.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Info
|
3
|
-
def self.go(
|
4
|
-
require LIB_DIR + 'user'
|
5
|
-
require LIB_DIR + 'common'
|
6
|
-
require 'pp'
|
3
|
+
def self.go(options)
|
7
4
|
user = User.new
|
8
5
|
app_id = nil
|
9
|
-
if(
|
10
|
-
app_id =
|
6
|
+
if(options["app"] && options["app"].length > 0)
|
7
|
+
app_id = options["app"]
|
11
8
|
else
|
12
9
|
app_id = KRL_COMMON::get_app().application_id rescue nil
|
13
10
|
end
|
14
|
-
raise "Unable to determine the application id.
|
11
|
+
raise "Unable to determine the application id. Use 'krl help info' for more information." unless app_id
|
15
12
|
|
16
13
|
app_info = user.api.get_app_info(app_id)
|
17
14
|
app_details = user.api.get_app_details(app_id)
|
@@ -43,4 +40,4 @@ module KRL_CMD
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
46
|
-
end
|
43
|
+
end
|
data/lib/note.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Note
|
3
|
-
def self.go(
|
4
|
-
raise "Please supply a version and a note. (note must be enclosed in quotes)" unless args.length == 2
|
5
|
-
version = args.first.to_i
|
6
|
-
note = args.last.to_s
|
7
|
-
require LIB_DIR + 'common'
|
3
|
+
def self.go(options)
|
8
4
|
app = KRL_COMMON::get_app
|
5
|
+
version = options["version"] ? options["version"] : app.version
|
6
|
+
note = options["note"]
|
9
7
|
app.set_version_note(version, note)
|
10
8
|
puts "Done."
|
11
9
|
end
|
12
10
|
end
|
13
|
-
end
|
11
|
+
end
|
data/lib/show.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Show
|
3
|
-
def self.go(
|
4
|
-
version =
|
5
|
-
require LIB_DIR + 'common'
|
3
|
+
def self.go(options)
|
4
|
+
version = options["version"]
|
6
5
|
app = KRL_COMMON::get_app
|
7
6
|
puts "KRL for version #{version}"
|
8
7
|
puts app.krl(version)
|
9
8
|
end
|
10
9
|
end
|
11
|
-
end
|
10
|
+
end
|
data/lib/stats.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'json'
|
2
|
+
module KRL_CMD
|
3
|
+
class Stats
|
4
|
+
def self.interface
|
5
|
+
user = KRL_CMD::User.new
|
6
|
+
begin
|
7
|
+
p_interface = user.stats_interface
|
8
|
+
puts "-- Dimensions --"
|
9
|
+
p_interface["dims"].each {|s| puts "\t" + s}
|
10
|
+
puts
|
11
|
+
puts "-- KPIS --"
|
12
|
+
p_interface["kpis"].each {|s| puts "\t" + s}
|
13
|
+
puts
|
14
|
+
puts "-- Ranges --"
|
15
|
+
p_interface["ranges"].each {|s| puts "\t" + s}
|
16
|
+
rescue
|
17
|
+
raise "There was an error trying to retrieve the stats interface"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.kpis(options)
|
22
|
+
app = KRL_COMMON::get_app
|
23
|
+
begin
|
24
|
+
data = app.kpis(options["range"])
|
25
|
+
display_stats(data, %w(DAY RSE BRSE CALLBACKS RULES RULES_FIRED ACTIONS), options["format"])
|
26
|
+
rescue => e
|
27
|
+
ap e.message if $DEBUG
|
28
|
+
ap e.backtrace if $DEBUG
|
29
|
+
raise e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.account_kpis(options)
|
35
|
+
user = KRL_CMD::User.new
|
36
|
+
begin
|
37
|
+
data = user.kpis([], options["range"])
|
38
|
+
display_stats(data, %w(RULESET DAY RSE BRSE CALLBACKS RULES RULES_FIRED ACTIONS), options["format"])
|
39
|
+
rescue => e
|
40
|
+
ap e.message if $DEBUG
|
41
|
+
ap e.backtrace if $DEBUG
|
42
|
+
raise e.message
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.logging(options)
|
47
|
+
app = KRL_COMMON::get_app
|
48
|
+
begin
|
49
|
+
data = app.logging(options["range"])
|
50
|
+
display_stats(data, [], "json")
|
51
|
+
rescue => e
|
52
|
+
ap e.message if $DEBUG
|
53
|
+
ap e.backtrace if $DEBUG
|
54
|
+
raise e.message
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.query(options)
|
59
|
+
user = KRL_CMD::User.new
|
60
|
+
if options["conditions"]
|
61
|
+
conditions = []
|
62
|
+
options["conditions"].each {|k,v| conditions << {:field => k, :value => v}}
|
63
|
+
else
|
64
|
+
conditions = nil
|
65
|
+
end
|
66
|
+
begin
|
67
|
+
data = user.api.get_stats_query(
|
68
|
+
options["kpis"].join(","),
|
69
|
+
options["dims"].join(","),
|
70
|
+
conditions,
|
71
|
+
options["range"]
|
72
|
+
)
|
73
|
+
fields = []
|
74
|
+
(options["dims"] + options["kpis"]).each {|v| fields << v.upcase}
|
75
|
+
display_stats(data, fields, options["format"])
|
76
|
+
|
77
|
+
rescue => e
|
78
|
+
ap e.message #if $DEBUG
|
79
|
+
ap e.backtrace #if $DEBUG
|
80
|
+
raise "Unable to retrieve query results. #{e.message}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
|
88
|
+
def self.display_stats(data, fields, format)
|
89
|
+
field_opts = []
|
90
|
+
fields.each do |field|
|
91
|
+
field_opts << {:field => field, :value => lambda { |r| r[field].to_s }}
|
92
|
+
end
|
93
|
+
if data["valid"] == true
|
94
|
+
if format == "table"
|
95
|
+
KRL_COMMON.pretty_table(data["data"], field_opts)
|
96
|
+
elsif format == "json"
|
97
|
+
puts JSON.pretty_generate(data["data"])
|
98
|
+
else
|
99
|
+
raise "Unknown format (#{format})"
|
100
|
+
end
|
101
|
+
|
102
|
+
else
|
103
|
+
raise data["error"]
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
data/lib/update.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
module KRL_CMD
|
2
3
|
class Update
|
3
|
-
def self.go(
|
4
|
-
version =
|
5
|
-
require LIB_DIR + 'common'
|
4
|
+
def self.go(options)
|
5
|
+
version = options["version"]
|
6
6
|
app = KRL_COMMON::get_app
|
7
7
|
root_dir = Dir.pwd
|
8
|
-
File.
|
8
|
+
krl_file = File.join(Dir.pwd, app.application_id + ".krl")
|
9
|
+
|
10
|
+
if File.exists?(krl_file) && options["save"]
|
11
|
+
backup_file = app.application_id + ".saved.krl"
|
12
|
+
raise "Backup file already exists (#{backup_file}). Your krl was not updated. Please rename or delete your existing backup file." if File.exists?(backup_file)
|
13
|
+
FileUtils.cp(krl_file, backup_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
File.open(krl_file, "w") { |f| f.print(app.krl(version)) }
|
9
17
|
puts "Updated to version: #{version}"
|
10
18
|
end
|
11
19
|
end
|
12
|
-
end
|
20
|
+
end
|
data/lib/versions.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module KRL_CMD
|
2
2
|
class Versions
|
3
|
-
def self.go(
|
4
|
-
|
5
|
-
limit = args.to_s.to_i
|
3
|
+
def self.go(options)
|
4
|
+
limit = options["limit"]
|
6
5
|
app = KRL_COMMON::get_app
|
7
6
|
p_version = app.production_version.to_i
|
8
7
|
KRL_COMMON::pretty_table(app.versions.reverse, [
|
@@ -11,7 +10,7 @@ module KRL_CMD
|
|
11
10
|
{:field => "Date", :value => lambda { |r| r["created"].to_s }},
|
12
11
|
{:field => "Note", :value => lambda { |r| r["note"].to_s }},
|
13
12
|
{:field => "Production", :value => lambda { |r| r["version"] == p_version ? "Yes" : "No" }}
|
14
|
-
], limit)
|
13
|
+
], limit, ! limit.nil?)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Farmer, Cid Dennis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 39
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 1
|
33
|
-
-
|
34
|
-
version: 0.1.
|
33
|
+
- 30
|
34
|
+
version: 0.1.30
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
type: :runtime
|
81
81
|
version_requirements: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: awesome_print
|
84
84
|
prerelease: false
|
85
85
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
@@ -91,8 +91,38 @@ dependencies:
|
|
91
91
|
segments:
|
92
92
|
- 0
|
93
93
|
version: "0"
|
94
|
-
type: :
|
94
|
+
type: :runtime
|
95
95
|
version_requirements: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: thor
|
98
|
+
prerelease: false
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 43
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
- 14
|
108
|
+
- 6
|
109
|
+
version: 0.14.6
|
110
|
+
type: :runtime
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rspec
|
114
|
+
prerelease: false
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
type: :development
|
125
|
+
version_requirements: *id007
|
96
126
|
description: " Build your Kynetx applications with the IDE of your choice! Installing the krl gem will give you \n command line tools that provides a simple interface that is similar to git or svn.\n"
|
97
127
|
email: mjf@kynetx.com
|
98
128
|
executables:
|
@@ -106,6 +136,7 @@ files:
|
|
106
136
|
- lib/apps.rb
|
107
137
|
- lib/check.rb
|
108
138
|
- lib/checkout.rb
|
139
|
+
- lib/cli.rb
|
109
140
|
- lib/commit.rb
|
110
141
|
- lib/common.rb
|
111
142
|
- lib/create.rb
|
@@ -115,6 +146,7 @@ files:
|
|
115
146
|
- lib/info.rb
|
116
147
|
- lib/note.rb
|
117
148
|
- lib/show.rb
|
149
|
+
- lib/stats.rb
|
118
150
|
- lib/test.rb
|
119
151
|
- lib/update.rb
|
120
152
|
- lib/user.rb
|