ugc 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,9 +2,26 @@
2
2
 
3
3
  ugc enables convenient terminal access to Apigee's App Services (aka Usergrid).
4
4
 
5
+ ## Features
6
+
7
+ * Multiple connection/login profiles
8
+ * Simple syntax
9
+ * Use relative (or absolute) URLs
10
+ * Easy-to-read tabular output
11
+ * Optionally also emits raw output (--verbose switch)
12
+
5
13
  ## Installation
6
14
 
7
15
  $ gem install ugc
16
+
17
+ Note: Requires Ruby 1.9.x. If you have issues, check your version:
18
+
19
+ $ ruby -v
20
+
21
+ If necessary, install a new version of Ruby. [RVM](Ruby 1.9.x
22
+ ) is recommended:
23
+
24
+ $ \curl -L https://get.rvm.io | bash -s stable --ruby
8
25
 
9
26
  ## Usage
10
27
 
@@ -21,7 +38,7 @@ Connect to an Apigee administrator account:
21
38
  organization = scottganyo
22
39
  $ ugc target app messagee
23
40
  application = messagee
24
- $ ugc login -a scott@ganyo.com
41
+ $ ugc login --admin scott@ganyo.com
25
42
  password: **********
26
43
  logged in user: scott@ganyo.com
27
44
 
@@ -29,3 +46,25 @@ Connect to an Apigee administrator account:
29
46
  ### Examples
30
47
 
