wpcli 0.1.5 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/Rakefile +3 -0
- data/lib/wpcli/client.rb +19 -1
- data/lib/wpcli/version.rb +1 -1
- data/spec/wpcli/client_spec.rb +73 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7420ce749bad764f4dda2f91b153f58960e83b96
|
4
|
+
data.tar.gz: e50fd5760ae5ff81b700fce11b0a11b8e46302fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae33c6283a5f25718357318e4256e5cf4a6c6d7f11e35bab2c117846b0d415817a92e7b794586117fb9d98aba75b9d17895541360c6cda6eb955259d30a326e
|
7
|
+
data.tar.gz: 544697a49646184df988918d1ba4b87809e3db528925715da58b755db9daf34763057444ce9957744f64334b9bb04affc807e22479a9aa0e4ec8c54b5522ce7c
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Just pass commands (http://wp-cli.org/commands/) to run method and use returned
|
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
gem 'wpcli', "~> 0.
|
11
|
+
gem 'wpcli', "~> 0.2.0"
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
@@ -60,4 +60,4 @@ If you like to use client for example in command line, you can create instance w
|
|
60
60
|
4. Push to the branch (`git push origin my-new-feature`)
|
61
61
|
5. Create new Pull Request
|
62
62
|
|
63
|
-
[](http://badge.fury.io/rb/wpcli)
|
63
|
+
[](http://badge.fury.io/rb/wpcli) [](https://travis-ci.org/hasanen/wpcli)
|
data/Rakefile
CHANGED
data/lib/wpcli/client.rb
CHANGED
@@ -19,7 +19,16 @@ module Wpcli
|
|
19
19
|
if index < first_data_row
|
20
20
|
@columns = parse_header line, separator
|
21
21
|
else
|
22
|
-
|
22
|
+
if single_value_response
|
23
|
+
parsed_line = parse_line(line, separator)
|
24
|
+
value = parsed_line[:value]
|
25
|
+
unless value.nil? || value == "null"
|
26
|
+
rows << {} unless rows.size == 1
|
27
|
+
rows.first[parsed_line[:field].to_sym] = value
|
28
|
+
end
|
29
|
+
else
|
30
|
+
rows << parse_line(line, separator)
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
@@ -29,6 +38,7 @@ module Wpcli
|
|
29
38
|
def parse_header line, separator
|
30
39
|
columns = []
|
31
40
|
line.split(separator).each_with_index do |column, index|
|
41
|
+
detect_if_line_is_from_single_value_response column
|
32
42
|
columns[index] = column.strip.downcase unless column.strip.empty?
|
33
43
|
end
|
34
44
|
columns
|
@@ -44,5 +54,13 @@ module Wpcli
|
|
44
54
|
def starts_with_plus? line
|
45
55
|
line.start_with? "+"
|
46
56
|
end
|
57
|
+
|
58
|
+
def detect_if_line_is_from_single_value_response column
|
59
|
+
@single_value = column.strip.downcase == "field" unless @single_value
|
60
|
+
end
|
61
|
+
|
62
|
+
def single_value_response
|
63
|
+
@single_value
|
64
|
+
end
|
47
65
|
end
|
48
66
|
end
|
data/lib/wpcli/version.rb
CHANGED
data/spec/wpcli/client_spec.rb
CHANGED
@@ -23,8 +23,36 @@ let(:wp_user_list_tabs_newlines) { "ID\tuser_login\tdisplay_name\tuser_email\tus
|
|
23
23
|
| Contributor | contributor |
|
24
24
|
| Subscriber | subscriber |
|
25
25
|
+------------------+------------------------------------+
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:single_user) do <<EOF
|
30
|
+
+---------------------+------------------------------------+
|
31
|
+
| Field | Value |
|
32
|
+
+---------------------+------------------------------------+
|
33
|
+
| ID | 1 |
|
34
|
+
| user_login | username |
|
35
|
+
| user_pass | hash_of_paassword |
|
36
|
+
| user_nicename | Firstname Lastname |
|
37
|
+
| user_email | |
|
38
|
+
| user_url | |
|
39
|
+
| user_registered | 2013-11-25 12:41:38 |
|
40
|
+
| user_activation_key | |
|
41
|
+
| user_status | 0 |
|
42
|
+
| display_name | Nickname |
|
43
|
+
| roles | administrator |
|
44
|
+
+---------------------+------------------------------------+
|
45
|
+
EOF
|
46
|
+
end
|
47
|
+
let(:single_user_not_found) do <<EOF
|
48
|
+
+-------+-------+
|
49
|
+
| Field | Value |
|
50
|
+
+-------+-------+
|
51
|
+
| roles | null |
|
52
|
+
+-------+-------+
|
26
53
|
EOF
|
27
54
|
end
|
55
|
+
|
28
56
|
describe '.new' do
|
29
57
|
let(:path) { "path_to_wp" }
|
30
58
|
let(:command) { "user role" }
|
@@ -128,5 +156,50 @@ EOF
|
|
128
156
|
end
|
129
157
|
end
|
130
158
|
end
|
159
|
+
|
160
|
+
context 'single user' do
|
161
|
+
before :each do
|
162
|
+
@wpcli.stub(:`).with("wp user get username").and_return(single_user)
|
163
|
+
@array = @wpcli.run "user get username"
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'returns array' do
|
167
|
+
it { @array.kind_of?(Array).should be(true) }
|
168
|
+
|
169
|
+
it 'which has one hash' do
|
170
|
+
@array.size.should eq(1)
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
it 'hash has correct columns' do
|
175
|
+
@array.first.has_key?(:ID).should be(true)
|
176
|
+
@array.first.has_key?(:user_login).should be(true)
|
177
|
+
@array.first.has_key?(:user_pass).should be(true)
|
178
|
+
@array.first.has_key?(:user_nicename).should be(true)
|
179
|
+
@array.first.has_key?(:user_email).should be(true)
|
180
|
+
@array.first.has_key?(:user_url).should be(true)
|
181
|
+
@array.first.has_key?(:user_registered).should be(true)
|
182
|
+
@array.first.has_key?(:user_activation_key).should be(true)
|
183
|
+
@array.first.has_key?(:user_status).should be(true)
|
184
|
+
@array.first.has_key?(:display_name).should be(true)
|
185
|
+
@array.first.has_key?(:roles).should be(true)
|
186
|
+
@array.first.keys.size.should eq(11)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
context 'single user not found' do
|
191
|
+
before :each do
|
192
|
+
@wpcli.stub(:`).with("wp user get username").and_return(single_user_not_found)
|
193
|
+
@array = @wpcli.run "user get username"
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'returns array' do
|
197
|
+
it { @array.kind_of?(Array).should be(true) }
|
198
|
+
|
199
|
+
it 'which has zore hash' do
|
200
|
+
@array.size.should eq(0)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
131
204
|
end
|
132
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wpcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joni Hasanen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|