script 0.0.4 → 1.0.0

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: 5b3eebc0b8ffe63d808137cc772a49faa8dc9eac
4
- data.tar.gz: f46549975e784a273bf327e195ea576fddd643af
3
+ metadata.gz: f1399ac78e96bea7357b6e68477cf6ec9c379966
4
+ data.tar.gz: b6458f57445515f08e39e4bec1ed9a6ca41bcf51
5
5
  SHA512:
6
- metadata.gz: ee9167d56e4af31bcb123bb8456262511d67d2d303f462bfc661bd54eddd444749e1976fa4c5eed88b9aab7af5d41b909b1bfd918dfd152df258b416115c336b
7
- data.tar.gz: 1fbce152e3984cc426f3cb6f3f890888b0a3542aa7e88a33367a4d13648fd69584a2cf767a9e74f0b4e9624aba5cffdbc3293e346e68674a963d00e1d87b76fe
6
+ metadata.gz: ea4674a144d25c850401e77a3db238d0ac028f1f9f591f20e4626e54a164e8fc1b584f71b9ab84bf2a800405beb6daae3b7e41c8c601bc57dd0d1825c856246a
7
+ data.tar.gz: bafbaf00ab2d203846f5b2c064341b6443b9adebe444b712bf95c6306678a09a101457afe86b1c5a4e534cad4b0f321d274787f1449a95a6e0eceec27a78fdf7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- script (0.0.4)
4
+ script (1.0.0)
5
5
  colorize
6
6
 
7
7
  GEM
@@ -15,6 +15,8 @@ GEM
15
15
  rspec-core (~> 3.7.0)
16
16
  rspec-expectations (~> 3.7.0)
17
17
  rspec-mocks (~> 3.7.0)
18
+ rspec-autotest (1.0.0)
19
+ rspec-core (>= 2.99.0.beta1, < 4.0.0)
18
20
  rspec-core (3.7.0)
19
21
  rspec-support (~> 3.7.0)
20
22
  rspec-expectations (3.7.0)
@@ -29,10 +31,11 @@ PLATFORMS
29
31
  ruby
30
32
 
31
33
  DEPENDENCIES
32
- bundler (~> 1.16)
34
+ bundler
33
35
  byebug
34
36
  rake (~> 10.0)
35
37
  rspec (~> 3.0)
38
+ rspec-autotest
36
39
  script!
37
40
 
38
41
  BUNDLED WITH
data/README.md CHANGED
@@ -8,6 +8,7 @@ The Script is everything you need to make the most of Ruby - a fabulous scriptin
8
8
  - [Setup](#setup)
9
9
  - [Usage](#usage)
10
10
  - [Steps](#steps)
11
+ - [Output](#output)
11
12
  - [Shareables](#shareables)
12
13
  - [Contributing](#contributing)
13
14
  - [License](#license)
@@ -21,53 +22,75 @@ Install gem:
21
22
  gem install script
22
23
  ```
23
24
 
24
- And require it in your script file:
25
+ Or add it as dependency to your Gemfile:
26
+
27
+ ```ruby
28
+ gem 'script'
29
+ ```
30
+
31
+ Then simply require it in your script file:
25
32
 
26
33
  ```
27
34
  require 'script'
28
35
  ```
29
36
 
37
+ And you're good to go.
38
+
30
39
  ## Usage
31
40
 
32
41
  ### Steps
33
42
 
34
- Reason about the step as a logical group of commands. Lets take for instance, the deploy script which builds a docker image, pushes it to Dockerhub and eventually creates the deployment on Kubernetes.
43
+ Steps encourages you to split commands into higher level constructs which are essential for more complex scripts.
44
+
45
+ Use Script to define the steps:
35
46
 
36
47
  ```ruby
37
- #!/usr/local/bin/ruby
48
+ #!/usr/bin/env ruby
38
49
 
39
50
  require "script"
40
51
 
41
- deploy = Script.new
52
+ Script.define do |s|
53
+ s.step("step 1") do
54
+ # Commands
55
+ end
42
56
 
43
- deploy.step("Setup tools") do
44
- `sudo apt-get install -y google-cloud-sdk kubectl`
45
- `gcloud auth activate-service-account $GCLOUD_SERVICE_ACCOUNT_NAME`
46
- `gcloud config set project dummy-project`
47
- `gcloud container clusters get-credentials default --zone us-east`
57
+ s.step("step 2") do
58
+ # Commands
59
+ end
48
60
  end
61
+ ```
49
62
 
50
- deploy.step("Deploy docker image") do
51
- `docker pull dummy`
52
- `docker build --cache-from dummy -t dummy`
53
- `docker build -t scripter/script .`
54
- `docker push dummy`
55
- end
63
+ Once you've run the ruby script, it will execute each of the steps in the order they were defined.
56
64
 
57
- deploy.step("Deploy to Kubernetes cluster") do
58
- `kubectl apply -f k8s.yml --record`
59
- end
65
+ ### Error handling
60
66
 
61
- # Finally, run the script
67
+ In case of an error in one of the steps, the script is stopped right away without executing further steps.
62
68
 
63
- deploy.run
64
- ```
69
+ ### Output
70
+
71
+ Nicely formatted output is the primary motivation behind the Script. Most of the time you want to separate your commands output , in order to help investigation or debugging later.
65
72
 
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:
73
+ Let's take for an example the following script:
67
74
 
68
- ![output](https://i.imgur.com/a6F2iAh.png)
75
+ ```ruby
76
+ #!/usr/bin/env ruby
77
+
78
+ require "script"
69
79
 
70
- In case of an exception in one of the steps, the execution of the script is aborted instantly.
80
+ Script.define do |s|
81
+ s.step("setup") do
82
+ system("bundle install")
83
+ end
84
+
85
+ s.step("build") do
86
+ system("bundle exec rake spec")
87
+ end
88
+
89
+ s.step("deploy") do
90
+ system("gem push script-*")
91
+ end
92
+ end
93
+ ```
71
94
 
72
95
  ### Shareables
73
96
 
@@ -75,12 +98,12 @@ In case you need to share data between steps, you can pass hash of shareables to
75
98
 
76
99
  ```ruby
77
100
  script.step("Step 1") do |shareables|
78
- shareables["environment"] = "production"
101
+ shareables["environment"] = "production"
79
102
  end
80
103
 
81
104
  script.step("Step 2") do |shareables|
82
- environment = shareables["environment"]
83
- puts "Deploying on #{environment} environment"
105
+ environment = shareables["environment"]
106
+ puts "Deploying on #{environment} environment"
84
107
  end
85
108
  ```
86
109
 
@@ -1,3 +1,3 @@
1
1
  class Script
2
- VERSION = "0.0.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -23,8 +23,9 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "colorize"
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "byebug"
30
+ spec.add_development_dependency "rspec-autotest"
30
31
  end
@@ -3,14 +3,16 @@
3
3
  require "script"
4
4
 
5
5
  Script.define do |s|
6
- s.step("step 1") do
7
- puts "Step 1"
8
- puts "Completed"
9
- raise
10
- end
6
+ s.step("setup") do
7
+ system("bundle install")
8
+ end
11
9
 
12
- s.step("step 2") do
13
- puts "Step 2"
14
- puts "Completed"
15
- end
10
+ s.step("build") do
11
+ system("bundle exec rake spec")
12
+ end
13
+
14
+ s.step("deploy") do
15
+ system("gem push script-*")
16
+ end
16
17
  end
18
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bmarkons
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-autotest
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'
83
97
  description: Gives you a hand with composing neat Ruby scripts.
84
98
  email:
85
99
  - mamaveb@gmail.com