runcom 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -16
- data/lib/runcom.rb +1 -0
- data/lib/runcom/configuration.rb +7 -24
- data/lib/runcom/identity.rb +1 -1
- data/lib/runcom/xdg/configuration.rb +30 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0079d1916af6b0a44c839bbd3f61988c5efe1bff'
|
4
|
+
data.tar.gz: 2d41953a849b8c6b7a41f881ff552934876b160b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba0a18fb05999333917446f60d817df0256d68c9987ef66b55c54f2e4e753b687b0c699783ba99d3fa0cc1577e55887877d8137c097801c9c4fb6ef210e88396
|
7
|
+
data.tar.gz: 340f0063f2ddf39d5bd90ffa82d59c771238a1a17011f3993c01611df8c44612e003dc97974119914cc1dde9b811133bc0dfefba7140d3045d1c96bd7522ab4f
|
data/README.md
CHANGED
@@ -4,11 +4,14 @@
|
|
4
4
|
[![Code Climate GPA](https://codeclimate.com/github/bkuhlmann/runcom.svg)](https://codeclimate.com/github/bkuhlmann/runcom)
|
5
5
|
[![Code Climate Coverage](https://codeclimate.com/github/bkuhlmann/runcom/coverage.svg)](https://codeclimate.com/github/bkuhlmann/runcom)
|
6
6
|
[![Gemnasium Status](https://gemnasium.com/bkuhlmann/runcom.svg)](https://gemnasium.com/bkuhlmann/runcom)
|
7
|
-
[![
|
7
|
+
[![Circle CI Status](https://circleci.com/gh/bkuhlmann/runcom.svg?style=svg)](https://circleci.com/gh/bkuhlmann/runcom)
|
8
8
|
[![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/bkuhlmann)
|
9
9
|
|
10
|
-
|
11
|
-
(
|
10
|
+
Runcom (a.k.a. [Run Command](https://en.wikipedia.org/wiki/Run_commands)) provides common
|
11
|
+
functionality for Command Line Interfaces (CLIs) in which to manage global, local, or multiple
|
12
|
+
configurations in general. It does this by leveraging the
|
13
|
+
[XDG Base Directory Specification](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html).
|
14
|
+
Read on for further details.
|
12
15
|
|
13
16
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
14
17
|
|
@@ -18,6 +21,11 @@ A [run command manager](https://en.wikipedia.org/wiki/Run_commands) for command
|
|
18
21
|
- [Requirements](#requirements)
|
19
22
|
- [Setup](#setup)
|
20
23
|
- [Usage](#usage)
|
24
|
+
- [`Runcom::Configuration`](#runcomconfiguration)
|
25
|
+
- [XDG Configurations](#xdg-configurations)
|
26
|
+
- [`$XDG_CONFIG_DIRS`](#xdg_config_dirs)
|
27
|
+
- [`$XDG_CONFIG_HOME`](#xdg_config_home)
|
28
|
+
- [Variable Priority](#variable-priority)
|
21
29
|
- [Tests](#tests)
|
22
30
|
- [Versioning](#versioning)
|
23
31
|
- [Code of Conduct](#code-of-conduct)
|
@@ -30,9 +38,14 @@ A [run command manager](https://en.wikipedia.org/wiki/Run_commands) for command
|
|
30
38
|
|
31
39
|
# Features
|
32
40
|
|
33
|
-
-
|
34
|
-
|
35
|
-
-
|
41
|
+
- Provides run command customization by loading a CLI-specific configuration from a
|
42
|
+
[YAML](http://yaml.org) file.
|
43
|
+
- Automatically detects and resolves resource configuration file path based on XDG environment
|
44
|
+
variables which provides several benefits:
|
45
|
+
- Uses the `$XDG_CONFIG_HOME` or `$XDG_CONFIG_DIRS` variables to define configuration paths.
|
46
|
+
- Improves configuration organization by not littering your `$HOME` directory with `*rc` files and
|
47
|
+
keeping them within a central configuration folder.
|
48
|
+
- Supports loading and merging of nested/complex configurations.
|
36
49
|
- Supports hash representation of configuration.
|
37
50
|
|
38
51
|
# Requirements
|
@@ -60,26 +73,80 @@ Add the following to your Gemfile:
|
|
60
73
|
|
61
74
|
# Usage
|
62
75
|
|
63
|
-
|
76
|
+
## `Runcom::Configuration`
|
64
77
|
|
65
|
-
|
78
|
+
An object can be initialized as follows:
|
66
79
|
|
67
|
-
|
80
|
+
configuration = Runcom::Configuration.new project_name: "example"
|
68
81
|
|
69
|
-
|
82
|
+
The default file name for a configuration is `configuration.yml` but a custom name can be used if
|
83
|
+
desired:
|
70
84
|
|
71
|
-
|
72
|
-
precedence is determined as follows:
|
85
|
+
configuration = Runcom::Configuration.new project_name: "example", file_name: "example.yml"
|
73
86
|
|
74
|
-
|
75
|
-
0. Global (i.e. `$HOME/.examplerc`)
|
76
|
-
0. Defaults (i.e. `{}` unless specified upon initialization).
|
87
|
+
Default settings can be initialized as well:
|
77
88
|
|
78
|
-
|
89
|
+
configuration = Runcom::Configuration.new project_name: "example", defaults: {name: "Example"}
|
90
|
+
|
91
|
+
Once a configuration has been initialized, a hash representation can be obtained:
|
92
|
+
|
93
|
+
configuration.to_h
|
94
|
+
|
95
|
+
A configuration can be merged with another hash (handy for runtime overrides)
|
96
|
+
|
97
|
+
updated_configuration = configuration.merge {name: "Updated Name"}
|
98
|
+
|
99
|
+
The computed path of the configuration can be asked for as well:
|
100
|
+
|
101
|
+
configuration.path # "~/.config/example/configuration.yml"
|
79
102
|
|
80
103
|
For further details, study the public interface as provided by the
|
81
104
|
[`Runcom::Configuration`](lib/runcom/configuration.rb) object.
|
82
105
|
|
106
|
+
## XDG Configurations
|
107
|
+
|
108
|
+
This gem leverages the XDG `$XDG_CONFIG_DIRS` and `$XDG_CONFIG_HOME` environment variables which are
|
109
|
+
used to compute the configuration path (as mentioned above). The following details how to take
|
110
|
+
advantage of the XDG variables (additional details can be found by reading the
|
111
|
+
[XDG Specification](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)).
|
112
|
+
|
113
|
+
### `$XDG_CONFIG_DIRS`
|
114
|
+
|
115
|
+
This variable is used to define a colon delimited list of configuration directories. The order is
|
116
|
+
important as the first directory defined will take precedent over the following directory and so
|
117
|
+
forth. Example:
|
118
|
+
|
119
|
+
XDG_CONFIG_DIRS="/example/one/.config:/example/two/.settings:/example/three/.configuration"
|
120
|
+
|
121
|
+
# Yields the following array:
|
122
|
+
[
|
123
|
+
"/example/one/.config",
|
124
|
+
"/example/two/.settings",
|
125
|
+
"/example/three/.configuration"
|
126
|
+
]
|
127
|
+
|
128
|
+
In the above example, the `"/example/one/.config"` path will take highest priority since it was
|
129
|
+
defined first.
|
130
|
+
|
131
|
+
When the `$XDG_CONFIG_DIRS` is not defined, it will default to the following array: `["/etc/xdg"]`.
|
132
|
+
|
133
|
+
### `$XDG_CONFIG_HOME`
|
134
|
+
|
135
|
+
This is the environment variable you'll want to use the most as it takes precidence over
|
136
|
+
`$XDG_CONFIG_DIRS` environment variable. It is not required to be defined as it defaults to
|
137
|
+
`$HOME/.config` which is generally want you want.
|
138
|
+
|
139
|
+
### Variable Priority
|
140
|
+
|
141
|
+
Configuration path precedence is determined in the following order (with the first taking highest
|
142
|
+
priority):
|
143
|
+
|
144
|
+
0. `$XDG_CONFIG_HOME` - Will be used if defined *and* an exists on the local file system. Otherwise,
|
145
|
+
falls back to the `$XDG_CONFIG_DIRS` array.
|
146
|
+
0. `$XDG_CONFIG_DIRS` - Iterates through defined directories starting with the first one defined
|
147
|
+
(highest priority). It will choose the first directory, in priority, that exists on the file
|
148
|
+
system while skipping those that don't exist.
|
149
|
+
|
83
150
|
# Tests
|
84
151
|
|
85
152
|
To test, run:
|
data/lib/runcom.rb
CHANGED
data/lib/runcom/configuration.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pathname"
|
3
4
|
require "yaml"
|
4
5
|
require "refinements/hashes"
|
5
6
|
|
@@ -8,32 +9,14 @@ module Runcom
|
|
8
9
|
class Configuration
|
9
10
|
using Refinements::Hashes
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
attr_reader :path
|
13
|
+
|
14
|
+
def initialize project_name:, file_name: "configuration.yml", defaults: {}
|
15
|
+
@path = Pathname "#{XDG::Configuration.computed_dir}/#{project_name}/#{file_name}"
|
13
16
|
@defaults = defaults
|
14
17
|
@settings = defaults.deep_merge load_settings
|
15
18
|
end
|
16
19
|
|
17
|
-
def local?
|
18
|
-
File.exist? local_path
|
19
|
-
end
|
20
|
-
|
21
|
-
def global?
|
22
|
-
File.exist? global_path
|
23
|
-
end
|
24
|
-
|
25
|
-
def local_path
|
26
|
-
File.join Dir.pwd, file_name
|
27
|
-
end
|
28
|
-
|
29
|
-
def global_path
|
30
|
-
File.join ENV["HOME"], file_name
|
31
|
-
end
|
32
|
-
|
33
|
-
def computed_path
|
34
|
-
local? ? local_path : global_path
|
35
|
-
end
|
36
|
-
|
37
20
|
def merge custom_settings
|
38
21
|
settings.deep_merge custom_settings
|
39
22
|
end
|
@@ -44,10 +27,10 @@ module Runcom
|
|
44
27
|
|
45
28
|
private
|
46
29
|
|
47
|
-
attr_reader :
|
30
|
+
attr_reader :file_path, :defaults, :settings
|
48
31
|
|
49
32
|
def load_settings
|
50
|
-
yaml = YAML.load_file
|
33
|
+
yaml = YAML.load_file path
|
51
34
|
yaml.is_a?(Hash) ? yaml : {}
|
52
35
|
rescue
|
53
36
|
defaults
|
data/lib/runcom/identity.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
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) being
|
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.unshift(home_dir).map { |directory| Pathname(directory).expand_path }
|
22
|
+
directories.select(&:exist?)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.computed_dir
|
26
|
+
computed_dirs.first
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runcom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: refinements
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '9.
|
47
|
+
version: '9.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '9.
|
54
|
+
version: '9.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '4.
|
145
|
+
version: '4.7'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '4.
|
152
|
+
version: '4.7'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rubocop
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0.
|
159
|
+
version: '0.49'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '0.
|
166
|
+
version: '0.49'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: codeclimate-test-reporter
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- lib/runcom.rb
|
193
193
|
- lib/runcom/configuration.rb
|
194
194
|
- lib/runcom/identity.rb
|
195
|
+
- lib/runcom/xdg/configuration.rb
|
195
196
|
homepage: https://github.com/bkuhlmann/runcom
|
196
197
|
licenses:
|
197
198
|
- MIT
|