fiedl-log 0.1.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c4e782e673e205f0b33c45c64b4770f8f36c28ca
4
- data.tar.gz: fe5b2363a8969ae792ec64b76d00e8e96165dec6
2
+ SHA256:
3
+ metadata.gz: 50633d096202849e748b14cc35cf0badcf887040d719239480c5117dda15d454
4
+ data.tar.gz: 83cd6b2bc6aea3834a3ef40a52bd1c19a8f573da7027a64fb8c325aa8ec2e352
5
5
  SHA512:
6
- metadata.gz: f1f0777da381db3ad3620c3dab2c010a4e32642483cbd0d3262f7deacb5037bd4d0971fd437c99d8edaecb18674fbe46581991a0040b1aa8f6d516ab83c20840
7
- data.tar.gz: 650e7588e9dbe262dfee9b75518f5aa83920d3e329816448eee3832afc941aa6bf2d0e59e8fc87552560d7f376867217c4df59c3814a6a78f98a08b1e1664d89
6
+ metadata.gz: 298c22019b349406edb0569f75c416e1209c78cd7715fdb635e093d9de61f3e36b48db493ac55427a816150756c51cd7159ad4cf65f63aabd0567bc65556bd2a
7
+ data.tar.gz: e36ea52a0268251cebffc7c8b348941e37391f4a884755bb91716e18718ce9bfb0e7bd1d6a39da142e12f91c4463bfc9ecff658cf54edb9114aa4314008c10e6
data/README.md CHANGED
@@ -2,23 +2,6 @@
2
2
 
3
3
  Simple colored output helper for ruby scripts.
4
4
 
5
-
6
- ## Installation
7
-
8
- Add this line to your application's Gemfile:
9
-
10
- ```ruby
11
- gem 'fiedl-log'
12
- ```
13
-
14
- And then execute:
15
-
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
- $ gem install fiedl-log
21
-
22
5
  ## Usage
23
6
 
24
7
  ```ruby
@@ -38,6 +21,8 @@ log.error "This script does nothing, yet."
38
21
  raise "This script does nothing, yet, sorry!"
39
22
  ```
40
23
 
