wpcli 0.1.1 → 0.1.2
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 +1 -1
- data/lib/wpcli/client.rb +11 -9
- data/lib/wpcli/version.rb +1 -1
- data/spec/wpcli/client_spec.rb +52 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 560f99a2ca9a0c5b2045fa77d4bf89853802c9b5
|
4
|
+
data.tar.gz: 44257dfbf43d531180b5149ace6f2728d1304947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73bcc7de07cba8cd5df628b7a989d5583009fc989c929922aab4437a31c545fe7416c0987f700a577b64c745d9c0352c1327bd68ecbed337aa17225ef786679
|
7
|
+
data.tar.gz: 0ed2030655252ca8972364cfee879cd9c81d5116723ecb4fff73f84bebe67d2e5ec284fd347bcba510fdd36ca7fc7215f9b8089daafe12071e094b9a17929e6a
|
data/README.md
CHANGED
data/lib/wpcli/client.rb
CHANGED
@@ -11,35 +11,37 @@ module Wpcli
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def parse text
|
14
|
+
first_data_row = starts_with_plus?(text) ? 3 : 1
|
14
15
|
rows = []
|
15
16
|
text.split("\n").each_with_index do |line, index|
|
16
|
-
unless
|
17
|
-
|
18
|
-
|
17
|
+
unless starts_with_plus? line
|
18
|
+
separator = line.include?('|') ? '|' : "\t"
|
19
|
+
if index < first_data_row
|
20
|
+
@columns = parse_header line, separator
|
19
21
|
else
|
20
|
-
rows << parse_line(line)
|
22
|
+
rows << parse_line(line, separator)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
rows
|
25
27
|
end
|
26
28
|
|
27
|
-
def parse_header line
|
29
|
+
def parse_header line, separator
|
28
30
|
columns = []
|
29
|
-
line.split(
|
31
|
+
line.split(separator).each_with_index do |column, index|
|
30
32
|
columns[index] = column.strip.downcase unless column.strip.empty?
|
31
33
|
end
|
32
34
|
columns
|
33
35
|
end
|
34
|
-
def parse_line line
|
36
|
+
def parse_line line, separator
|
35
37
|
hash = {}
|
36
|
-
line.split(
|
38
|
+
line.split(separator).each_with_index do |column, index|
|
37
39
|
hash[@columns[index].to_sym] = column.strip unless @columns[index].nil?
|
38
40
|
end
|
39
41
|
hash
|
40
42
|
end
|
41
43
|
|
42
|
-
def
|
44
|
+
def starts_with_plus? line
|
43
45
|
line.start_with? "+"
|
44
46
|
end
|
45
47
|
end
|
data/lib/wpcli/version.rb
CHANGED
data/spec/wpcli/client_spec.rb
CHANGED
@@ -10,6 +10,8 @@ describe Wpcli::Client do
|
|
10
10
|
+----+--------------------------+----------------+------------------------------+---------------------+------------------------------------+
|
11
11
|
EOF
|
12
12
|
end
|
13
|
+
let(:wp_user_list_tabs_newlines) { "ID\tuser_login\tdisplay_name\tuser_email\tuser_registered\troles\n1\tadmin\tadmin\tadmin@domain.tld\t2014-01-07 09:04:08\tadministrator\n" }
|
14
|
+
|
13
15
|
|
14
16
|
let(:wp_role_list) do <<EOF
|
15
17
|
+------------------+------------------------------------+
|
@@ -69,32 +71,62 @@ EOF
|
|
69
71
|
end
|
70
72
|
|
71
73
|
context 'user list' do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
context 'pretty format' do
|
75
|
+
before :each do
|
76
|
+
@wpcli.stub(:`).with("wp user list").and_return(wp_user_list)
|
77
|
+
@array = @wpcli.run "user list"
|
78
|
+
end
|
76
79
|
|
77
|
-
|
78
|
-
|
80
|
+
describe 'returns array' do
|
81
|
+
it { @array.kind_of?(Array).should be(true) }
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
+
it 'which contains hashes' do
|
84
|
+
@array.first.kind_of?(Hash).should be(true)
|
85
|
+
end
|
83
86
|
|
84
|
-
|
85
|
-
|
87
|
+
it 'which has two hashes' do
|
88
|
+
@array.size.should eq(2)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'first hash has correct columns' do
|
92
|
+
@array.first.has_key?(:id).should be(true)
|
93
|
+
@array.first.has_key?(:display_name).should be(true)
|
94
|
+
@array.first.has_key?(:user_email).should be(true)
|
95
|
+
@array.first.has_key?(:user_registered).should be(true)
|
96
|
+
@array.first.has_key?(:user_login).should be(true)
|
97
|
+
@array.first.has_key?(:roles).should be(true)
|
98
|
+
@array.first.keys.size.should eq(6)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
context 'tabs and newlines' do
|
103
|
+
before :each do
|
104
|
+
@wpcli.stub(:`).with("wp user list").and_return(wp_user_list_tabs_newlines)
|
105
|
+
@array = @wpcli.run "user list"
|
86
106
|
end
|
87
107
|
|
88
|
-
|
89
|
-
@array.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
108
|
+
describe 'returns array' do
|
109
|
+
it { @array.kind_of?(Array).should be(true) }
|
110
|
+
|
111
|
+
it 'which contains hashes' do
|
112
|
+
@array.first.kind_of?(Hash).should be(true)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'which has two hashes' do
|
116
|
+
@array.size.should eq(1)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'first hash has correct columns' do
|
120
|
+
@array.first.has_key?(:id).should be(true)
|
121
|
+
@array.first.has_key?(:display_name).should be(true)
|
122
|
+
@array.first.has_key?(:user_email).should be(true)
|
123
|
+
@array.first.has_key?(:user_registered).should be(true)
|
124
|
+
@array.first.has_key?(:user_login).should be(true)
|
125
|
+
@array.first.has_key?(:roles).should be(true)
|
126
|
+
@array.first.keys.size.should eq(6)
|
127
|
+
end
|
96
128
|
end
|
97
129
|
end
|
98
130
|
end
|
99
131
|
end
|
100
|
-
end
|
132
|
+
end
|