wpcli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/rails/generators/wpcli/config/config_generator.rb +13 -0
- data/lib/rails/generators/wpcli/config/templates/config_example.yml +2 -0
- data/lib/wpcli/client.rb +46 -0
- data/lib/wpcli/rails.rb +18 -0
- data/lib/wpcli/version.rb +3 -0
- data/lib/wpcli.rb +3 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/wpcli/client_spec.rb +100 -0
- data/wpcli.gemspec +24 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a849b2e8178a23a0e8cde15cc8c99594b40863f
|
4
|
+
data.tar.gz: 0fed61f994475d5dbb66678c9fca747371572c14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f89155c9d471e6cf8e08bba469ef9c01709b3b3e32079cd514ce4a024daaf27fefdcd42f251ca4d31164fd61e3bc2b83701367544714a64d8833721049e10fb9
|
7
|
+
data.tar.gz: 7c5f30f224c711781d71ebefbdd063e0a741cbab263a62fe9acf5cc2fc4b54ba96039eda9162618508db1ef7aec5d5cde35de16df8b5b31a5eb2944a8abe0a3c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Joni Hasanen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Wpcli
|
2
|
+
|
3
|
+
Simple wrapper for wp-cli (http://wp-cli.org/).
|
4
|
+
|
5
|
+
Just pass commands (http://wp-cli.org/commands/) to run method and use returned hash as you wish.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'wpcli'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wpcli
|
20
|
+
|
21
|
+
## Rails
|
22
|
+
|
23
|
+
Simplest way to use in rails is to create config file and use methods from module.
|
24
|
+
|
25
|
+
Generate example config
|
26
|
+
|
27
|
+
rails g wpcli:config
|
28
|
+
|
29
|
+
Generated file (config/wpcli.yml)
|
30
|
+
|
31
|
+
apps:
|
32
|
+
key_for_installation: /absolute/path/for/my/wp-installation
|
33
|
+
|
34
|
+
In controller include module
|
35
|
+
|
36
|
+
class MyController < ApplicationController
|
37
|
+
include Wpcli
|
38
|
+
|
39
|
+
And then you can use client with key:
|
40
|
+
|
41
|
+
users = wpcli(:key_for_installation).run "user list"
|
42
|
+
|
43
|
+
## Alternative way
|
44
|
+
|
45
|
+
If you like to use client for example in command line, you can create instance with path of wordpress installation
|
46
|
+
|
47
|
+
@wpcli = Wpcli::Client.new "path/to/wp"
|
48
|
+
users = @wpcli.run "user list"
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Wpcli
|
2
|
+
class ConfigGenerator < Rails::Generators::Base
|
3
|
+
desc 'Generates example config for your rails app'
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@_wpcli_source_root ||= File.expand_path("../templates", __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_config_file
|
10
|
+
template 'config_example.yml', File.join('config', 'wpcli.yml')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/wpcli/client.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Wpcli
|
2
|
+
class Client
|
3
|
+
def initialize path = ""
|
4
|
+
@path = path
|
5
|
+
end
|
6
|
+
def run command
|
7
|
+
output = `wp#{@path.empty? ? " " : " --path=" + @path + " "}#{command}`
|
8
|
+
parse output
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def parse text
|
14
|
+
rows = []
|
15
|
+
text.split("\n").each_with_index do |line, index|
|
16
|
+
unless separator? line
|
17
|
+
if index < 3
|
18
|
+
@columns = parse_header line
|
19
|
+
else
|
20
|
+
rows << parse_line(line)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
rows
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_header line
|
28
|
+
columns = []
|
29
|
+
line.split('|').each_with_index do |column, index|
|
30
|
+
columns[index] = column.strip.downcase unless column.strip.empty?
|
31
|
+
end
|
32
|
+
columns
|
33
|
+
end
|
34
|
+
def parse_line line
|
35
|
+
hash = {}
|
36
|
+
line.split('|').each_with_index do |column, index|
|
37
|
+
hash[@columns[index].to_sym] = column.strip unless @columns[index].nil?
|
38
|
+
end
|
39
|
+
hash
|
40
|
+
end
|
41
|
+
|
42
|
+
def separator? line
|
43
|
+
line.start_with? "+"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/wpcli/rails.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Wpcli
|
2
|
+
def wpcli key
|
3
|
+
load_apps if @apps.nil?
|
4
|
+
@apps[key]
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def load_apps
|
10
|
+
file = File.read("#{Rails.root}/config/wpcli.yml")
|
11
|
+
config = YAML.load(file)
|
12
|
+
|
13
|
+
@apps = {}
|
14
|
+
config["apps"].each do |key, path|
|
15
|
+
@apps[key] = Client.new path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/wpcli.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require_relative "../lib/wpcli"
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wpcli::Client do
|
4
|
+
let(:wp_user_list) do <<EOF
|
5
|
+
+----+--------------------------+----------------+------------------------------+---------------------+------------------------------------+
|
6
|
+
| ID | user_login | display_name | user_email | user_registered | roles |
|
7
|
+
+----+--------------------------+----------------+------------------------------+---------------------+------------------------------------+
|
8
|
+
| 1 | test@domain.com | Test 1 | test@domain.com | 2013-11-24 19:26:45 | administrator |
|
9
|
+
| 2 | test@domain.net | Test 2 | test@domain.net | 2013-11-25 12:41:38 | author |
|
10
|
+
+----+--------------------------+----------------+------------------------------+---------------------+------------------------------------+
|
11
|
+
EOF
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:wp_role_list) do <<EOF
|
15
|
+
+------------------+------------------------------------+
|
16
|
+
| name | role |
|
17
|
+
+------------------+------------------------------------+
|
18
|
+
| Administrator | administrator |
|
19
|
+
| Editor | editor |
|
20
|
+
| Author | author |
|
21
|
+
| Contributor | contributor |
|
22
|
+
| Subscriber | subscriber |
|
23
|
+
+------------------+------------------------------------+
|
24
|
+
EOF
|
25
|
+
end
|
26
|
+
describe '.new' do
|
27
|
+
let(:path) { "path_to_wp" }
|
28
|
+
let(:command) { "user role" }
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
@wpcli = Wpcli::Client.new path
|
32
|
+
@wpcli.stub(:`).with("wp --path=#{path} #{command}").and_return(wp_role_list)
|
33
|
+
end
|
34
|
+
context 'with path' do
|
35
|
+
it 'uses --path parameter' do
|
36
|
+
@array = @wpcli.run command
|
37
|
+
@array.kind_of?(Array).should be(true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe 'run' do
|
42
|
+
before :each do
|
43
|
+
@wpcli = Wpcli::Client.new
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'role list' do
|
47
|
+
before :each do
|
48
|
+
@wpcli.stub(:`).with("wp role list").and_return(wp_role_list)
|
49
|
+
@array = @wpcli.run "role list"
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'returns array' do
|
53
|
+
it { @array.kind_of?(Array).should be(true)}
|
54
|
+
|
55
|
+
it 'which contains hashes' do
|
56
|
+
@array.first.kind_of?(Hash).should be(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'which has five hashes' do
|
60
|
+
@array.size.should eq(5)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'first hash has correct columns' do
|
64
|
+
@array.first.has_key?(:name).should be(true)
|
65
|
+
@array.first.has_key?(:role).should be(true)
|
66
|
+
@array.first.keys.size.should eq(2)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'user list' do
|
72
|
+
before :each do
|
73
|
+
@wpcli.stub(:`).with("wp user list").and_return(wp_user_list)
|
74
|
+
@array = @wpcli.run "user list"
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'returns array' do
|
78
|
+
it { @array.kind_of?(Array).should be(true) }
|
79
|
+
|
80
|
+
it 'which contains hashes' do
|
81
|
+
@array.first.kind_of?(Hash).should be(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'which has two hashes' do
|
85
|
+
@array.size.should eq(2)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'first hash has correct columns' do
|
89
|
+
@array.first.has_key?(:id).should be(true)
|
90
|
+
@array.first.has_key?(:display_name).should be(true)
|
91
|
+
@array.first.has_key?(:user_email).should be(true)
|
92
|
+
@array.first.has_key?(:user_registered).should be(true)
|
93
|
+
@array.first.has_key?(:user_login).should be(true)
|
94
|
+
@array.first.has_key?(:roles).should be(true)
|
95
|
+
@array.first.keys.size.should eq(6)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/wpcli.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wpcli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wpcli"
|
8
|
+
spec.version = Wpcli::VERSION
|
9
|
+
spec.authors = ["Joni Hasanen"]
|
10
|
+
spec.email = ["joni.hasanen@pieceofcode.net"]
|
11
|
+
spec.description = %q{Simple wrapper for wp-cli}
|
12
|
+
spec.summary = %q{Simple wrapper for wp-cli}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wpcli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joni Hasanen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Simple wrapper for wp-cli
|
56
|
+
email:
|
57
|
+
- joni.hasanen@pieceofcode.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/rails/generators/wpcli/config/config_generator.rb
|
69
|
+
- lib/rails/generators/wpcli/config/templates/config_example.yml
|
70
|
+
- lib/wpcli.rb
|
71
|
+
- lib/wpcli/client.rb
|
72
|
+
- lib/wpcli/rails.rb
|
73
|
+
- lib/wpcli/version.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/wpcli/client_spec.rb
|
76
|
+
- wpcli.gemspec
|
77
|
+
homepage: ''
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Simple wrapper for wp-cli
|
101
|
+
test_files:
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/wpcli/client_spec.rb
|