sh_vars 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +21 -0
- data/README.md +18 -0
- data/lib/sh_vars/string.rb +164 -0
- data/lib/sh_vars/version.rb +3 -0
- data/lib/sh_vars.rb +12 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 57f7bfacb048c3592ab7325dcaf8fc99466f072eeb2c146db9218e910348f8dd
|
4
|
+
data.tar.gz: 90146d1a36f79e9d585d8517153f62bfecf7e71bf340f0079aa23681bba09f44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64a7ee0d58b729dbf2ac572dca32d7964f057e4fcdbfa419c47630aceb5ac36a6853646e5f1360ff138372cfbe57d4365d30d0322825de4ed2c0de1e0f688380
|
7
|
+
data.tar.gz: 3f33a69120bb971345165030b2eb3206281bc4ece6e5b48d739d7c840ca5e7133b096b253b51b17eae10b29f7065f8690f89865f80404b2e7f33c10db9aab33b
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at support@travis-ci.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sh_vars (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rspec (3.8.0)
|
11
|
+
rspec-core (~> 3.8.0)
|
12
|
+
rspec-expectations (~> 3.8.0)
|
13
|
+
rspec-mocks (~> 3.8.0)
|
14
|
+
rspec-core (3.8.0)
|
15
|
+
rspec-support (~> 3.8.0)
|
16
|
+
rspec-expectations (3.8.3)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-mocks (3.8.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-support (3.8.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
rspec
|
29
|
+
sh_vars!
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
2.0.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2018 Joe Corcoran <joe@corcoran.online>, Sven Fuchs <me@svenfuchs.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# ShVars [![Build Status](https://travis-ci.org/svenfuchs/cl.svg?branch=master)](https://travis-ci.org/svenfuchs/cl)
|
2
|
+
|
3
|
+
A library for parsing shell environment variables.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install sh_vars
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
require 'sh_vars'
|
15
|
+
|
16
|
+
ShVars.parse('FOO=foo BAR="bar"')
|
17
|
+
# => [['FOO', foo], ['BAR', '"bar"']]
|
18
|
+
```
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module ShVars
|
5
|
+
class String
|
6
|
+
class << self
|
7
|
+
def unquote_pair(str)
|
8
|
+
str = new(str).unquote
|
9
|
+
new(str).pair
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
KEY = %r([^\s=]+)
|
14
|
+
WORD = %r((\\.|(?!\s|"|'|`|\${|\$\(|\)).)+)
|
15
|
+
SPACE = %r(\s+)
|
16
|
+
EQUAL = %r(=)
|
17
|
+
OPEN = %r(\$\(|\$\{)
|
18
|
+
CLOSE = { '$(' => %r(\)), '${' => %r(\}) }
|
19
|
+
|
20
|
+
extend Forwardable
|
21
|
+
|
22
|
+
def_delegators :str, :check, :eos?, :peek, :pos, :scan, :skip, :string
|
23
|
+
attr_reader :str
|
24
|
+
|
25
|
+
def initialize(str)
|
26
|
+
@str = StringScanner.new(str.to_s.strip)
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse
|
30
|
+
pairs = [pair]
|
31
|
+
pairs << pair while space
|
32
|
+
pairs.tap { err('end of string') unless eos? }
|
33
|
+
end
|
34
|
+
|
35
|
+
def pair
|
36
|
+
double_quoted_pair || unquoted_pair
|
37
|
+
end
|
38
|
+
|
39
|
+
def double_quoted_pair
|
40
|
+
return unless var = double_quoted
|
41
|
+
self.class.unquote_pair(var)
|
42
|
+
end
|
43
|
+
|
44
|
+
def unquoted_pair
|
45
|
+
return unless key = scan(KEY)
|
46
|
+
return [key, ''] unless scan(EQUAL)
|
47
|
+
parts, part = [], nil
|
48
|
+
parts << part while part = value
|
49
|
+
[key, parts.join]
|
50
|
+
end
|
51
|
+
|
52
|
+
def values
|
53
|
+
parts, part = [], nil
|
54
|
+
parts << part while part = value || space
|
55
|
+
parts.join if parts.any?
|
56
|
+
end
|
57
|
+
|
58
|
+
def value
|
59
|
+
parens { values } || quoted || word
|
60
|
+
end
|
61
|
+
|
62
|
+
def open
|
63
|
+
@open ||= []
|
64
|
+
end
|
65
|
+
|
66
|
+
def parens
|
67
|
+
return unless paren = scan(OPEN)
|
68
|
+
|
69
|
+
open << paren
|
70
|
+
str = yield
|
71
|
+
open.pop
|
72
|
+
|
73
|
+
close = CLOSE[paren] if paren
|
74
|
+
close = scan(close) if close
|
75
|
+
[paren, str, close].join
|
76
|
+
end
|
77
|
+
|
78
|
+
def quoted
|
79
|
+
double_quoted || single_quoted("'") || single_quoted("`")
|
80
|
+
end
|
81
|
+
|
82
|
+
def word
|
83
|
+
scan(WORD) unless quote? || paren?
|
84
|
+
end
|
85
|
+
|
86
|
+
def space
|
87
|
+
scan(SPACE)
|
88
|
+
end
|
89
|
+
|
90
|
+
def single_quoted(char)
|
91
|
+
pattern = /#{char}/
|
92
|
+
return unless quote = scan(pattern)
|
93
|
+
quotes << quote
|
94
|
+
str = scan(/[^#{char}]*/) # how about nested double quoted strs in here
|
95
|
+
quote = quotes.pop
|
96
|
+
err(quote) unless scan(pattern) == quote
|
97
|
+
[quote, str, quote].join
|
98
|
+
end
|
99
|
+
|
100
|
+
def double_quoted
|
101
|
+
pattern = /^#{'\\' * level * 4}"/
|
102
|
+
return unless quote = scan(pattern)
|
103
|
+
quotes << quote
|
104
|
+
|
105
|
+
parts, part = [], nil
|
106
|
+
parts << part while part = scan_quote(quote)
|
107
|
+
parts << value
|
108
|
+
parts << part while part = scan_quote(quote)
|
109
|
+
|
110
|
+
quotes.pop
|
111
|
+
err(quote) unless scan(pattern) == quote
|
112
|
+
[quote, *parts, quote].join
|
113
|
+
end
|
114
|
+
|
115
|
+
def scan_quote(quote)
|
116
|
+
str = scan(/[^#{quote}\\]+/)
|
117
|
+
str ||= scan(/#{'\\' * level * 2}#{quote}/)
|
118
|
+
str
|
119
|
+
end
|
120
|
+
|
121
|
+
def unquote
|
122
|
+
pattern = /^#{'\\' * level * 4}"/
|
123
|
+
return unless quote = scan(pattern)
|
124
|
+
quotes << quote
|
125
|
+
|
126
|
+
parts, part = [], nil
|
127
|
+
parts << part while part = scan_unquote(quote)
|
128
|
+
parts << unquote
|
129
|
+
parts << part while part = scan_unquote(quote)
|
130
|
+
|
131
|
+
quote = quotes.pop
|
132
|
+
err(quote) unless scan(pattern) == quote
|
133
|
+
unquote = level == 0 ? '' : %(#{'\\' * (level)}")
|
134
|
+
[unquote, *parts, unquote].join
|
135
|
+
end
|
136
|
+
|
137
|
+
def scan_unquote(quote)
|
138
|
+
str = scan(/[^#{quote}\\]+/)
|
139
|
+
return str if str
|
140
|
+
str = scan(/#{'\\' * level * 2}#{quote}/)
|
141
|
+
['\\' * (level - 1), quote].join if str
|
142
|
+
end
|
143
|
+
|
144
|
+
def paren?
|
145
|
+
open.any? && peek(open.last.size) == open.last
|
146
|
+
end
|
147
|
+
|
148
|
+
def quote?
|
149
|
+
quotes.any? && peek(quotes.last.size) == quotes.last
|
150
|
+
end
|
151
|
+
|
152
|
+
def level
|
153
|
+
quotes.size
|
154
|
+
end
|
155
|
+
|
156
|
+
def quotes
|
157
|
+
@quotes ||= []
|
158
|
+
end
|
159
|
+
|
160
|
+
def err(char)
|
161
|
+
raise ParseError, "expected #{char} at position #{pos} in: #{string.inspect}"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/lib/sh_vars.rb
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sh_vars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sven Fuchs
|
8
|
+
- Joe Corcoran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Shell var parser.
|
15
|
+
email:
|
16
|
+
- me@svenfuchs.com
|
17
|
+
- joe@corcoran.online
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- lib/sh_vars.rb
|
28
|
+
- lib/sh_vars/string.rb
|
29
|
+
- lib/sh_vars/version.rb
|
30
|
+
homepage: https://github.com/svenfuchs/sh_vars
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.7.6
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Shell var parser
|
54
|
+
test_files: []
|