cmds 0.2.6 → 0.2.7

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: ce280edce2a5280b59577c6ed628d1272fb56837
4
- data.tar.gz: 721ae47183a85e44ae7cdc2a15457fd5f1fbdf6c
3
+ metadata.gz: a0d4f58d017003bd4ff1f97a41a31a1e092281de
4
+ data.tar.gz: 94f1272024e6d65078d597bc7c306c9c554b5780
5
5
  SHA512:
6
- metadata.gz: 71ac3174bc664c621b5abc3bbf2489f0f4eff8aee8702f2513e7770bfbe9a1051eb24724be91d6130aaff1a32c34b97d5d88761617bedb3908994f9f06d00ecf
7
- data.tar.gz: f712b163665cd228bf8066fe44fb0cb73df538902b6e874ea05328762c44937e47a1d231da192798e6ce00e1e3a622ad84b097ca1f598968ddbb4995a692610a
6
+ metadata.gz: b07ecf238f17240dc52bacb958d1368cabaa5c577db49623a5b8a52544110a27661ee9b428d4438584d3cae65b9dbb989012c3c17de15d2b1df28fc53399930e
7
+ data.tar.gz: 973a978ed2fb08958413c1cb163ebf88be9975475bb55da5d8f2d96cdc3e42f1ea39820bed70de1eb3c1de0eac5448a6f3346ff488c65f10b699e20aba65b45d
data/README.md CHANGED
@@ -445,19 +445,23 @@ It's a clumsy hack from when I was first writing this library, and I've pretty m
445
445
 
446
446
  It pretty much just replaces some special patterns with their ERB-equivalent via the {Cmds.replace_shortcuts} method before moving on to ERB processing:
447
447
 
448
- 1. `%s` => `<%= arg %>`
449
- 2. `%{key}` => `<%= key %>`
450
- 3. `%{key?}` => `<%= key? %>`
451
- 4. `%<key>s` => `<%= key %>`
452
- 5. `%<key?>s` => `<%= key? %>`
448
+ | Format | ERB Replacement |
449
+ | ----------- | --------------- |
450
+ | `%s` | `<%= arg %>` |
451
+ | `%{key}` | `<%= key %>` |
452
+ | `%{key?}` | `<%= key? %>` |
453
+ | `%<key>s` | `<%= key %>` |
454
+ | `%<key?>s` | `<%= key? %>` |
453
455
 
454
456
  And the escaping versions, where you can put anothe `%` in front to get the literal intead of the subsitution:
455
457
 
456
- 1. `%%s` => `%s`
457
- 2. `%%{key}` => `%{key}`
458
- 3. `%%{key?}` => `%{key?}`
459
- 4. `%%<key>s` => `%<key>s`
460
- 5. `%%<key?>s` => `%<key?>s`
458
+ | Format | ERB Replacement |
459
+ | ----------- | --------------- |
460
+ | `%%s` | `%s` |
461
+ | `%%{key}` | `%{key}` |
462
+ | `%%{key?}` | `%{key?}` |
463
+ | `%%<key>s` | `%<key>s` |
464
+ | `%%<key?>s` | `%<key?>s` |
461
465
 
462
466
  That's it. No `printf` formatting beyond besides `s` (string).
463
467
 
data/lib/cmds.rb CHANGED
@@ -28,16 +28,6 @@ require 'cmds/capture'
28
28
 
29
29
  class Cmds
30
30
 
31
- # Constants
32
- # ============================================================================
33
-
34
- # Absolute, expanded path to the gem's root directory.
35
- #
36
- # @return [Pathname]
37
- #
38
- ROOT = ( Pathname.new(__FILE__).dirname / '..' ).expand_path
39
-
40
-
41
31
  # Attributes
42
32
  # ============================================================================
43
33
 
data/lib/cmds/result.rb CHANGED
@@ -1,28 +1,43 @@
1
1
  require 'nrser/refinements'
2
2
 
3
3
  class Cmds
4
- # a simple data structure returned from calling {Cmds#capture}
4
+ # A simple data structure returned from calling {Cmds#capture}
5
5
  # on a {Cmds} instance.
6
6
  #
7
- # it contains the exit status code, standard output and standard error,
7
+ # It contains the exit status code, standard output and standard error,
8
8
  # as well as the actual string command issued (after all substitutions).
9
9
  #
10
- # instances also have a few convenience methods.
11
- #
12
- # @!attribute [r] cmd
13
- # @return [String] the command string that was executed.
14
- #
15
- # @!attribute [r] status
16
- # @return [Fixnum] the command process' exit status code.
17
- #
18
- # @!attribute [r] out
19
- # @return [String] the command process' standard output.
20
- #
21
- # @!attribute [r] err
22
- # @return [String] the command process' standard error.
23
- #
10
+ # Instances also have a few convenience methods.
11
+ #
24
12
  class Result
