runcom 3.1.0 → 4.0.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +130 -80
- data/lib/runcom/cache.rb +22 -0
- data/lib/runcom/{configuration.rb → config.rb} +9 -9
- data/lib/runcom/data.rb +26 -0
- data/lib/runcom/identity.rb +1 -1
- data/lib/runcom/pair.rb +10 -0
- data/lib/runcom/paths/combined.rb +31 -0
- data/lib/runcom/paths/directory.rb +31 -0
- data/lib/runcom/paths/friendly.rb +28 -0
- data/lib/runcom/paths/standard.rb +39 -0
- data/lib/runcom/xdg/cache.rb +25 -0
- data/lib/runcom/xdg/config.rb +26 -0
- data/lib/runcom/xdg/data.rb +26 -0
- data/lib/runcom/xdg/environment.rb +38 -0
- data/lib/runcom.rb +12 -2
- data.tar.gz.sig +0 -0
- metadata +45 -50
- metadata.gz.sig +0 -0
- data/lib/runcom/xdg/configuration.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0cccf991ffd5ecf95af5725c8c0b223f098ca93bdae3d49135cd0a29ba19eb9
|
4
|
+
data.tar.gz: d34cb932f9bd927eb2da2aff0e94180f0d2c5dca1fd15a7409d4529726b4158c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b489c2cca56abd562427d4d6263f1563a104b3709336c66d3499554aff3e24b8d1a2ebbf76fe31db080dc9888287ae2339a802ab5127862a71f32f15b1cffb
|
7
|
+
data.tar.gz: 19af5524f8622d785a633d005e2b0d696cd762be47678b67b05da54002002327c6c3699ac67fdaa07fe58375241792803dd3a9733d1ac2ae14f38490562a5589
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
Runcom (a.k.a. [Run Command](https://en.wikipedia.org/wiki/Run_commands)) provides common
|
9
9
|
functionality for Command Line Interfaces (CLIs) in which to manage global, local, or multiple
|
10
|
-
configurations in general. It does this by leveraging the
|
11
|
-
|
12
|
-
|
10
|
+
caches, configurations, or data in general. It does this by leveraging the [XDG Base Directory
|
11
|
+
Specification](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). Read on for
|
12
|
+
further details.
|
13
13
|
|
14
14
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
15
15
|
|
@@ -19,11 +19,16 @@ Read on for further details.
|
|
19
19
|
- [Requirements](#requirements)
|
20
20
|
- [Setup](#setup)
|
21
21
|
- [Usage](#usage)
|
22
|
-
- [`Runcom::Configuration`](#runcomconfiguration)
|
23
22
|
- [XDG](#xdg)
|
24
|
-
- [
|
25
|
-
- [
|
23
|
+
- [Overview](#overview)
|
24
|
+
- [Variable Behavior](#variable-behavior)
|
25
|
+
- [`$XDG_*_DIRS`](#xdg__dirs)
|
26
|
+
- [`$XDG_*_HOME`](#xdg__home)
|
26
27
|
- [Variable Priority](#variable-priority)
|
28
|
+
- [Runcom](#runcom)
|
29
|
+
- [Overview](#overview-1)
|
30
|
+
- [Variable Priority](#variable-priority-1)
|
31
|
+
- [Configuration Specialization](#configuration-specialization)
|
27
32
|
- [Examples](#examples)
|
28
33
|
- [Tests](#tests)
|
29
34
|
- [Versioning](#versioning)
|
@@ -37,19 +42,22 @@ Read on for further details.
|
|
37
42
|
|
38
43
|
## Features
|
39
44
|
|
40
|
-
- Provides
|
41
|
-
|
42
|
-
-
|
43
|
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
|
47
|
-
-
|
48
|
-
|
45
|
+
- Provides an embedded `XDG::Environment` implementation that strictly adheres to the *XDG Base
|
46
|
+
Directory Specification* which provides access to the following environment settings:
|
47
|
+
- `$XDG_CACHE_HOME`
|
48
|
+
- `$XDG_CONFIG_HOME`
|
49
|
+
- `$XDG_CONFIG_DIRS`
|
50
|
+
- `$XDG_DATA_HOME`
|
51
|
+
- `$XDG_DATA_DIRS`
|
52
|
+
- Provides a developer friendly wrapping of the XDG implementation for cache, config, and data. For
|
53
|
+
the config, the following is supported:
|
54
|
+
- Supports loading of CLI-specific [YAML](http://yaml.org) configuration file.
|
55
|
+
- Supports loading and merging of nested/complex configurations.
|
56
|
+
- Supports hash representation of configuration.
|
49
57
|
|
50
58
|
## Requirements
|
51
59
|
|
52
|
-
|
60
|
+
1. [Ruby 2.6.x](https://www.ruby-lang.org).
|
53
61
|
|
54
62
|
## Setup
|
55
63
|
|
@@ -63,51 +71,47 @@ Add the following to your Gemfile:
|
|
63
71
|
|
64
72
|
## Usage
|
65
73
|
|
66
|
-
|
74
|
+
This gem provides an embedded XDG implementation along with a developer friendly wrapper
|
75
|
+
implementation. Both of which are described in detail below.
|
67
76
|
|
68
|
-
|
69
|
-
from custom locations. It is meant to be used within your CLI program(s).
|
70
|
-
|
71
|
-
An object can be initialized as follows:
|
72
|
-
|
73
|
-
configuration = Runcom::Configuration.new "example"
|
74
|
-
|
75
|
-
The default file name for a configuration is `configuration.yml` but a custom name can be used if
|
76
|
-
desired:
|
77
|
-
|
78
|
-
configuration = Runcom::Configuration.new "example", file_name: "example.yml"
|
79
|
-
|
80
|
-
Default settings can be initialized as well:
|
81
|
-
|
82
|
-
configuration = Runcom::Configuration.new "example", defaults: {name: "Example"}
|
83
|
-
|
84
|
-
Once a configuration has been initialized, a hash representation can be obtained:
|
77
|
+
### XDG
|
85
78
|
|
86
|
-
|
79
|
+
The following describes the embedded XDG implementation. It's worth noting there is a [XDG
|
80
|
+
Gem](https://github.com/rubyworks/xdg) which also implements the *XDG Base Directory Specification*
|
81
|
+
but hasn't been updated in ~6 years.
|
87
82
|
|
88
|
-
|
83
|
+
#### Overview
|
89
84
|
|
90
|
-
|
85
|
+
Provides an API that strictly adheres to the *XDG Base Directory Specification*. Usage:
|
91
86
|
|
92
|
-
|
87
|
+
xdg = Runcom::XDG::Environment.new
|
88
|
+
xdg.cache_home # <= Answers computed `$XDG_CACHE_HOME` value.
|
89
|
+
xdg.config_home # <= Answers computed `$XDG_CONFIG_HOME` value.
|
90
|
+
xdg.config_dirs # <= Answers computed `$XDG_CONFIG_DIRS` value.
|
91
|
+
xdg.data_home # <= Answers computed `$XDG_DATA_HOME` value.
|
92
|
+
xdg.data_dirs # <= Answers computed `$XDG_DATA_DIRS` value.
|
93
93
|
|
94
|
-
|
94
|
+
`Runcom::XDG::Environment` wraps the following objects which can be used individually if you don't
|
95
|
+
want to load the entire environment:
|
95
96
|
|
96
|
-
|
97
|
+
cache = Runcom::XDG::Cache.new
|
98
|
+
config = Runcom::XDG::Config.new
|
99
|
+
data = Runcom::XDG::Data.new
|
97
100
|
|
98
|
-
|
101
|
+
The `cache`, `config`, and `data` objects share the same API which means you can ask each the
|
102
|
+
following messages:
|
99
103
|
|
100
|
-
|
101
|
-
|
104
|
+
- `#home` - Answers the home directory as computed via the `$XDG_*_HOME` key.
|
105
|
+
- `#directories` - Answers an array directories as computed via the `$XDG_*_DIRS` key.
|
106
|
+
- `#all` - Answers an array of *all* directories as computed from the combined `$XDG_*_HOME` and
|
107
|
+
`$XDG_*_DIRS` values (with `$XDG_*_HOME` prefixed at the start of the array).
|
102
108
|
|
103
|
-
|
109
|
+
#### Variable Behavior
|
104
110
|
|
105
|
-
|
106
|
-
|
107
|
-
advantage of the XDG variables (additional details can be found by reading the
|
108
|
-
[XDG Specification](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)).
|
111
|
+
The behavior of all XDG environment variables can be lumped into two categories of `$XDG_*_HOME` and
|
112
|
+
`$XDG_*_DIRS` behavior. Each is described below.
|
109
113
|
|
110
|
-
|
114
|
+
##### `$XDG_*_DIRS`
|
111
115
|
|
112
116
|
This variable is used to define a colon delimited list of configuration directories. The order is
|
113
117
|
important as the first directory defined will take precedent over the following directory and so
|
@@ -126,66 +130,112 @@ In the above example, the `"/example/one/.config"` path will take highest priori
|
|
126
130
|
defined first.
|
127
131
|
|
128
132
|
When the `$XDG_CONFIG_DIRS` is not defined, it will default to the following array: `["/etc/xdg"]`.
|
133
|
+
Other `$XDG_*_DIRS` variables share similar behavior.
|
129
134
|
|
130
|
-
|
135
|
+
##### `$XDG_*_HOME`
|
131
136
|
|
132
137
|
This is the environment variable you'll want to use the most as it takes precidence over
|
133
|
-
`$
|
134
|
-
|
138
|
+
`$XDG_*_DIRS` environment variable. When not defined, it defaults to `$HOME/.config` which is
|
139
|
+
generally want you want. Other `$XDG_*_HOME` variables share similar behavior.
|
135
140
|
|
136
141
|
#### Variable Priority
|
137
142
|
|
138
143
|
Configuration path precedence is determined in the following order (with the first taking highest
|
139
144
|
priority):
|
140
145
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
(highest priority). It will choose the first directory, in priority, that exists on the file
|
145
|
-
system while skipping any that don't exist.
|
146
|
+
1. `$XDG_*_HOME` - Will be used if defined. Otherwise, falls back to specification default.
|
147
|
+
1. `$XDG_*_DIRS` - Iterates through directories in order defined (with first taking highest
|
148
|
+
priority). Otherwise, falls back to specification default.
|
146
149
|
|
147
|
-
###
|
150
|
+
### Runcom
|
151
|
+
|
152
|
+
Provides wrapper objects around the `XDG` objects which extends and enhances beyond what is found in
|
153
|
+
the *XDG Base Directory Specification*. This includes preference of local over global
|
154
|
+
configurations by default as well as other conveniences.
|
155
|
+
|
156
|
+
#### Overview
|
157
|
+
|
158
|
+
While there isn't an environment convenience object as found in the `XDG` namespace, you can
|
159
|
+
instantiate each object individually:
|
160
|
+
|
161
|
+
cache = Runcom::Cache.new
|
162
|
+
config = Runcom::Config.new
|
163
|
+
data = Runcom::Data.new
|
164
|
+
|
165
|
+
Each of the above objects share the same basic API:
|
166
|
+
|
167
|
+
- `#path` - Answers first existing file system path first computed by the `$XDG_*_HOME` value
|
168
|
+
followed by each computed `$XDG_*_DIRS` value in the order defined.
|
169
|
+
- `#paths` - Answers all file system paths which is the combined `$XDG_*_HOME` and `$XDG_*_DIRS`
|
170
|
+
values in the order defined.
|
171
|
+
|
172
|
+
#### Variable Priority
|
173
|
+
|
174
|
+
Configuration path precedence is determined in the following order (with the first taking highest
|
175
|
+
priority):
|
176
|
+
|
177
|
+
1. **Local Configuration** - If a `$XDG_*_HOME` or `$XDG_*_DIRS` path relative to the current
|
178
|
+
working directory is detected, it will take preference over the global configuration. This is the
|
179
|
+
same behavior as found in Git where the local `.git/config` takes precedence over the global
|
180
|
+
`~/.gitconfig`.
|
181
|
+
1. **Global Configuration** - When a local configuration isn't found, the global configuration is
|
182
|
+
used as defined by the *XDG Base Directory Specification*.
|
183
|
+
|
184
|
+
#### Configuration Specialization
|
185
|
+
|
186
|
+
The `Runcom::Config` deserves additional highlighting as it provides support for loading custom CLI
|
187
|
+
configurations directly from the command line or from custom locations. It is meant to be used
|
188
|
+
within your CLI program(s).
|
189
|
+
|
190
|
+
An object can be initialized as follows:
|
191
|
+
|
192
|
+
configuration = Runcom::Config.new "example"
|
193
|
+
|
194
|
+
The default file name for a configuration is `configuration.yml` but a custom name can be used if
|
195
|
+
desired:
|
196
|
+
|
197
|
+
configuration = Runcom::Config.new "example", file_name: "example.yml"
|
198
|
+
|
199
|
+
Default settings can be initialized as well:
|
200
|
+
|
201
|
+
configuration = Runcom::Config.new "example", defaults: {name: "Example"}
|
202
|
+
|
203
|
+
Once a configuration has been initialized, a hash representation can be obtained:
|
148
204
|
|
149
|
-
|
150
|
-
[direnv](https://direnv.net) where you can define a custom `XDG_CONFIG_HOME` for your specific
|
151
|
-
project.
|
205
|
+
configuration.to_h
|
152
206
|
|
153
|
-
|
207
|
+
A configuration can be merged with another hash (handy for runtime overrides):
|
154
208
|
|
155
|
-
|
156
|
-
/.config/test/configuration.yml
|
157
|
-
/.envrc
|
209
|
+
updated_configuration = configuration.merge {name: "Updated Name"}
|
158
210
|
|
159
|
-
|
211
|
+
A configuration can also be merged with another configuration:
|
160
212
|
|
161
|
-
|
213
|
+
updated_configuration = configuration.merge Runcom::Config.new("other", defaults: {a: 1})
|
162
214
|
|
163
|
-
|
164
|
-
instead of `~/.config` (which is the default behavior). While running code within this project, you
|
165
|
-
could initialize your configuration object like this:
|
215
|
+
The computed path of the configuration can be asked for as well:
|
166
216
|
|
167
|
-
configuration
|
217
|
+
configuration.path # "~/.config/example/configuration.yml"
|
168
218
|
|
169
|
-
|
170
|
-
|
219
|
+
For further details, study the public interface as provided by the
|
220
|
+
[`Runcom::Config`](lib/runcom/config.rb) object.
|
171
221
|
|
172
|
-
|
222
|
+
### Examples
|
173
223
|
|
174
224
|
If you need further examples of gems that use this gem, check out the following:
|
175
225
|
|
176
226
|
- [Gemsmith](https://github.com/bkuhlmann/gemsmith) - A command line interface for smithing new Ruby
|
177
227
|
gems.
|
228
|
+
- [Git Cop](https://github.com/bkuhlmann/git-cop) - Enforces consistent Git commits.
|
178
229
|
- [Milestoner](https://github.com/bkuhlmann/milestoner) - A command line interface for releasing Git
|
179
230
|
repository milestones.
|
180
|
-
- [
|
181
|
-
|
182
|
-
contents for Markdown files.
|
231
|
+
- [Pennyworth](https://github.com/bkuhlmann/pennyworth) - A command line interface that enhances and
|
232
|
+
extends [Alfred](https://www.alfredapp.com) with Ruby support.
|
183
233
|
- [Pragmater](https://github.com/bkuhlmann/pragmater) - A command line interface for
|
184
234
|
managing/formatting source file pragma comments.
|
185
235
|
- [Sublime Text Kit](https://github.com/bkuhlmann/sublime_text_kit) - A command line interface for
|
186
236
|
managing Sublime Text metadata.
|
187
|
-
- [
|
188
|
-
|
237
|
+
- [Tocer](https://github.com/bkuhlmann/tocer) - A command line interface for generating table of
|
238
|
+
contents for Markdown files.
|
189
239
|
|
190
240
|
## Tests
|
191
241
|
|
@@ -195,7 +245,7 @@ To test, run:
|
|
195
245
|
|
196
246
|
## Versioning
|
197
247
|
|
198
|
-
Read [Semantic Versioning](
|
248
|
+
Read [Semantic Versioning](https://semver.org) for details. Briefly, it means:
|
199
249
|
|
200
250
|
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
201
251
|
- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
|
data/lib/runcom/cache.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Runcom
|
4
|
+
# A developer friendly wrapper of XDG cache.
|
5
|
+
Cache = Struct.new :name, :home, :environment, keyword_init: true do
|
6
|
+
def initialize *arguments
|
7
|
+
super
|
8
|
+
|
9
|
+
self[:home] ||= Runcom::Paths::Friendly
|
10
|
+
self[:environment] ||= ENV
|
11
|
+
freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
paths.find(&:exist?)
|
16
|
+
end
|
17
|
+
|
18
|
+
def paths
|
19
|
+
XDG::Cache.new(home: home, environment: environment).all
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,8 +5,8 @@ require "yaml"
|
|
5
5
|
require "refinements/hashes"
|
6
6
|
|
7
7
|
module Runcom
|
8
|
-
#
|
9
|
-
class
|
8
|
+
# A developer friendly wrapper of XDG config.
|
9
|
+
class Config
|
10
10
|
using Refinements::Hashes
|
11
11
|
|
12
12
|
DEFAULT_FILE_NAME = "configuration.yml"
|
@@ -22,13 +22,19 @@ module Runcom
|
|
22
22
|
paths.find(&:exist?)
|
23
23
|
end
|
24
24
|
|
25
|
+
def paths
|
26
|
+
XDG::Config.new(home: Runcom::Paths::Friendly).all.map do |root|
|
27
|
+
Pathname "#{root}/#{name}/#{file_name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
def merge other
|
26
32
|
self.class.new name, file_name: file_name, defaults: settings.deep_merge(other.to_h)
|
27
33
|
end
|
28
34
|
|
29
35
|
# :reek:FeatureEnvy
|
30
36
|
def == other
|
31
|
-
other.is_a?(
|
37
|
+
other.is_a?(Config) && hash == other.hash
|
32
38
|
end
|
33
39
|
|
34
40
|
alias eql? ==
|
@@ -57,11 +63,5 @@ module Runcom
|
|
57
63
|
yaml = YAML.load_file path
|
58
64
|
yaml.is_a?(Hash) ? yaml : {}
|
59
65
|
end
|
60
|
-
|
61
|
-
def paths
|
62
|
-
XDG::Configuration.computed_dirs.map do |root|
|
63
|
-
Pathname "#{root}/#{name}/#{file_name}"
|
64
|
-
end
|
65
|
-
end
|
66
66
|
end
|
67
67
|
end
|
data/lib/runcom/data.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
# A developer friendly wrapper of XDG data.
|
7
|
+
Data = Struct.new :name, :home, :environment, keyword_init: true do
|
8
|
+
def initialize *arguments
|
9
|
+
super
|
10
|
+
|
11
|
+
self[:home] ||= Runcom::Paths::Friendly
|
12
|
+
self[:environment] ||= ENV
|
13
|
+
freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
paths.find(&:exist?)
|
18
|
+
end
|
19
|
+
|
20
|
+
def paths
|
21
|
+
XDG::Data.new(home: home, environment: environment).all.map do |root|
|
22
|
+
Pathname "#{root}/#{name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/runcom/identity.rb
CHANGED
data/lib/runcom/pair.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module Paths
|
7
|
+
# The combined home and directories for environment.
|
8
|
+
class Combined
|
9
|
+
def initialize initial_home, initial_directories
|
10
|
+
@initial_home = initial_home
|
11
|
+
@initial_directories = initial_directories
|
12
|
+
end
|
13
|
+
|
14
|
+
def home
|
15
|
+
initial_home.dynamic
|
16
|
+
end
|
17
|
+
|
18
|
+
def directories
|
19
|
+
initial_directories.dynamic
|
20
|
+
end
|
21
|
+
|
22
|
+
def all
|
23
|
+
directories.prepend home
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :initial_home, :initial_directories
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module Paths
|
7
|
+
# A collection of XDG directories with a strict adherence to the XDG specification.
|
8
|
+
class Directory
|
9
|
+
DELIMITER = ":"
|
10
|
+
|
11
|
+
def initialize pair, environment = ENV
|
12
|
+
@pair = pair
|
13
|
+
@environment = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def default
|
17
|
+
String(pair.value).split(DELIMITER).map { |path| Pathname(path).expand_path }
|
18
|
+
end
|
19
|
+
|
20
|
+
def dynamic
|
21
|
+
environment.fetch(pair.key, String(pair.value)).split(DELIMITER).uniq.map do |path|
|
22
|
+
Pathname(path).expand_path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :pair, :environment
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module Paths
|
7
|
+
# A XDG home path with a loose adherence to XDG specification by preferring local path if it
|
8
|
+
# exists, otherwise defaulting to standard computed path.
|
9
|
+
class Friendly
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
delegate %i[key value default] => :standard
|
13
|
+
|
14
|
+
def initialize pair, environment = ENV
|
15
|
+
@standard = Standard.new pair, environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def dynamic
|
19
|
+
path = String value
|
20
|
+
File.exist?(path) ? Pathname(path).expand_path : standard.dynamic
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :standard
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
module Runcom
|
7
|
+
module Paths
|
8
|
+
# A XDG home path with a strict adherence to the XDG specification.
|
9
|
+
class Standard
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
HOME_KEY = "HOME"
|
13
|
+
|
14
|
+
delegate %i[key value] => :pair
|
15
|
+
|
16
|
+
def initialize pair, environment = ENV
|
17
|
+
@pair = pair
|
18
|
+
@environment = environment
|
19
|
+
end
|
20
|
+
|
21
|
+
def default
|
22
|
+
home.join(String(value)).expand_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def dynamic
|
26
|
+
path = String environment[key]
|
27
|
+
path.empty? ? default : home.join(path).expand_path
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :pair, :environment
|
33
|
+
|
34
|
+
def home
|
35
|
+
Pathname environment.fetch(HOME_KEY)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module XDG
|
7
|
+
# A XDG cache that adheres to specification defaults.
|
8
|
+
class Cache
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
HOME_PAIR = Pair.new("XDG_CACHE_HOME", ".cache").freeze
|
12
|
+
|
13
|
+
delegate %i[home directories all] => :combined
|
14
|
+
|
15
|
+
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
16
|
+
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
17
|
+
directories.new(Runcom::Pair.new, environment)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :combined
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module XDG
|
7
|
+
# A XDG configuration that adheres to specification defaults.
|
8
|
+
class Config
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
HOME_PAIR = Pair.new("XDG_CONFIG_HOME", ".config").freeze
|
12
|
+
DIRS_PAIR = Pair.new("XDG_CONFIG_DIRS", "/etc/xdg").freeze
|
13
|
+
|
14
|
+
delegate %i[home directories all] => :combined
|
15
|
+
|
16
|
+
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
17
|
+
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
18
|
+
directories.new(DIRS_PAIR, environment)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :combined
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module Runcom
|
6
|
+
module XDG
|
7
|
+
# XDG data that adheres to specification defaults.
|
8
|
+
class Data
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
HOME_PAIR = Pair.new("XDG_DATA_HOME", ".local/share").freeze
|
12
|
+
DIRS_PAIR = Pair.new("XDG_DATA_DIRS", "/usr/local/share:/usr/share").freeze
|
13
|
+
|
14
|
+
delegate %i[home directories all] => :combined
|
15
|
+
|
16
|
+
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
17
|
+
@combined = Paths::Combined.new home.new(HOME_PAIR, environment),
|
18
|
+
directories.new(DIRS_PAIR, environment)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :combined
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Runcom
|
4
|
+
module XDG
|
5
|
+
# A XDG environment that provides access to all variables.
|
6
|
+
class Environment
|
7
|
+
def initialize home: Paths::Standard, directories: Paths::Directory, environment: ENV
|
8
|
+
@cache = Cache.new home: home, directories: directories, environment: environment
|
9
|
+
@config = Config.new home: home, directories: directories, environment: environment
|
10
|
+
@data = Data.new home: home, directories: directories, environment: environment
|
11
|
+
end
|
12
|
+
|
13
|
+
def cache_home
|
14
|
+
cache.home
|
15
|
+
end
|
16
|
+
|
17
|
+
def config_home
|
18
|
+
config.home
|
19
|
+
end
|
20
|
+
|
21
|
+
def config_dirs
|
22
|
+
config.directories
|
23
|
+
end
|
24
|
+
|
25
|
+
def data_home
|
26
|
+
data.home
|
27
|
+
end
|
28
|
+
|
29
|
+
def data_dirs
|
30
|
+
data.directories
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :cache, :config, :data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/runcom.rb
CHANGED
@@ -3,5 +3,15 @@
|
|
3
3
|
require "runcom/identity"
|
4
4
|
require "runcom/errors/base"
|
5
5
|
require "runcom/errors/syntax"
|
6
|
-
require "runcom/
|
7
|
-
require "runcom/
|
6
|
+
require "runcom/pair"
|
7
|
+
require "runcom/paths/standard"
|
8
|
+
require "runcom/paths/friendly"
|
9
|
+
require "runcom/paths/directory"
|
10
|
+
require "runcom/paths/combined"
|
11
|
+
require "runcom/xdg/config"
|
12
|
+
require "runcom/xdg/data"
|
13
|
+
require "runcom/xdg/cache"
|
14
|
+
require "runcom/xdg/environment"
|
15
|
+
require "runcom/config"
|
16
|
+
require "runcom/cache"
|
17
|
+
require "runcom/data"
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runcom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
4Zrsxi713z6sndd9JBAm4G7mJiV93MsuCM5N4ZDY7XaxIhvctNSNhX/Yn8LLdtGI
|
30
30
|
b4jw5t40FKyNUvLPPXYAvQALBtk=
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2019-01-01 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: refinements
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '6.0'
|
41
41
|
type: :runtime
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '6.0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler-audit
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,145 +74,131 @@ dependencies:
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0.1'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.0'
|
83
|
-
type: :development
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.0'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: gemsmith
|
77
|
+
name: guard-rspec
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '4.7'
|
97
83
|
type: :development
|
98
84
|
prerelease: false
|
99
85
|
version_requirements: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '4.7'
|
104
90
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
91
|
+
name: pry
|
106
92
|
requirement: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '0.10'
|
111
97
|
type: :development
|
112
98
|
prerelease: false
|
113
99
|
version_requirements: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '0.10'
|
118
104
|
- !ruby/object:Gem::Dependency
|
119
|
-
name:
|
105
|
+
name: pry-byebug
|
120
106
|
requirement: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
110
|
+
version: '3.5'
|
125
111
|
type: :development
|
126
112
|
prerelease: false
|
127
113
|
version_requirements: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
117
|
+
version: '3.5'
|
132
118
|
- !ruby/object:Gem::Dependency
|
133
|
-
name:
|
119
|
+
name: rake
|
134
120
|
requirement: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
124
|
+
version: '12.3'
|
139
125
|
type: :development
|
140
126
|
prerelease: false
|
141
127
|
version_requirements: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
131
|
+
version: '12.3'
|
146
132
|
- !ruby/object:Gem::Dependency
|
147
|
-
name:
|
133
|
+
name: reek
|
148
134
|
requirement: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
138
|
+
version: '5.0'
|
153
139
|
type: :development
|
154
140
|
prerelease: false
|
155
141
|
version_requirements: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
145
|
+
version: '5.0'
|
160
146
|
- !ruby/object:Gem::Dependency
|
161
|
-
name:
|
147
|
+
name: rspec
|
162
148
|
requirement: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
152
|
+
version: '3.8'
|
167
153
|
type: :development
|
168
154
|
prerelease: false
|
169
155
|
version_requirements: !ruby/object:Gem::Requirement
|
170
156
|
requirements:
|
171
157
|
- - "~>"
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
159
|
+
version: '3.8'
|
174
160
|
- !ruby/object:Gem::Dependency
|
175
|
-
name:
|
161
|
+
name: rubocop
|
176
162
|
requirement: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
166
|
+
version: '0.62'
|
181
167
|
type: :development
|
182
168
|
prerelease: false
|
183
169
|
version_requirements: !ruby/object:Gem::Requirement
|
184
170
|
requirements:
|
185
171
|
- - "~>"
|
186
172
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
173
|
+
version: '0.62'
|
188
174
|
- !ruby/object:Gem::Dependency
|
189
|
-
name: rspec
|
175
|
+
name: rubocop-rspec
|
190
176
|
requirement: !ruby/object:Gem::Requirement
|
191
177
|
requirements:
|
192
178
|
- - "~>"
|
193
179
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
180
|
+
version: '1.30'
|
195
181
|
type: :development
|
196
182
|
prerelease: false
|
197
183
|
version_requirements: !ruby/object:Gem::Requirement
|
198
184
|
requirements:
|
199
185
|
- - "~>"
|
200
186
|
- !ruby/object:Gem::Version
|
201
|
-
version: '
|
187
|
+
version: '1.30'
|
202
188
|
- !ruby/object:Gem::Dependency
|
203
|
-
name:
|
189
|
+
name: simplecov
|
204
190
|
requirement: !ruby/object:Gem::Requirement
|
205
191
|
requirements:
|
206
192
|
- - "~>"
|
207
193
|
- !ruby/object:Gem::Version
|
208
|
-
version: '0.
|
194
|
+
version: '0.13'
|
209
195
|
type: :development
|
210
196
|
prerelease: false
|
211
197
|
version_requirements: !ruby/object:Gem::Requirement
|
212
198
|
requirements:
|
213
199
|
- - "~>"
|
214
200
|
- !ruby/object:Gem::Version
|
215
|
-
version: '0.
|
201
|
+
version: '0.13'
|
216
202
|
description:
|
217
203
|
email:
|
218
204
|
- brooke@alchemists.io
|
@@ -225,11 +211,21 @@ files:
|
|
225
211
|
- LICENSE.md
|
226
212
|
- README.md
|
227
213
|
- lib/runcom.rb
|
228
|
-
- lib/runcom/
|
214
|
+
- lib/runcom/cache.rb
|
215
|
+
- lib/runcom/config.rb
|
216
|
+
- lib/runcom/data.rb
|
229
217
|
- lib/runcom/errors/base.rb
|
230
218
|
- lib/runcom/errors/syntax.rb
|
231
219
|
- lib/runcom/identity.rb
|
232
|
-
- lib/runcom/
|
220
|
+
- lib/runcom/pair.rb
|
221
|
+
- lib/runcom/paths/combined.rb
|
222
|
+
- lib/runcom/paths/directory.rb
|
223
|
+
- lib/runcom/paths/friendly.rb
|
224
|
+
- lib/runcom/paths/standard.rb
|
225
|
+
- lib/runcom/xdg/cache.rb
|
226
|
+
- lib/runcom/xdg/config.rb
|
227
|
+
- lib/runcom/xdg/data.rb
|
228
|
+
- lib/runcom/xdg/environment.rb
|
233
229
|
homepage: https://github.com/bkuhlmann/runcom
|
234
230
|
licenses:
|
235
231
|
- Apache-2.0
|
@@ -245,15 +241,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
241
|
requirements:
|
246
242
|
- - "~>"
|
247
243
|
- !ruby/object:Gem::Version
|
248
|
-
version: '2.
|
244
|
+
version: '2.6'
|
249
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
246
|
requirements:
|
251
247
|
- - ">="
|
252
248
|
- !ruby/object:Gem::Version
|
253
249
|
version: '0'
|
254
250
|
requirements: []
|
255
|
-
|
256
|
-
rubygems_version: 2.7.6
|
251
|
+
rubygems_version: 3.0.2
|
257
252
|
signing_key:
|
258
253
|
specification_version: 4
|
259
254
|
summary: A run command manager for command line interfaces.
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
module Runcom
|
6
|
-
module XDG
|
7
|
-
# Represents X Desktop Group (XGD) configuration support. XGD is also known as
|
8
|
-
# [Free Desktop](https://www.freedesktop.org). Here is the exact
|
9
|
-
# [specification](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) used
|
10
|
-
# for this implementation.
|
11
|
-
class Configuration
|
12
|
-
def self.home_dir
|
13
|
-
ENV.fetch "XDG_CONFIG_HOME", File.join(ENV["HOME"], ".config")
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.dirs
|
17
|
-
ENV.fetch("XDG_CONFIG_DIRS", "/etc/xdg").split ":"
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.computed_dirs
|
21
|
-
directories = dirs.prepend(home_dir).map { |directory| Pathname(directory).expand_path }
|
22
|
-
directories.select(&:exist?)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|