rbish 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f68bf5527673e629613a4343f6b728b64582c2f
4
+ data.tar.gz: cca5a28a4d846e1d988a851e62cb14234e1b407a
5
+ SHA512:
6
+ metadata.gz: f76d7c2b763af6680d085301344f463dda5b9ba164f2c3226847298ca089ab9399c11355c9bf0390e44f424ce389aa051ce0f20f8a75bf996328ad03a1876428
7
+ data.tar.gz: 4a2d56029918d9a1e83af752c1acd0e0e7c299797ec9215a53770755c4cdaa1ac2a85bf1628956a13dd1a26c77dc04375da60d830b42577855abbc23a873cacf
@@ -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
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First version to be published to rubygems.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rbish.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 suu-g
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.
@@ -0,0 +1,35 @@
1
+ # Rbish
2
+
3
+ An erb-shellscript executor
4
+
5
+ ## Installation
6
+
7
+ Install it yourself as:
8
+
9
+ $ gem install rbish
10
+
11
+ ## Usage
12
+
13
+ Just give the filename of your shellscript to rbish.
14
+
15
+ $ rbish myscript.sh
16
+
17
+ rbish can take strings from STDIN as well.
18
+
19
+ $ rbish < myscript.sh
20
+
21
+ You can use ERB in your shellscript whereever you like.
22
+
23
+ $ cat myscript.sh
24
+ #!/bin/sh
25
+ <% (1..10).each do |i| %>
26
+ sudo arping -c 1 <%= "192.168.10.2%02d" % i %>
27
+ <% end %>
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( http://github.com/suu-g/rbish/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
+ require "rbish"
5
+
6
+ cmd = Rbish::CLI.new
7
+ cmd.run
@@ -0,0 +1,26 @@
1
+ require "mixlib/log"
2
+
3
+ require "rbish/version"
4
+ require "rbish/cli"
5
+ require "rbish/command"
6
+ require "rbish/config"
7
+ require "rbish/shell"
8
+
9
+ module Rbish
10
+ class OptionError < StandardError; end
11
+
12
+ class Log
13
+ extend Mixlib::Log
14
+ end
15
+
16
+ # not capable in ruby 1.8
17
+ [:debug, :info, :warn, :error, :fatal].each do |meth|
18
+ define_singleton_method(meth){|msg| Log.send(meth, msg) }
19
+ end
20
+
21
+ def self.init
22
+ Log.init($stderr)
23
+ end
24
+ end
25
+
26
+ Rbish.init
@@ -0,0 +1,74 @@
1
+ require "mixlib/cli"
2
+
3
+ module Rbish
4
+ class CLI
5
+
6
+ include Mixlib::CLI
7
+
8
+ option :version,
9
+ :short => "-v",
10
+ :long => "--version",
11
+ :description => "Show version",
12
+ :boolean => true,
13
+ :default => nil
14
+
15
+ option :help,
16
+ :short => "-h",
17
+ :long => "--help",
18
+ :description => "Show this message",
19
+ :on => :tail,
20
+ :boolean => true,
21
+ :show_options => true,
22
+ :exit => 0
23
+
24
+ option :log_level,
25
+ :short => "-l LEVEL",
26
+ :long => "--loglevel LEVEL",
27
+ :description => "Set the log level (debug, info, warn, error, fatal)"
28
+
29
+ def version_check
30
+ if config[:version]
31
+ puts "rbish #{Rbish::VERSION}"
32
+ exit 0
33
+ end
34
+ end
35
+
36
+ def run(argv=ARGV)
37
+ parse_options(argv)
38
+ version_check
39
+ parse_cli_arguments
40
+ Config.merge!(config)
41
+
42
+ cmd = Command.new(@target, Config)
43
+ cmd.run
44
+ rescue OptionError => e
45
+ Rbish.error("#{e.class}: #{e.message}")
46
+ exit 1
47
+ rescue => e
48
+ Rbish.error("#{e.class}: #{e.message}")
49
+ exit 3
50
+ end
51
+
52
+ private
53
+
54
+ def parse_cli_arguments
55
+ if target.nil?
56
+ # requires filename when you don't have anything from $stdin
57
+ raise OptionError, "Please specify file name." if $stdin.isatty
58
+ @target = $stdin
59
+ else
60
+ begin
61
+ @target = File.open(target, "r")
62
+ rescue SystemCallError => e
63
+ raise OptionError, "Couldn't open file #{target}." if $stdin.isatty
64
+ end
65
+ end
66
+ end
67
+
68
+ # Returns target File object.
69
+ def target
70
+ return cli_arguments.first
71
+ end
72
+ end
73
+ end
74
+
@@ -0,0 +1,16 @@
1
+ require "erb"
2
+ require "tilt"
3
+
4
+ module Rbish
5
+ class Command
6
+ def initialize(fd, config)
7
+ @fd = fd
8
+ @config = config
9
+ end
10
+
11
+ def run
12
+ template = Tilt::ERBTemplate.new { @fd.read }
13
+ ::Rbish::Shell.run(template.render)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require "mixlib/config"
2
+
3
+ module Rbish
4
+ class Config
5
+ extend Mixlib::Config
6
+
7
+ config_strict_mode true
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Rbish
2
+ class Shell
3
+ def self.run(command)
4
+ # TODO: make it better, by using one of the libraries below:
5
+ # - open3
6
+ # - systemu
7
+ # - mixlib-shellout
8
+ puts `#{command}`
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Rbish
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rbish/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rbish"
8
+ spec.version = Rbish::VERSION
9
+ spec.authors = ["suu-g"]
10
+ spec.email = ["suu-g@kata.me"]
11
+ spec.summary = %q{An erb-shellscript executor}
12
+ spec.description = spec.summary
13
+ spec.homepage = "http://github.com/suu-g/rbish"
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_dependency "tilt"
22
+ spec.add_dependency "mixlib-cli"
23
+ spec.add_dependency "mixlib-config"
24
+ spec.add_dependency "mixlib-log"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rbish do
4
+ before do
5
+ end
6
+
7
+ describe "#initialize" do
8
+ before do
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rbish do
4
+ before do
5
+ end
6
+
7
+ describe "#initialize" do
8
+ before do
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rbish do
4
+ before do
5
+ end
6
+
7
+ describe "#initialize" do
8
+ before do
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rbish do
4
+ before do
5
+ end
6
+
7
+ describe "#initialize" do
8
+ before do
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rbish do
4
+ before do
5
+ end
6
+
7
+ describe "#initialize" do
8
+ before do
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,3 @@
1
+ $:.unshift File.expand_path '..', __FILE__
2
+ $:.unshift File.expand_path '../../lib', __FILE__
3
+ require 'rbish'
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - suu-g
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: mixlib-config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: mixlib-log
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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: rspec
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
+ description: An erb-shellscript executor
112
+ email:
113
+ - suu-g@kata.me
114
+ executables:
115
+ - rbish
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - CHANGELOG.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/rbish
126
+ - lib/rbish.rb
127
+ - lib/rbish/cli.rb
128
+ - lib/rbish/command.rb
129
+ - lib/rbish/config.rb
130
+ - lib/rbish/shell.rb
131
+ - lib/rbish/version.rb
132
+ - rbish.gemspec
133
+ - spec/cli_spec.rb
134
+ - spec/command_spec.rb
135
+ - spec/config_spec.rb
136
+ - spec/rbish_spec.rb
137
+ - spec/shell_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: http://github.com/suu-g/rbish
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: An erb-shellscript executor
163
+ test_files:
164
+ - spec/cli_spec.rb
165
+ - spec/command_spec.rb
166
+ - spec/config_spec.rb
167
+ - spec/rbish_spec.rb
168
+ - spec/shell_spec.rb
169
+ - spec/spec_helper.rb