tumugi-plugin-command 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9b4591bbbf87266be270751214404f6a471c08a
4
+ data.tar.gz: f699a5e914c3b1d54afc23b28da9114960dfb239
5
+ SHA512:
6
+ metadata.gz: a2bd5c5872f9815d00504c269dd7fc362f92e5b5169dfd32afa8eccf769c90606fe0d34386fbaeb8455f33b346a12340c4a64f69f6ac0cce97f67ea6435860f7
7
+ data.tar.gz: f02742e92853b41027b5974c0086d9a324f7a77051a6af1de6b5210d934e1c82fc8722a49cc77c5e031c58eef1ceeb80ef1adf23da0fbe0338b5bcca9731003a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test/tmp/
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
7
+ - ruby-head
8
+ - jruby-9.0.5.0
9
+ before_install:
10
+ - gem install bundler
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tumugi-plugin-shell.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ [![Build Status](https://travis-ci.org/tumugi/tumugi-plugin-command.svg?branch=master)](https://travis-ci.org/tumugi/tumugi-plugin-command) [![Code Climate](https://codeclimate.com/github/tumugi/tumugi-plugin-command/badges/gpa.svg)](https://codeclimate.com/github/tumugi/tumugi-plugin-command) [![Coverage Status](https://coveralls.io/repos/github/tumugi/tumugi-plugin-command/badge.svg?branch=master)](https://coveralls.io/github/tumugi/tumugi-plugin-command) [![Gem Version](https://badge.fury.io/rb/tumugi-plugin-command.svg)](https://badge.fury.io/rb/tumugi-plugin-command)
2
+
3
+ # tumugi-plugin-command
4
+
5
+ tumugi-plugin-command is a plugin to execute a command.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tumugi-plugin-command'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```sh
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```sh
24
+ $ gem install tumugi-plugin-command
25
+ ```
26
+
27
+ ## Task
28
+
29
+ ### Tumugi::Plugin::CommandTask
30
+
31
+ `Tumugi::Plugin::BigqueryShellTask` is task to execute a specified command.
32
+
33
+ #### Usage
34
+
35
+ - Run command
36
+
37
+ ```rb
38
+ task :task1, type: :command do
39
+ param_set :command, "ls -la"
40
+ end
41
+ ```
42
+
43
+ - Run command and save STDOUT into file
44
+
45
+ ```rb
46
+ task :task1, type: :command do
47
+ param_set :command, "echo 'success'"
48
+ param_set :output_file, "result.txt"
49
+ end
50
+ ```
51
+
52
+ - Run external shell script
53
+
54
+ ```sh:external_script.sh
55
+ #!/bin/sh
56
+ echo 'success' > tmp/external_script_result.txt
57
+ ```
58
+
59
+ ```rb
60
+ task :task1, type: :command do
61
+ requires :task2
62
+ param_set :command, -> { "cat #{input.path}" }
63
+ end
64
+
65
+ task :task2, type: :command do
66
+ param_set :command, "./examples/external_script.sh"
67
+ output target(:local_file, "tmp/external_script_result.txt")
68
+ end
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tumugi/tumugi-plugin-command.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [Apache License
82
+ Version 2.0](http://www.apache.org/licenses/).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tumugi/plugin/shell"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ echo 'success' > tmp/external_script_result.txt
@@ -0,0 +1,3 @@
1
+ task :task1, type: :command do
2
+ param_set :command, "echo 'test test'"
3
+ end
@@ -0,0 +1,9 @@
1
+ task :task1, type: :command do
2
+ requires :task2
3
+ param_set :command, -> { "cat #{input.path}" }
4
+ end
5
+
6
+ task :task2, type: :command do
7
+ param_set :command, "./examples/external_script.sh"
8
+ output target(:local_file, "tmp/external_script_result.txt")
9
+ end
@@ -0,0 +1,4 @@
1
+ task :task1, type: :command do
2
+ param_set :command, "echo 'success'"
3
+ param_set :output_file, "tmp/result.txt"
4
+ end
@@ -0,0 +1,7 @@
1
+ module Tumugi
2
+ module Plugin
3
+ module Command
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'open3'
2
+ require 'shellwords'
3
+
4
+ require 'tumugi/plugin'
5
+ require 'tumugi/plugin/target/local_file.rb'
6
+ require 'tumugi/task'
7
+
8
+ module Tumugi
9
+ module Plugin
10
+ class CommandTask < Tumugi::Task
11
+ Tumugi::Plugin.register_task('command', self)
12
+
13
+ param :command, type: :string, required: true
14
+ param :output_file, type: :string
15
+
16
+ def output
17
+ unless output_file.nil?
18
+ Tumugi::Plugin::LocalFileTarget.new(output_file)
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def run
25
+ log "Execute command: #{command}"
26
+ begin
27
+ out, err, status = Open3.capture3(*Shellwords.split(command))
28
+ rescue => e
29
+ raise Tumugi::TumugiError, e.message
30
+ end
31
+
32
+ logger.info out unless out.empty?
33
+ logger.error err unless err.empty?
34
+
35
+ if status.exitstatus == 0
36
+ if output_file && _output
37
+ log "Save STDOUT into #{_output.path}"
38
+ _output.open('w') do |f|
39
+ f.print(out)
40
+ end
41
+ end
42
+ else
43
+ raise Tumugi::TumugiError, "Command failed: exit status is #{status.exitstatus}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tumugi/plugin/command/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tumugi-plugin-command"
8
+ spec.version = Tumugi::Plugin::Command::VERSION
9
+ spec.authors = ["Kazuyuki Honda"]
10
+ spec.email = ["hakobera@gmail.com"]
11
+
12
+ spec.summary = "Tumugi plugin to execute a command"
13
+ spec.homepage = "https://github.com/tumugi/tumugi-plugin-command"
14
+ spec.license = "Apache License Version 2.0"
15
+
16
+ spec.required_ruby_version = ">= 2.1"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "tumugi", "~> 0.4.5"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "test-unit", "~> 3.1"
28
+ spec.add_development_dependency "test-unit-rr"
29
+ spec.add_development_dependency 'coveralls'
30
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tumugi-plugin-command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazuyuki Honda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tumugi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.5
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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit-rr
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: coveralls
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
+ description:
98
+ email:
99
+ - hakobera@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - examples/external_script.sh
112
+ - examples/run_command.rb
113
+ - examples/run_external_script.rb
114
+ - examples/save_result_to_file.rb
115
+ - lib/tumugi/plugin/command/version.rb
116
+ - lib/tumugi/plugin/task/command.rb
117
+ - tumugi-plugin-command.gemspec
118
+ homepage: https://github.com/tumugi/tumugi-plugin-command
119
+ licenses:
120
+ - Apache License Version 2.0
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '2.1'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Tumugi plugin to execute a command
142
+ test_files: []