cmds 0.2.6 → 0.2.7
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/README.md +14 -10
- data/lib/cmds.rb +0 -10
- data/lib/cmds/result.rb +57 -20
- data/lib/cmds/util.rb +3 -0
- data/lib/cmds/version.rb +19 -1
- data/spec/spec_helper.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0d4f58d017003bd4ff1f97a41a31a1e092281de
|
4
|
+
data.tar.gz: 94f1272024e6d65078d597bc7c306c9c554b5780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
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
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
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
|
-
#
|
4
|
+
# A simple data structure returned from calling {Cmds#capture}
|
5
5
|
# on a {Cmds} instance.
|
6
6
|
#
|
7
|
-
#
|
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
|
-
#
|
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
|
-
|
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
|
-
|
53
|
+
|
54
|
+
# @return [Boolean]
|
55
|
+
# `true` if {#status} is `0`.
|
39
56
|
def ok?
|
40
57
|
@status == 0
|
41
58
|
end
|
42
59
|
|
43
|
-
|
60
|
+
|
61
|
+
# @return [Boolean]
|
62
|
+
# `true` if {#status} is not `0`.
|
44
63
|
def error?
|
45
64
|
! ok?
|
46
65
|
end
|
47
66
|
|
48
|
-
|
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
data/lib/cmds/version.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
class Cmds
|
2
|
-
|
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.
|
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-
|
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
|