25
- attr_reader :cmd, :status, :out, :err
13
+
14
+ # The command string that was executed.
15
+ #
16
+ # @return [String]
17
+ #
18
+ attr_reader :cmd
19
+
20
+
21
+ # The command process' exit status code.
22
+ #
23
+ # @return [Fixnum]
24
+ #
25
+ attr_reader :status
26
+
27
+
28
+ # The command process' standard output.
29
+ #
30
+ # @return [String]
31
+ #
32
+ attr_reader :out
33
+
34
+
35
+ # The command process' standard error.
36
+ #
37
+ # @return [String]
38
+ #
39
+ attr_reader :err
40
+
26
41
 
27
42
  # @param cmd [String] {#cmd} attribute.
28
43
  # @param status [Fixnum] {#status} attribute.
@@ -35,17 +50,22 @@ class Cmds
35
50
  @err = err
36
51
  end
37
52
 
38
- # @return [Boolean] true if {#status} is `0`.
53
+
54
+ # @return [Boolean]
55
+ # `true` if {#status} is `0`.
39
56
  def ok?
40
57
  @status == 0
41
58
  end
42
59
 
43
- # @return [Boolean] true if {#status} is not `0`.
60
+
61
+ # @return [Boolean]
62
+ # `true` if {#status} is not `0`.
44
63
  def error?
45
64
  ! ok?
46
65
  end
47
66
 
48
- # raises an error if the command failed (exited with a {#status} other
67
+
68
+ # Raises an error if the command failed (exited with a {#status} other
49
69
  # than `0`).
50
70
  #
51
71
  # @return [Result] it's self (so that it can be chained).
@@ -56,5 +76,22 @@ class Cmds
56
76
  Cmds.check_status @cmd, @status, @err
57
77
  self
58
78
  end # raise_error
79
+
80
+
81
+ # Get a {Hash} containing the instance variable values for easy logging,
82
+ # JSON dumping, etc.
83
+ #
84
+ # @example
85
+ # Cmds( "echo %s", "hey" ).to_h
86
+ # # => {:cmd=>"echo hey", :status=>0, :out=>"hey\n", :err=>""}
87
+ #
88
+ # @return [Hash<Symbol, V>]
89
+ #
90
+ def to_h
91
+ instance_variables.map { |name|
92
+ [name.to_s.sub('@', '').to_sym, instance_variable_get( name )]
93
+ }.to_h
94
+ end
95
+
59
96
  end # Result
60
97
  end # Cmds
data/lib/cmds/util.rb CHANGED
@@ -135,6 +135,9 @@ class Cmds
135
135
  msg += " and stderr:\n\n" + err
136
136
  end
137
137
 
138
+ # Remove NULL bytes (not sure how they get in there...)
139
+ msg = msg.delete("\000")
140
+
138
141
  raise SystemCallError.new msg, status
139
142
  end
140
143
  end # .assert
data/lib/cmds/version.rb CHANGED
@@ -1,3 +1,21 @@
1
+ require 'pathname'
2
+
1
3
  class Cmds
2
- VERSION = "0.2.6"
4
+
5
+ # Constants
6
+ # ============================================================================
7
+
8
+ # Absolute, expanded path to the gem's root directory.
9
+ #
10
+ # @return [Pathname]
11
+ #
12
+ ROOT = (Pathname.new( __FILE__ ).dirname / '..' / '..').expand_path
13
+
14
+
15
+ # Library version string.
16
+ #
17
+ # @return [String]
18
+ #
19
+ VERSION = "0.2.7"
20
+
3
21
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,17 @@ require 'cmds'
7
7
 
8
8
  require 'nrser/rspex'
9
9
 
10
+
11
+ # RSpec Configuration
12
+ # ============================================================================
13
+
14
+ RSpec.configure do |config|
15
+ # Enable flags like --only-failures and --next-failure
16
+ config.example_status_persistence_file_path = \
17
+ Cmds::ROOT / 'tmp' / ".rspec_status"
18
+ end
19
+
20
+
10
21
  ECHO_CMD = "./test/echo_cmd.rb"
11
22
 
12
23
  def echo_cmd_data result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nrser
@@ -222,6 +222,7 @@ files:
222
222
  - test/lines.txt
223
223
  - test/questions.rb
224
224
  - test/tick.rb
225
+ - tmp/.gitkeep
225
226
  homepage: https://github.com/nrser/cmds
226
227
  licenses:
227
228
  - MIT