yacli 0.1.8

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDI1MTYxMTU4ZTVhOTU4MzE4MGY4ZGJhYjI2OGVmNWNlNmNhMGZmZQ==
5
+ data.tar.gz: !binary |-
6
+ MzQwZDllOTljMDVhZmE3ZGEzZjk5MzIwZTIwYzA5YmQ3MjRmZDc4YQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDc4ODNmNjQ4NTlhZjk1NjQyMjU1Mjg1ZGFhZDJmMjhjODA4MzMxNDZmZjU5
10
+ YTQ3YzE2YTczNDczNjljOTJiYTU1MjIwOGQ5N2RlMDVlZTY4MjQwNTM3YTNj
11
+ MWQwYTExNGFkMTk3NTIwMTRlM2VhNGIxMTFkOTUwMDAxZWQ2OGE=
12
+ data.tar.gz: !binary |-
13
+ YmZlZjVjMTBmOGE5ZGNkMjQ3MjA4OWJlY2NlMDNlNDI5ZDg2YThmZmQ1ODgz
14
+ MjRiMDMwMGU1YWMyNTllMzQyMDllYWI1MjAwYjZmN2VkODhkZGI0MzhhNzFm
15
+ NjRhMTYxZTg5ZTYwNjFiMDA1YzM3ZjFmMWQ1YjNmZDRlM2M0OTg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.5
5
+ deploy:
6
+ provider: rubygems
7
+ api_key:
8
+ secure: FWnp95y7k+XMsgwPfNaB4eDQtGnX0aIPzuCWAGIgNqec8mK9d/139wSGuvKX8hFqb/Wq9IwLobRYrFV5ReQvhbXW59YMWPaM1NEZdFNdED5jVozdgHK6//O13CI37rFYF2kBwR9yuwstwOJAVWlluPZn2dQzp8d/B6lnlgrxSnOO3o90zwlWARnKXY91XvPlVu0ertoFTa3m6nFGMW6revseW7oh7WaUph6o5S8nsZ9LzhCMfAElOwYoERkt1KhlZ/p93RCgReyj4stDEhhem38Vm5PejGpnlgOkHvSXmXT2EfM/Z6FtWvFwpRGn8XwDIrwt2A05taGbkB80jTxnuRCRhDUuBxBVg3ZfWqblcqMco//gGxDm4ZxwtF/iP3MwAsEnvDO2MVOnlXdeRTWW2HwgVvW7hUeEQDX1yPBXJ9jRbGWw31zg8D75KeO5iWrabfM938kjK41mmSkWWVHTtYI82TjkeGoWoFQJzR8ETS4i/zP9ezZVI+F7nmwNbViilntUJPAaGEjaXgPXLUjCHAuRacleHUm7BC+PFVWnCm+V8iRIpmv3U+fwDzEKKj1TTKZb662d9PIaqP6jliuXYPqgSv1KCbT5uz5k6T9kgUu+wlbphsYC0tiilT9r4NgewpHQT4Q6FlReQj9r+0XQgXaPQr+hHIP9N10dx5n/POc=
9
+ gem: yacli
10
+ on:
11
+ all_branches: true
12
+ tags: true
13
+ repo: rombob/yacli
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yacli.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ #notification :gntp
2
+ notification :growl
3
+
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/yacli/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('lib/yacli.rb') { "spec" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 rombob@gmail.com
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,43 @@
1
+ yacli
2
+ ============================================
3
+ [![Gem Version](http://img.shields.io/gem/v/yacli.svg)][gem]
4
+ [![Build Status](http://img.shields.io/travis/rombob/yacli.svg)][travis]
5
+ [![Coverage Status](https://img.shields.io/coveralls/rombob/yacli.svg)][coveralls]
6
+
7
+ [gem]: https://rubygems.org/gems/yacli
8
+ [travis]: http://travis-ci.org/rombob/yacli
9
+ [coveralls]: https://coveralls.io/r/rombob/yacli
10
+
11
+
12
+ Prerequisites
13
+ -------------
14
+ You will need the following:
15
+
16
+ - Ruby 1.9+
17
+ - Bundler
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'yacli'
24
+
25
+ And then execute:
26
+
27
+ $ bundle install
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install yacli
32
+
33
+ ## Usage
34
+
35
+ $ yacli help [COMMAND] # Describe expanded available commands or one specific command
36
+
37
+ ## Contributing
38
+
39
+ 1. [Fork it]( https://github.com/rombob/yacli/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:spec]
4
+ desc 'run Rspec specs'
5
+ task :spec do
6
+ sh 'rspec spec'
7
+ end
8
+
data/bin/yacli ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yacli/cli'
4
+ Yacli::Run.go
data/lib/yacli/base.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'logger'
2
+ require 'socket'
3
+
4
+ module Yacli
5
+ class Base
6
+ def init_logger(log_path = nil)
7
+ output_file = log_path.nil? ? STDOUT : log_path
8
+ logger = Logger.new(output_file)
9
+ logger.level = (!ENV['DEBUG'].nil?) ? Logger::DEBUG : Logger::INFO
10
+ logger.debug "logger.level: #{logger.level}"
11
+ logger
12
+ end
13
+
14
+ def error_exit(msg, exit_code = 1)
15
+ @log.error msg
16
+ raise ExecutionError
17
+ end
18
+
19
+ def pass_cli(cmd, valid_out_pattern = nil)
20
+ cmd += ' 2>&1'
21
+ @log.debug "running cmd: #{cmd}"
22
+ cmd_out = `#{cmd}`
23
+ success_exec = $?.success?
24
+ @log.info "cmd_out: #{cmd_out}"
25
+ @log.debug "success_exec: #{success_exec}"
26
+
27
+ valid_content = valid_out_pattern.nil? ? true : !cmd_out.match(/#{valid_out_pattern}/).nil?
28
+ @log.debug "valid_content: #{valid_content}"
29
+
30
+ raise InvalidExitCodeError.new(cmd_out) if !success_exec
31
+ raise InvalidContentError.new(cmd_out) if !valid_content
32
+ { :success => success_exec, :output => cmd_out }
33
+ end
34
+ end
35
+ end
data/lib/yacli/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'thor'
2
+
3
+ module Yacli
4
+ class Run < Thor
5
+
6
+ def self.common_opts
7
+ method_option :cmd, :aliases => "-r", :required => true
8
+ method_option :'config-path', :aliases => "-c", :required => false
9
+ method_option :'log-path', :aliases => "-l", :required => false
10
+ method_option :'dry-run', :aliases => "-d", :type => :boolean, :default => false
11
+ end
12
+
13
+ desc "upload", "sync from local to s3"
14
+ common_opts
15
+ def upload
16
+ require 's3rsync/sync'
17
+ sync = Sync.new(options)
18
+ exit sync.run(:upload)
19
+ end
20
+
21
+ desc "download", "sync from s3 to local"
22
+ common_opts
23
+ def download
24
+ require 's3rsync/sync'
25
+ sync = Sync.new(options)
26
+ exit sync.run(:download)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,35 @@
1
+ module Yacli
2
+ class YacliError < StandardError
3
+ class << self
4
+ # @param [Integer] code
5
+ def status_code(code)
6
+ define_method(:status_code) { code }
7
+ define_singleton_method(:status_code) { code }
8
+ end
9
+ end
10
+
11
+ alias_method :message, :to_s
12
+ end
13
+
14
+ class ExecutionError < YacliError; status_code(2); end
15
+ class InvalidExitCodeError < YacliError
16
+ status_code(3)
17
+ def initialize(cmd_return)
18
+ @cmd_return = cmd_return.inspect
19
+ end
20
+
21
+ def to_s
22
+ "Command output #{@cmd_return}"
23
+ end
24
+ end
25
+ class InvalidContentError < YacliError
26
+ status_code(4)
27
+ def initialize(cmd_return)
28
+ @cmd_return = cmd_return.inspect
29
+ end
30
+
31
+ def to_s
32
+ "Command output #{@cmd_return}"
33
+ end
34
+ end
35
+ end
data/lib/yacli/run.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "yacli"
2
+ require "json"
3
+ require "erb"
4
+
5
+ module Yacli
6
+ class Run < Base
7
+
8
+ def initialize(opt = {})
9
+ log_path = !opt['log-path'].nil? ? opt['log-path'] : nil
10
+ @log = init_logger(log_path)
11
+ @log.debug "opt: #{opt.inspect}"
12
+ end
13
+
14
+ def go(cmd = 'uname -a')
15
+ @log.debug "cmd: #{cmd}"
16
+ output = pass_cli cmd
17
+ @log.info "output: #{output}"
18
+ output
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Yacli
2
+ VERSION = "0.1.8"
3
+ end
data/lib/yacli.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "yacli/version"
2
+ require "yacli/base"
3
+ require "yacli/run"
4
+ require "yacli/errors"
5
+
6
+ module Yacli
7
+
8
+ end
data/spec/run_spec.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'yacli/run'
3
+
4
+ include Helpers
5
+
6
+ describe Yacli::Run do
7
+ context 'run is successfull' do
8
+ let(:opt) {
9
+ {
10
+ 'cmd' => 'date',
11
+ 'dry-run' => false,
12
+ }
13
+ }
14
+ let(:output) { 'Success' }
15
+
16
+ before do
17
+ allow_any_instance_of(Yacli::Run).to receive(:pass_cli).and_return(nil)
18
+ end
19
+
20
+ after do
21
+ #
22
+ end
23
+
24
+ before(:each) do
25
+ #Helpers::pre_run_helper
26
+ end
27
+
28
+ after(:each) do
29
+ # Nothing
30
+ end
31
+
32
+ it "print date" do
33
+ cmd = "date"
34
+ allow_any_instance_of(Yacli::Run).to receive(:pass_cli).with(cmd).and_return(output)
35
+ run = Yacli::Run.new(opt)
36
+ expect(run.go(cmd)).to eq output
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ require "yacli"
4
+ require "yacli/base"
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ add_filter '/bin/'
14
+ end
15
+
16
+ module Helpers
17
+
18
+ end
data/yacli.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yacli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yacli"
8
+ spec.version = Yacli::VERSION
9
+ spec.authors = ["rombob"]
10
+ spec.email = ["rombob@gmail.com"]
11
+ spec.summary = "CLI wrapper library tool"
12
+ spec.description = "Provide minimal tools for shell commands wrapper scripts"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency "thor", "0.19.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "bump"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "growl"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "coveralls"
32
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yacli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - rombob
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: bump
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Provide minimal tools for shell commands wrapper scripts
154
+ email:
155
+ - rombob@gmail.com
156
+ executables:
157
+ - yacli
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - .gitignore
162
+ - .ruby-version
163
+ - .travis.yml
164
+ - Gemfile
165
+ - Guardfile
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - bin/yacli
170
+ - lib/yacli.rb
171
+ - lib/yacli/base.rb
172
+ - lib/yacli/cli.rb
173
+ - lib/yacli/errors.rb
174
+ - lib/yacli/run.rb
175
+ - lib/yacli/version.rb
176
+ - spec/run_spec.rb
177
+ - spec/spec_helper.rb
178
+ - yacli.gemspec
179
+ homepage: ''
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.4.5
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: CLI wrapper library tool
203
+ test_files:
204
+ - spec/run_spec.rb
205
+ - spec/spec_helper.rb