31
48
  ![image](https://github.com/scottganyo/ugc/raw/master/examples.jpeg)
49
+
50
+ ## Release notes
51
+
52
+ ### 0.0.3
53
+ * New features
54
+ 1. support for query result paging
55
+
56
+
57
+ ## Copyright
58
+ Copyright (c) 2013 Scott Ganyo
59
+
60
+ Licensed under the Apache License, Version 2.0 (the "License");
61
+ you may not use the included files except in compliance with the License.
62
+
63
+ You may obtain a copy of the License at
64
+
65
+ <http://www.apache.org/licenses/LICENSE-2.0>
66
+
67
+ Unless required by applicable law or agreed to in writing, software distributed under
68
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
69
+ either express or implied. See the License for the specific language governing permissions and
70
+ limitations under the License.
@@ -4,6 +4,8 @@ arg_name 'url'
4
4
  command :delete do |c|
5
5
 
6
6
  c.action do |global_options,options,args|
7
+ help_now! unless args[0]
8
+
7
9
  format_result resource(args[0]).delete
8
10
  end
9
11
 
@@ -4,6 +4,8 @@ arg_name 'url'
4
4
  command :get do |c|
5
5
 
6
6
  c.action do |global_options,options,args|
7
+ help_now! unless args[0]
8
+
7
9
  format_result resource(args[0]).get
8
10
  end
9
11
 
@@ -37,6 +37,8 @@ command :ls,:list do |c|
37
37
  c.desc 'whatevers'
38
38
  c.command [:whatevers] do |c2|
39
39
  c2.action do |global_options,options,args|
40
+ help_now! unless args[0]
41
+
40
42
  whatevers = $application[args[0]].collection
41
43
  format_collection(whatevers)
42
44
  end
@@ -8,21 +8,19 @@ command :login do |c|
8
8
  c.switch [:a,:admin]
9
9
  c.action do |global_options,options,args|
10
10
 
11
- if args[0]
12
- password = ask('password: ') { |q| q.echo = '*' }
11
+ help_now! unless args[0]
13
12
 
14
- if password
15
- if options[:admin]
16
- management = Ugc::Management.new
17
- management.login args[0], password
18
- else
19
- application = Ugc::Application.new
20
- application.login args[0], password
21
- end
13
+ password = ask('password: ') { |q| q.echo = '*' }
14
+
15
+ if password
16
+ if options[:admin]
17
+ management = Ugc::Management.new
18
+ management.login args[0], password
19
+ else
20
+ application = Ugc::Application.new
21
+ application.login args[0], password
22
22
  end
23
- puts "logged in user: #{args[0]}"
24
- else
25
- raise 'username required'
26
23
  end
24
+ puts "logged in user: #{args[0]}"
27
25
  end
28
26
  end
@@ -5,6 +5,8 @@ command :post do |c|
5
5
  c.flag [:d,:data]
6
6
 
7
7
  c.action do |global_options,options,args|
8
+ help_now! unless args[0]
9
+
8
10
  format_result resource(args[0]).post (options[:data] || args[1])
9
11
  end
10
12
 
@@ -5,6 +5,8 @@ command :put do |c|
5
5
  c.flag [:d,:data]
6
6
 
7
7
  c.action do |global_options,options,args|
8
+ help_now! unless args[0]
9
+
8
10
  format_result resource(args[0]).put (options[:data] || args[1])
9
11
  end
10
12
 
@@ -22,33 +22,9 @@ command :query do |c|
22
22
  query.gsub! /from\s+#{type}/i, ''
23
23
  end
24
24
 
25
- result = $application[type].query query
25
+ response = $application[type].query query
26
26
 
27
- collection = result.collection
28
- format_collection collection, parsed_query['select']
27
+ format_collection response.collection, parsed_query['select']
29
28
  end
30
29
 
31
30
  end
32
-
33
- def parse_sql(query)
34
- result = {}
35
- keywords = %w(select from where)
36
- current = nil
37
- query.downcase.split(/[\s,*]/).each do |ea|
38
- next if ea == ''
39
- if keywords.include? ea
40
- current = ea
41
- elsif current
42
- if result[current]
43
- if result[current].is_a? Array
44
- result[current] << ea
45
- else
46
- result[current] = [result[current]] << ea
47
- end
48
- else
49
- result[current] = ea
50
- end
51
- end
52
- end
53
- result
54
- end
@@ -13,6 +13,8 @@ command :target do |c|
13
13
  c.desc 'set organization'
14
14
  c.command [:org,:organization] do |ep|
15
15
  ep.action do |global_options,options,args|
16
+ help_now! unless args[0]
17
+
16
18
  $settings.organization = args[0]
17
19
  puts "organization = #{$settings.organization}"
18
20
  end
@@ -21,6 +23,8 @@ command :target do |c|
21
23
  c.desc 'set application'
22
24
  c.command [:app,:application] do |ep|
23
25
  ep.action do |global_options,options,args|
26
+ help_now! unless args[0]
27
+
24
28
  $settings.application = args[0]
25
29
  puts "application = #{$settings.application}"
26
30
  end
@@ -1,10 +1,10 @@
1
1
  SKIP_ATTRS = %w(metadata uri type)
2
2
 
3
- def format_result(result)
4
- if result.multiple_entities? && result.collection.size > 1
5
- format_collection(result.collection)
3
+ def format_result(response)
4
+ if response.multiple_entities? && response.collection.size > 1
5
+ format_collection(response.collection)
6
6
  else
7
- format_entity(result.entity)
7
+ format_entity(response.entity)
8
8
  end
9
9
  end
10
10
 
@@ -23,7 +23,7 @@ def format_collection(collection, headers=nil)
23
23
  end
24
24
  collection.each_with_index do |entity, index|
25
25
  row do
26
- column index
26
+ column index+1
27
27
  if entity.is_a? Array
28
28
  entity.each do |v|
29
29
  column v
@@ -36,6 +36,9 @@ def format_collection(collection, headers=nil)
36
36
  end
37
37
  end
38
38
  end
39
+ if collection.cursor && agree('Next Page? (Y/N)') {|q| q.default = 'Y'}
40
+ format_collection(collection.next_page, headers)
41
+ end
39
42
  else
40
43
  puts "0 results"
41
44
  end
@@ -65,27 +68,5 @@ def equal_column_size(num_cols)
65
68
  end
66
69
 
67
70
  def terminal_columns
68
- size = detect_terminal_size
69
- size ? size[0] : 80
70
- end
71
-
72
- # Returns [width, height] of terminal when detected, nil if not detected.
73
- # Think of this as a simpler version of Highline's Highline::SystemExtensions.terminal_size()
74
- def detect_terminal_size
75
- if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
76
- [ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
77
- elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
78
- [`tput cols`.to_i, `tput lines`.to_i]
79
- elsif STDIN.tty? && command_exists?('stty')
80
- `stty size`.scan(/\d+/).map { |s| s.to_i }.reverse
81
- else
82
- nil
83
- end
84
- rescue
85
- nil
86
- end
87
-
88
- # Determines if a shell command exists by searching for it in ENV['PATH'].
89
- def command_exists?(command)
90
- ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exists? File.join(d, command) }
91
- end
71
+ HighLine.new.output_cols
72
+ end
@@ -0,0 +1,22 @@
1
+ def parse_sql(query)
2
+ result = {}
3
+ keywords = %w(select from where)
4
+ current = nil
5
+ query.downcase.split(/[\s,*]/).each do |ea|
6
+ next if ea == ''
7
+ if keywords.include? ea
8
+ current = ea
9
+ elsif current
10
+ if result[current]
11
+ if result[current].is_a? Array
12
+ result[current] << ea
13
+ else
14
+ result[current] = [result[current]] << ea
15
+ end
16
+ else
17
+ result[current] = ea
18
+ end
19
+ end
20
+ end
21
+ result
22
+ end
data/lib/ugc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ugc
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ugc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -155,6 +155,7 @@ files:
155
155
  - lib/ugc/commands/query.rb
156
156
  - lib/ugc/commands/target.rb
157
157
  - lib/ugc/helpers/formatters.rb
158
+ - lib/ugc/helpers/sql.rb
158
159
  - lib/ugc/helpers/uri.rb
159
160
  - lib/ugc/management.rb
160
161
  - lib/ugc/settings.rb
@@ -183,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
184
  version: '0'
184
185
  segments:
185
186
  - 0
186
- hash: -2123078772774079119
187
+ hash: -3089552561571580179
187
188
  required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  none: false
189
190
  requirements:
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  version: '0'
193
194
  segments:
194
195
  - 0
195
- hash: -2123078772774079119
196
+ hash: -3089552561571580179
196
197
  requirements: []
197
198
  rubyforge_project:
198
199
  rubygems_version: 1.8.24