script 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 872a8cf06708366e28dddb15b4ce5329d886c179
4
- data.tar.gz: 6d4f26cb5d7dd669933a9bd168d3060ae22488aa
3
+ metadata.gz: 5b3eebc0b8ffe63d808137cc772a49faa8dc9eac
4
+ data.tar.gz: f46549975e784a273bf327e195ea576fddd643af
5
5
  SHA512:
6
- metadata.gz: 445cb6296d580a65ea6bc3e931c20fae66e134eeb5f2af47eadabf853ff9b94baed6df6d060f0b78c1d38412c797653548387b2f7b4f4d9ca02e3ed1a69333d8
7
- data.tar.gz: a20c4b72f3598aa6825f888802d63fd042953ceb466710d0631aed951e47354b2f5a81c2511325898b3eee55e8186eff576e31a44ad9cef14d084191b9eb6fd9
6
+ metadata.gz: ee9167d56e4af31bcb123bb8456262511d67d2d303f462bfc661bd54eddd444749e1976fa4c5eed88b9aab7af5d41b909b1bfd918dfd152df258b416115c336b
7
+ data.tar.gz: 1fbce152e3984cc426f3cb6f3f890888b0a3542aa7e88a33367a4d13648fd69584a2cf767a9e74f0b4e9624aba5cffdbc3293e346e68674a963d00e1d87b76fe
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- script (0.0.2)
4
+ script (0.0.4)
5
5
  colorize
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,11 +1,14 @@
1
- # Script<img width="40" align="left" src="https://cdn.codementor.io/assets/topic/category_header/ruby-on-rails-bc9ab2af8d92eb4e7eb3211d548a09ad.png">
1
+ # Script[<img width="40" align="left" src="misc/ruby.png">](https://github.com/bmarkons/script#script)
2
+ [![Build Status](https://semaphoreci.com/api/v1/bmarkons/script/branches/master/badge.svg)](https://semaphoreci.com/bmarkons/script)
3
+ [![Gem Version](https://badge.fury.io/rb/script.svg)](https://badge.fury.io/rb/script)
2
4
 
3
- The Script is everything you need to make the most of Ruby, as fabulous scripting language.
5
+ The Script is everything you need to make the most of Ruby - a fabulous scripting language. The one started with idea of having nicely formatted output, but ended up in much more...
4
6
 
5
7
  ###### Table of contents
6
8
  - [Setup](#setup)
7
9
  - [Usage](#usage)
8
10
  - [Steps](#steps)
11
+ - [Shareables](#shareables)
9
12
  - [Contributing](#contributing)
10
13
  - [License](#license)
11
14
  - [Code of Conduct](#code-of-conduct)
@@ -38,27 +41,21 @@ require "script"
38
41
  deploy = Script.new
39
42
 
40
43
  deploy.step("Setup tools") do
41
-
42
44
  `sudo apt-get install -y google-cloud-sdk kubectl`
43
45
  `gcloud auth activate-service-account $GCLOUD_SERVICE_ACCOUNT_NAME`
44
46
  `gcloud config set project dummy-project`
45
47
  `gcloud container clusters get-credentials default --zone us-east`
46
-
47
48
  end
48
49
 
49
50
  deploy.step("Deploy docker image") do
50
-
51
51
  `docker pull dummy`
52
52
  `docker build --cache-from dummy -t dummy`
53
53
  `docker build -t scripter/script .`
54
54
  `docker push dummy`
55
-
56
55
  end
57
56
 
58
57
  deploy.step("Deploy to Kubernetes cluster") do
59
-
60
58
  `kubectl apply -f k8s.yml --record`
61
-
62
59
  end
63
60
 
64
61
  # Finally, run the script
@@ -66,7 +63,26 @@ end
66
63
  deploy.run
67
64
  ```
68
65
 
69
- The steps are run in order in which they are registered.
66
+ The steps are run in order in which they are registered. The output from the script commands is nicely formatted and divided per steps:
67
+
68
+ ![output](https://i.imgur.com/a6F2iAh.png)
69
+
70
+ In case of an exception in one of the steps, the execution of the script is aborted instantly.
71
+
72
+ ### Shareables
73
+
74
+ In case you need to share data between steps, you can pass hash of shareables to the step block:
75
+
76
+ ```ruby
77
+ script.step("Step 1") do |shareables|
78
+ shareables["environment"] = "production"
79
+ end
80
+
81
+ script.step("Step 2") do |shareables|
82
+ environment = shareables["environment"]
83
+ puts "Deploying on #{environment} environment"
84
+ end
85
+ ```
70
86
 
71
87
  ## Contributing
72
88
 
@@ -6,6 +6,12 @@ require "script/output"
6
6
  require "colorize"
7
7
 
8
8
  class Script
9
+ def self.define
10
+ script = new
11
+ yield(script)
12
+ script.run
13
+ end
14
+
9
15
  def initialize
10
16
  @engine = Script::Engine.new
11
17
  end
@@ -1,6 +1,7 @@
1
1
  class Script::Engine
2
2
  def initialize
3
3
  @steps = []
4
+ @shareables = {}
4
5
  end
5
6
 
6
7
  def steps
@@ -14,7 +15,7 @@ class Script::Engine
14
15
  def run
15
16
  @steps.each do |step|
16
17
  puts Script::Output.started(step)
17
- step.run
18
+ step.run(@shareables)
18
19
  puts Script::Output.result(step)
19
20
 
20
21
  abort_run if step.result == :failed
@@ -4,8 +4,8 @@ class Script::Step
4
4
  @block = block
5
5
  end
6
6
 
7
- def run
8
- @block.call
7
+ def run(shareables)
8
+ @block.call(shareables)
9
9
  @result = :succeded
10
10
  rescue
11
11
  @result = :failed
@@ -1,3 +1,3 @@
1
1
  class Script
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
@@ -2,17 +2,15 @@
2
2
 
3
3
  require "script"
4
4
 
5
- script = Script.new
5
+ Script.define do |s|
6
+ s.step("step 1") do
7
+ puts "Step 1"
8
+ puts "Completed"
9
+ raise
10
+ end
6
11
 
7
- script.step("step 1") do
8
- puts "Step 1"
9
- puts "Completed"
10
- raise
12
+ s.step("step 2") do
13
+ puts "Step 2"
14
+ puts "Completed"
15
+ end
11
16
  end
12
-
13
- script.step("step 2") do
14
- puts "Step 2"
15
- puts "Completed"
16
- end
17
-
18
- script.run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - bmarkons
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2018-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -103,6 +103,7 @@ files:
103
103
  - lib/script/output.rb
104
104
  - lib/script/step.rb
105
105
  - lib/script/version.rb
106
+ - misc/ruby.png
106
107
  - script.gemspec
107
108
  - scripts/gh-md-toc
108
109
  - scripts/script.rb
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.5.1
130
+ rubygems_version: 2.5.2.1
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: Ruby scripting