scriptster 0.2.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +30 -17
- data/examples/rainbow.rb +83 -0
- data/examples/template.rb +45 -0
- data/examples/test.rb +22 -0
- data/lib/scriptster.rb +2 -2
- data/lib/scriptster/configuration.rb +1 -2
- data/lib/scriptster/shellcmd.rb +5 -2
- data/lib/scriptster/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ab01abdd932c4089a19e464727861c4397c886d
|
4
|
+
data.tar.gz: 771d12e4026b18fc257387c5a4f59ad71debe8ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35ff0d7d04e9187d2703636d1cb82e0a4c3879a60d0f64b0d0fff411b3ece52b061a78d4ddd075de2308a5c417df275a530a2040c78041d97606dea5f1ea7d05
|
7
|
+
data.tar.gz: a930061dd62ee56bba2566f41dd186fafc6ae4d31224f34e8858561b65d391ca34374797f63c4eb544ba1d7e2430959cfb05b77ad9fa3a645bd48313cf3ee4dc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,13 +4,17 @@
|
|
4
4
|
[](http://inch-ci.org/github/pazdera/scriptster)
|
5
5
|
[](https://travis-ci.org/pazdera/scriptster)
|
6
6
|
|
7
|
-
Scriptster is a small
|
8
|
-
|
9
|
-
|
7
|
+
Scriptster is a small Ruby gem that will help you write scripts in Ruby. It
|
8
|
+
only consists of two functions and it's especially useful for apps
|
9
|
+
which depend on many external tools.
|
10
10
|
|
11
|
-
|
11
|
+
<img alt="Example output"
|
12
|
+
src="http://broken.build/assets/images/posts/scriptster-example.png"
|
13
|
+
style="width:400px;">
|
14
|
+
|
15
|
+
This library focuses on these two basic things:
|
12
16
|
* Running shell commands
|
13
|
-
* Providing nice logs
|
17
|
+
* Providing nice logs and status messages about what happened
|
14
18
|
|
15
19
|
See the examples bellow.
|
16
20
|
|
@@ -20,32 +24,41 @@ See the examples bellow.
|
|
20
24
|
require 'scriptster'
|
21
25
|
```
|
22
26
|
|
23
|
-
It
|
24
|
-
|
25
|
-
|
26
|
-
the
|
27
|
+
It's not necessary to configure scriptster before using it, if you're happy
|
28
|
+
with the default settings. But chances are you won't be, in which case the
|
29
|
+
`configure` method is exactly what you're after. Bellow is a quick example
|
30
|
+
(for the full list of options, please refer to the
|
31
|
+
[docs](http://www.rubydoc.info/github/pazdera/scriptster/master/frames)):
|
27
32
|
|
28
33
|
```ruby
|
29
34
|
Scriptster::configure do |conf|
|
30
35
|
conf.name = "my-script"
|
31
|
-
conf.
|
36
|
+
conf.verbosity = :verbose
|
37
|
+
conf.file = nil
|
38
|
+
conf.colours = :dark
|
39
|
+
conf.log_format = "%{timestamp} %{name} %{type} %{message}"
|
32
40
|
end
|
33
41
|
```
|
34
42
|
|
35
|
-
The following snippet demonstrates
|
43
|
+
The following snippet demonstrates how can you use **scriptster**
|
36
44
|
in practice:
|
37
45
|
|
38
46
|
```ruby
|
39
|
-
Scriptster::log :info, "
|
47
|
+
Scriptster::log :info, "Checking branches"
|
40
48
|
|
41
|
-
Scriptster::cmd
|
49
|
+
git_cmd = Scriptster::cmd "git branch",
|
42
50
|
:show_out = true,
|
43
|
-
:show_err = true
|
51
|
+
:show_err = true
|
52
|
+
|
53
|
+
branch_exists = git_cmd.out.split("\n").grep(/#{branch}/).length > 0
|
54
|
+
Scriptster::log(:warn, "Branch '#{branch}' not found") unless branch_exists
|
44
55
|
```
|
45
56
|
|
46
|
-
The `log` method
|
47
|
-
|
48
|
-
|
57
|
+
The first `log` method will format and print a status message to stdout.
|
58
|
+
The latter `cmd` method executes the given `git` command, prints it's
|
59
|
+
output, but it also keeps it for processing. You will find more about
|
60
|
+
the options and parameters of these functions in the
|
61
|
+
[documentation](http://www.rubydoc.info/github/pazdera/scriptster/master/frames).
|
49
62
|
|
50
63
|
## Installation
|
51
64
|
|
data/examples/rainbow.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scriptster'
|
4
|
+
|
5
|
+
Scriptster::configure do |conf|
|
6
|
+
conf.verbosity = :verbose
|
7
|
+
conf.log_format = "%{name} %{type} %{message}"
|
8
|
+
conf.colours = Proc.new do
|
9
|
+
Tco::configure do |conf|
|
10
|
+
conf.names["red"] = "#BF0C43" #"DF151A"
|
11
|
+
conf.names["orange"] = "#F9BA15" #"FD8603"
|
12
|
+
conf.names["yellow"] = "#8EAC00" #"F4F328"
|
13
|
+
conf.names["green"] = "#127A97" #"00DA3C"
|
14
|
+
conf.names["blue"] = "#452B72" #"00CBE7"
|
15
|
+
|
16
|
+
conf.names["light-grey"] = "#ababab"
|
17
|
+
conf.names["medium-grey"] = "#444444"
|
18
|
+
conf.names["dark-grey"] = "#2b2b2b"
|
19
|
+
|
20
|
+
conf.styles["info"] = {
|
21
|
+
:fg => "dark-grey", :bg => "green",
|
22
|
+
:bright => false, :underline => false
|
23
|
+
}
|
24
|
+
conf.styles["info-message"] = {
|
25
|
+
:fg => "default", :bg => "default",
|
26
|
+
:bright => false, :underline => false
|
27
|
+
}
|
28
|
+
|
29
|
+
conf.styles["warn"] = {
|
30
|
+
:fg => "dark-grey", :bg => "orange",
|
31
|
+
:bright => false, :underline => false
|
32
|
+
}
|
33
|
+
conf.styles["warn-message"] = {
|
34
|
+
:fg => "default", :bg => "default",
|
35
|
+
:bright => false, :underline => false
|
36
|
+
}
|
37
|
+
|
38
|
+
conf.styles["err"] = {
|
39
|
+
:fg => "dark-grey", :bg => "red",
|
40
|
+
:bright => false, :underline => false
|
41
|
+
}
|
42
|
+
conf.styles["err-message"] = {
|
43
|
+
:fg => "default", :bg => "default",
|
44
|
+
:bright => false, :underline => false
|
45
|
+
}
|
46
|
+
|
47
|
+
conf.styles["debug"] = {
|
48
|
+
:fg => "#000", :bg => "blue",
|
49
|
+
:bright => false, :underline => false
|
50
|
+
}
|
51
|
+
conf.styles["debug-message"] = {
|
52
|
+
:fg => "default", :bg => "default",
|
53
|
+
:bright => false, :underline => false
|
54
|
+
}
|
55
|
+
|
56
|
+
conf.styles["name"] = {
|
57
|
+
:fg => "medium-grey", :bg => "default",
|
58
|
+
:bright => false, :underline => false
|
59
|
+
}
|
60
|
+
conf.styles["highlight"] = {
|
61
|
+
:fg => "orange", :bg => "default",
|
62
|
+
:bright => false, :underline => false
|
63
|
+
}
|
64
|
+
conf.styles["cmd"] = {
|
65
|
+
:fg => "blue", :bg => "light-grey",
|
66
|
+
:bright => false, :underline => false
|
67
|
+
}
|
68
|
+
conf.styles["timestamp"] = {
|
69
|
+
:fg => "medium-grey", :bg => "default",
|
70
|
+
:bright => false, :underline => false
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Scriptster::log :err, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
77
|
+
Scriptster::log :err, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
78
|
+
Scriptster::log :warn, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
79
|
+
Scriptster::log :warn, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
80
|
+
Scriptster::log :info, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
81
|
+
Scriptster::log :info, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
82
|
+
Scriptster::log :debug, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
83
|
+
Scriptster::log :debug, "{{red:: These}} {{orange:: logs}} {{yellow:: are}} {{green:: pretty}} {{blue:: funky.}}"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Docopt docs: http://bit.ly/1LT7Rch
|
4
|
+
# Scriptster::configure docs: http://bit.ly/1H4X3kR
|
5
|
+
# Scriptster::cmd docs: http://bit.ly/1LOuVrB
|
6
|
+
|
7
|
+
require 'docopt'
|
8
|
+
require 'scriptster'
|
9
|
+
|
10
|
+
include Scriptster
|
11
|
+
|
12
|
+
doc = <<DOCOPT
|
13
|
+
Usage:
|
14
|
+
#{File.basename __FILE__} [-h]
|
15
|
+
|
16
|
+
Options:
|
17
|
+
-h, --help Show this message.
|
18
|
+
DOCOPT
|
19
|
+
|
20
|
+
Scriptster::configure do |conf|
|
21
|
+
conf.verbosity = :verbose
|
22
|
+
conf.log_format = '%{timestamp} [%{name}] %{type} %{message}'
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
args = Docopt::docopt doc
|
27
|
+
rescue Docopt::Exit => e
|
28
|
+
log :err, e.message
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
### >>> Example
|
33
|
+
log :info, "Listing files:"
|
34
|
+
ls = cmd 'ls -l | grep -v "^total"',
|
35
|
+
show_out: true,
|
36
|
+
out_level: :debug,
|
37
|
+
tag: 'ls -l'
|
38
|
+
|
39
|
+
files = []
|
40
|
+
ls.out.lines.each do |line|
|
41
|
+
files.push line.split[-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
log :info, files.join(', ')
|
45
|
+
# <<<
|
data/examples/test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scriptster'
|
4
|
+
|
5
|
+
include Scriptster
|
6
|
+
|
7
|
+
Scriptster::configure do |conf|
|
8
|
+
conf.file = "log.txt"
|
9
|
+
conf.verbosity = :verbose
|
10
|
+
conf.colours = :dark
|
11
|
+
conf.log_format = "%{timestamp} [%{name}] %{type} %{message}"
|
12
|
+
end
|
13
|
+
|
14
|
+
log :info, "Row, row, row your punt", :verbose
|
15
|
+
log :warn, "Gently down the {{highlight stream}}", :verbose
|
16
|
+
log :err, "Belts off, trousers down", :verbose
|
17
|
+
log :debug, "Isn't life a {{highlight scream}}, whoa!", :verbose
|
18
|
+
|
19
|
+
cmd "uname -mnrs",
|
20
|
+
:show_out => true,
|
21
|
+
:show_err => true,
|
22
|
+
:expect => 0
|
data/lib/scriptster.rb
CHANGED
@@ -40,7 +40,7 @@ module Scriptster
|
|
40
40
|
#
|
41
41
|
# @see .log
|
42
42
|
def log(*args)
|
43
|
-
|
43
|
+
Logger::log *args
|
44
44
|
end
|
45
45
|
|
46
46
|
# Execute a shell command
|
@@ -54,7 +54,7 @@ module Scriptster
|
|
54
54
|
#
|
55
55
|
# @see .cmd
|
56
56
|
def cmd(*args)
|
57
|
-
|
57
|
+
ShellCmd.new *args
|
58
58
|
end
|
59
59
|
|
60
60
|
# Use this method to reconfigure the library.
|
@@ -35,13 +35,12 @@ module Scriptster
|
|
35
35
|
# @see ColourThemes
|
36
36
|
# @attr [String] log_format Template for each line in the logs
|
37
37
|
class Configuration
|
38
|
-
|
38
|
+
attr_accessor :name, :verbosity, :file, :colours, :log_format
|
39
39
|
|
40
40
|
def initialize
|
41
41
|
@name = File.basename($0)
|
42
42
|
@verbosity = :verbose
|
43
43
|
@file = nil
|
44
|
-
@timestamps = true
|
45
44
|
@colours = :dark
|
46
45
|
@log_format = "%{timestamp} %{name} %{type} %{message}"
|
47
46
|
end
|
data/lib/scriptster/shellcmd.rb
CHANGED
@@ -46,6 +46,8 @@ module Scriptster
|
|
46
46
|
# @param [String] cmd The command line to be run.
|
47
47
|
# @param [Hash] opts Various options of the command.
|
48
48
|
# @option opts [Boolean] :show_out Care about STDOUT flag.
|
49
|
+
# @option opts [Boolean] :out_level To which log level to print the output
|
50
|
+
# [default: :info].
|
49
51
|
# @option opts [Boolean] :show_err Care about STDERR flag.
|
50
52
|
# @option opts [Boolean] :raise Raise on error flag.
|
51
53
|
# @option opts [String] :tag Logger tag (defaults to the first
|
@@ -56,6 +58,7 @@ module Scriptster
|
|
56
58
|
@err = ""
|
57
59
|
|
58
60
|
@show_out = false
|
61
|
+
@out_level = :info
|
59
62
|
@show_err = true
|
60
63
|
@raise = true
|
61
64
|
@tag = cmd.split[0]
|
@@ -74,7 +77,7 @@ module Scriptster
|
|
74
77
|
private
|
75
78
|
# Execute the command and collect all the data from it.
|
76
79
|
#
|
77
|
-
# The function will
|
80
|
+
# The function will block until the command has finished.
|
78
81
|
def run
|
79
82
|
Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
|
80
83
|
stdout_buffer=""
|
@@ -98,7 +101,7 @@ module Scriptster
|
|
98
101
|
if @show_out
|
99
102
|
$&.strip.split("\n").each do |line|
|
100
103
|
line = @tag.style("cmd") + " " + line if @tag
|
101
|
-
log(
|
104
|
+
log(@out_level, line)
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
data/lib/scriptster/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scriptster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radek Pazdera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tco
|
@@ -80,6 +80,9 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
+
- examples/rainbow.rb
|
84
|
+
- examples/template.rb
|
85
|
+
- examples/test.rb
|
83
86
|
- gemrc
|
84
87
|
- lib/scriptster.rb
|
85
88
|
- lib/scriptster/configuration.rb
|