24
+ ![screenshot](https://github.com/fiedl/fiedl-log/raw/master/screenshots/Bildschirmfoto%202016-11-24%20um%2018.14.49.png)
25
+
41
26
  ### Manually defining a log instance
42
27
 
43
28
  This gem defines `log` unless `log` is already defined. But, of course, you may manually instantiate it:
@@ -60,6 +45,68 @@ log.filter_out("my_secret_password")
60
45
 
61
46
  This will filter out any occurance of "my_secret_password" and replace it by "[...]" in the output.
62
47
 
48
+ ### Shell commands
49
+
50
+ Print a shell command, execute it and display the result:
51
+
52
+ ```ruby
53
+ # ~/some_ruby_script.rb
54
+ require 'fiedl/log'
55
+
56
+ shell "whoami"
57
+ ```
58
+
59
+ ![screenshot](https://github.com/fiedl/fiedl-log/raw/master/screenshots/Bildschirmfoto%202016-11-24%20um%2018.15.47.png)
60
+
61
+ The `shell` command returns both the output of the stdin and the stderr.
62
+
63
+ To prevent the `shell` command from printing anything, use `verbose: false`:
64
+
65
+ ```ruby
66
+ user = shell "whoami", verbose: false
67
+ ```
68
+
69
+ ### Logging variables
70
+
71
+ ```ruby
72
+ # ~/some_ruby_script.rb
73
+ require 'fiedl/log'
74
+
75
+ foo = "bar"
76
+ log.variable foo, "foo"
77
+
78
+ options = {
79
+ foo: 'bar'
80
+ }
81
+ log.configuration options
82
+ ```
83
+
84
+ ### Other helpers
85
+
86
+ Ensure that a certain file is present before continuing: If the file is missing, the error is logged and the script is stopped.
87
+
88
+ ```ruby
89
+ # ~/some_ruby_script.rb
90
+ require 'fiedl/log'
91
+
92
+ log.ensure_file "$HOME/.zshrc"
93
+ ```
94
+
95
+ ## Installation
96
+
97
+ Add this line to your application's Gemfile:
98
+
99
+ ```ruby
100
+ gem 'fiedl-log'
101
+ ```
102
+
103
+ And then execute:
104
+
105
+ $ bundle
106
+
107
+ Or install it yourself as:
108
+
109
+ $ gem install fiedl-log
63
110
 
64
111
  ## Development
65
112
 
@@ -69,7 +116,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
69
116
 
70
117
  ## Contributing
71
118
 
72
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fiedl-log.
119
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fiedl/fiedl-log.
73
120
 
74
121
 
75
122
  ## License
data/fiedl-log.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "fiedl-log"
8
8
  spec.version = Fiedl::Log::VERSION
9
9
  spec.authors = ["Sebastian Fiedlschuster"]
10
- spec.email = ["sebastian@fiedlschuster.de"]
10
+ spec.email = ["rubygems@fiedlschuster.de"]
11
11
 
12
12
  spec.summary = %q{Simple colored output helper for ruby scripts.}
13
13
  spec.description = spec.summary
@@ -17,10 +17,10 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ["lib", "lib/fiedl/log"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "bundler", ">= 2.2.10"
23
+ spec.add_development_dependency "rake", ">= 12.3.3"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
25
 
26
26
  spec.add_dependency "colored"
data/lib/fiedl/log/log.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Fiedl::Log::Log
2
+
2
3
  def head(text)
3
4
  info ""
4
5
  info "==========================================================".blue
@@ -25,12 +26,21 @@ class Fiedl::Log::Log
25
26
  def prompt(text)
26
27
  self.write "$ " + text.bold
27
28
  end
29
+ def variable(variable, variable_name)
30
+ self.write "#{variable_name.to_s.blue} = #{variable}"
31
+ end
32
+ def configuration(hash)
33
+ pp hash
34
+ end
28
35
  def write(text)
36
+ self.p "#{text}\n"
37
+ end
38
+ def p(text)
29
39
  @filter_out ||= []
30
40
  @filter_out.each do |expression|
31
41
  text = text.gsub(expression, "[...]")
32
42
  end
33
- print text + "\n"
43
+ print text
34
44
  end
35
45
  def filter_out(expression)
36
46
  @filter_out ||= []
@@ -40,4 +50,42 @@ class Fiedl::Log::Log
40
50
  filter_out expression
41
51
  end
42
52
 
53
+ def raise(text)
54
+ self.error(text.bold)
55
+ super(text)
56
+ end
57
+
58
+ # Print commant, execute it and display result.
59
+ # See also: http://stackoverflow.com/a/10224650/2066546
60
+ #
61
+ def shell(command, verbose: true)
62
+ prompt command if verbose
63
+
64
+ output = ""
65
+ r, io = IO.pipe
66
+ pid = fork do
67
+ system(command, out: io, err: io)
68
+ end
69
+ io.close
70
+ r.each_char{|c| (print c if verbose); output += c}
71
+
72
+ Process.waitpid pid
73
+ return output.strip
74
+ end
75
+
76
+ # Ensure that a certain file is present.
77
+ #
78
+ def ensure_file(filename, options = {})
79
+ if File.exists?(filename)
80
+ log.success "File: #{filename}"
81
+ else
82
+ log.error "Something went wrong. File #{filename} is missing."
83
+ if options[:show_log]
84
+ log.section "Last log"
85
+ shell "tail -n 20 #{options[:show_log]}"
86
+ end
87
+ raise "File is missing."
88
+ end
89
+ end
90
+
43
91
  end
@@ -1,5 +1,5 @@
1
1
  module Fiedl
2
2
  module Log
3
- VERSION = "0.1.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/lib/fiedl/log.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "fiedl/log/version"
2
2
  require "fiedl/log/log"
3
3
  require "colored"
4
+ require "pp"
4
5
 
5
6
  STDOUT.sync = true
6
7
 
@@ -9,4 +10,14 @@ module Fiedl
9
10
  end
10
11
  end
11
12
 
12
- log = Fiedl::Log::Log.new unless defined? log
13
+ unless defined? log
14
+ def log
15
+ @log ||= Fiedl::Log::Log.new
16
+ end
17
+ end
18
+
19
+ unless defined? shell
20
+ def shell(command, verbose: true)
21
+ log.shell command, verbose: verbose
22
+ end
23
+ end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fiedl-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Fiedlschuster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
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: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  description: Simple colored output helper for ruby scripts.
70
70
  email:
71
- - sebastian@fiedlschuster.de
71
+ - rubygems@fiedlschuster.de
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -86,6 +86,8 @@ files:
86
86
  - lib/fiedl/log.rb
87
87
  - lib/fiedl/log/log.rb
88
88
  - lib/fiedl/log/version.rb
89
+ - screenshots/Bildschirmfoto 2016-11-24 um 18.14.49.png
90
+ - screenshots/Bildschirmfoto 2016-11-24 um 18.15.47.png
89
91
  homepage: https://github.com/fiedl/fiedl-log
90
92
  licenses:
91
93
  - MIT
@@ -94,6 +96,7 @@ post_install_message:
94
96
  rdoc_options: []
95
97
  require_paths:
96
98
  - lib
99
+ - lib/fiedl/log
97
100
  required_ruby_version: !ruby/object:Gem::Requirement
98
101
  requirements:
99
102
  - - ">="
@@ -105,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
108
  - !ruby/object:Gem::Version
106
109
  version: '0'
107
110
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.5.1
111
+ rubygems_version: 3.0.3.1
110
112
  signing_key:
111
113
  specification_version: 4
112
114
  summary: Simple colored output helper for ruby scripts.