wdi 0.0.1 → 0.0.2
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/LICENSE.txt +23 -18
- data/README.md +19 -22
- data/bin/wdi +4 -0
- data/data/default-config.json +8 -0
- data/lib/wdi/cli.rb +75 -0
- data/lib/wdi/config.rb +131 -0
- data/lib/wdi/folder.rb +34 -0
- data/lib/wdi/version.rb +1 -1
- data/lib/wdi.rb +8 -2
- data/wdi.gemspec +8 -5
- metadata +44 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 072e4d21629eadc99678fe270a358e9314472052
|
4
|
+
data.tar.gz: 92f8aa139b8714d8f24fb7450f4965bb64bfea85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee5fa06b3dab7bc021c052e34a0cd4b9dcd9f7317453df1c252834d71a158ca682e959d0b80400e4f0c98f953e0e14b9dd1a0da1fe848ec94eeffb01235964a5
|
7
|
+
data.tar.gz: 37e8829b0ed20141daf877ef632685d3f86f9eeacfde723175cd64a88b6f61886d8993e262348fd673677148e7382c433fa5f8793fef5a3552be6dac0389c82a
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,27 @@
|
|
1
|
-
Copyright (c) 2014
|
1
|
+
Copyright (c) 2014, General Assembly
|
2
|
+
All rights reserved.
|
2
3
|
|
3
|
-
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
12
9
|
|
13
|
-
|
14
|
-
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
* Neither the name of General Assembly nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,29 +1,26 @@
|
|
1
|
-
#
|
1
|
+
# The WDI Tool
|
2
2
|
|
3
|
-
|
3
|
+
Use this gem to set up the WDI configuration file(s) and make changes to them. These exist in the folder ~/.wdi, and are used by the breadth of WDI command line tools in order to define common constants or development/environmental settings specific to the WDI command line tools.
|
4
4
|
|
5
|
-
##
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'wdi'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
5
|
+
## Usage
|
16
6
|
|
17
|
-
|
7
|
+
```bash
|
8
|
+
wdi init (--load URI)
|
9
|
+
#=> if there is no .wdi folder, it creates one
|
10
|
+
#=> by default it uses the example in data/default-config.json, or if
|
11
|
+
#=> --load is defined (as a URI), then it attempts to use that
|
12
|
+
#=> if there is a .wdi folder, this fails and suggests using `wdi config`
|
13
|
+
```
|
18
14
|
|
19
|
-
|
15
|
+
```bash
|
16
|
+
wdi config set <key(.key...)> <value>
|
17
|
+
wdi config get <key(.key...)>
|
20
18
|
|
21
|
-
|
19
|
+
wdi config add <key(.key...)> <value>
|
20
|
+
wdi config remove <key(.key...)> (--force)
|
22
21
|
|
23
|
-
|
22
|
+
wdi config keys (<key>)
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
24
|
+
# wdi get-base
|
25
|
+
# wdi get-repo class.current
|
26
|
+
```
|
data/bin/wdi
ADDED
data/lib/wdi/cli.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "wdi"
|
2
|
+
require "wdi/folder"
|
3
|
+
require "wdi/config"
|
4
|
+
require "thor"
|
5
|
+
|
6
|
+
module WDI
|
7
|
+
module CLI
|
8
|
+
class Config < Thor
|
9
|
+
desc "set", "set a value in the WDI config file"
|
10
|
+
def set(key, value)
|
11
|
+
begin
|
12
|
+
WDI::Config::set(key, value)
|
13
|
+
say "The key '#{key}' in the WDI config file has been set to '#{value}'.", :green
|
14
|
+
rescue WDI::ConfigError => e
|
15
|
+
say e.message, :red
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "get", "get a value from the WDI config file"
|
20
|
+
def get(key)
|
21
|
+
begin
|
22
|
+
say WDI::Config::get(WDI::Config::translate(key), key)
|
23
|
+
rescue WDI::ConfigError => e
|
24
|
+
say e.message, :red
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# desc "add", "an alias for set that appends values to a key's list (if the values are in an array)"
|
29
|
+
# def add(key, *values)
|
30
|
+
|
31
|
+
# end
|
32
|
+
|
33
|
+
# desc "remove", "deletes a key from the config file"
|
34
|
+
# method_option :force,
|
35
|
+
# aliases: ["-f"],
|
36
|
+
# default: false,
|
37
|
+
# desc: "Force key's removal, if it exists, without prompting the user for confirmation."
|
38
|
+
# def remove(key)
|
39
|
+
|
40
|
+
# end
|
41
|
+
|
42
|
+
desc "keys", "list the keys in the WDI config file"
|
43
|
+
def keys(key=nil)
|
44
|
+
begin
|
45
|
+
say WDI::Config::keys(WDI::Config::translate(key), key).join("\n")
|
46
|
+
rescue WDI::ConfigError => e
|
47
|
+
say e.message, :red
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Wdi < Thor
|
53
|
+
desc "init", "initialize a new WDI directory at ~/.wdi"
|
54
|
+
method_option :load,
|
55
|
+
aliases: ["-l"],
|
56
|
+
default: WDI::DEFAULT_CONFIG_FILE,
|
57
|
+
desc: "Load the WDI config(.json) from a local file or URI path."
|
58
|
+
method_option :force,
|
59
|
+
aliases: ["-f"],
|
60
|
+
default: false,
|
61
|
+
desc: "Force overwrite of the current WDI directory, if it exists."
|
62
|
+
def init
|
63
|
+
begin
|
64
|
+
WDI::Folder::create_with_config(options[:force], options[:load])
|
65
|
+
say "The .wdi folder and config file have been created.", :green
|
66
|
+
rescue WDI::ConfigError, WDI::FolderError => e
|
67
|
+
say e.message, :red
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "config SUBCOMMAND ...ARGS", "interact with the WDI config file"
|
72
|
+
subcommand "config", WDI::CLI::Config
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/wdi/config.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "json"
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
require "pry"
|
6
|
+
|
7
|
+
module WDI
|
8
|
+
module Config
|
9
|
+
KEY_REGEX = /^[a-z.]*$/ # only lowercase words separated by periods
|
10
|
+
|
11
|
+
def self.path
|
12
|
+
File.expand_path("config.json", WDI::Folder::path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.exists?
|
16
|
+
File.exists?(self.path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.file
|
20
|
+
@@config ||= self.load
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load
|
24
|
+
@@config = JSON.parse(IO.read(self.path), symbolize_names: true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.save
|
28
|
+
File.open(File.expand_path("config.json", WDI::Folder::path), "w+") do |f|
|
29
|
+
f.write JSON.pretty_generate(self.file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.load_file(config_uri)
|
34
|
+
begin
|
35
|
+
uri = URI(config_uri)
|
36
|
+
config_file = ["http", "https"].include?(uri.scheme) ? uri.open.read : IO.read(config_uri)
|
37
|
+
@@config = self.safe_replace(JSON.parse(config_file, symbolize_names: true))
|
38
|
+
self.save
|
39
|
+
|
40
|
+
rescue Errno::ENOENT => e
|
41
|
+
raise WDI::ConfigError, "No file at this path. Use 'http://' prefix if URI."
|
42
|
+
rescue URI::InvalidURIError => e
|
43
|
+
raise WDI::ConfigError, "Malformed URI. Could not find file at this path."
|
44
|
+
rescue OpenURI::HTTPError => e
|
45
|
+
raise WDI::ConfigError, "Provided URI can not be found. Ensure that the link is active."
|
46
|
+
rescue JSON::ParserError => e
|
47
|
+
raise WDI::ConfigError, "Provided file is not correctly formatted JSON."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
############################################
|
52
|
+
|
53
|
+
def self.get(key, key_name)
|
54
|
+
raise WDI::ConfigError, "This key is not in the WDI config file." if key.nil?
|
55
|
+
raise WDI::ConfigError,
|
56
|
+
"This key doesn't represent a property in the WDI config file. " +
|
57
|
+
"Try `wdi config keys #{key_name}`." if key.is_a?(Hash)
|
58
|
+
return key
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.set(key_name, new_value)
|
62
|
+
current_value = WDI::Config::translate(key_name)
|
63
|
+
raise WDI::ConfigError,
|
64
|
+
"This key doesn't represent a property in the WDI config file. " +
|
65
|
+
"Try `wdi config keys #{key_name}`." if current_value.is_a?(Hash)
|
66
|
+
|
67
|
+
|
68
|
+
self.set_child(self.file, key_name, new_value)
|
69
|
+
self.save
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.set_child(key, key_name, value)
|
73
|
+
parent, child = key_name.split(".", 2)
|
74
|
+
if child.nil?
|
75
|
+
key[parent.to_sym] = value
|
76
|
+
else
|
77
|
+
self.set_child(key[parent.to_sym], child, value)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.keys(tree, parent_key="", key_list=[])
|
82
|
+
raise WDI::ConfigError,
|
83
|
+
"There are no (sub-)keys in the WDI config file that fit this criteria." unless tree.is_a?(Hash)
|
84
|
+
|
85
|
+
tree.each_pair do |child_key, value|
|
86
|
+
if value.is_a?(Hash)
|
87
|
+
self.keys(value, self.append_keys(parent_key, child_key), key_list)
|
88
|
+
else
|
89
|
+
key_list << self.append_keys(parent_key, child_key)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
return key_list
|
94
|
+
end
|
95
|
+
|
96
|
+
############################################
|
97
|
+
|
98
|
+
def self.append_keys(parent, child)
|
99
|
+
parent = (parent.nil? || parent == "") ? "" : parent.to_s + "."
|
100
|
+
child = (child.nil? || child == "") ? "" : child.to_s
|
101
|
+
parent + child
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.translate(key, tree=self.file)
|
105
|
+
# assume we are talking about the config tree as a whole if nil
|
106
|
+
return tree if key.nil?
|
107
|
+
|
108
|
+
raise WDI::ConfigError,
|
109
|
+
"This key is not formatted correctly for the WDI config file." unless key =~ KEY_REGEX
|
110
|
+
parent, child = key.split(".", 2)
|
111
|
+
value = tree[parent.to_sym]
|
112
|
+
raise WDI::ConfigError, "This key is not in the WDI config file." if value.nil?
|
113
|
+
|
114
|
+
return (child.nil? ? value : self.translate(child, value))
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.safe_replace(config)
|
118
|
+
JSON.recurse_proc(config) do |line|
|
119
|
+
if line.is_a?(String)
|
120
|
+
# so this is not REALLY safe, but should be safe enough... maybe even too restrictive
|
121
|
+
allowed_bash_regex = /(`(echo|pwd|ls)[^\|;&]*`)/
|
122
|
+
|
123
|
+
result = eval( line[allowed_bash_regex] )
|
124
|
+
line.gsub!( allowed_bash_regex, result.chomp ) unless result.nil?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
return config
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/wdi/folder.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "wdi/config"
|
2
|
+
require "fileutils"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module WDI
|
6
|
+
module Folder
|
7
|
+
def self.path
|
8
|
+
File.expand_path(".wdi", "~")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.exists?
|
12
|
+
File.exists?(self.path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create(remove_current_directory)
|
16
|
+
self.remove! if remove_current_directory
|
17
|
+
|
18
|
+
raise WDI::FolderError, \
|
19
|
+
"The .wdi folder already exists. Either remove it to initialize anew, " + \
|
20
|
+
"or use `wdi config` to edit the config file." if self.exists?
|
21
|
+
|
22
|
+
Dir.mkdir self.path
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create_with_config(remove_current_directory, file)
|
26
|
+
self.create(remove_current_directory)
|
27
|
+
WDI::Config::load_file(file)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.remove!
|
31
|
+
FileUtils.rm_rf(self.path) if self.exists?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/wdi/version.rb
CHANGED
data/lib/wdi.rb
CHANGED
data/wdi.gemspec
CHANGED
@@ -6,11 +6,11 @@ require 'wdi/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "wdi"
|
8
8
|
spec.version = Wdi::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
11
|
-
spec.summary = %q{A utility
|
9
|
+
spec.authors = ["Philip Hughes"]
|
10
|
+
spec.email = ["pj@ga.co"]
|
11
|
+
spec.summary = %q{A utility for dealing with and configuring the WDI folder and command line tools.}
|
12
12
|
spec.homepage = "https://github.com/ga-instructors/wdi-gem"
|
13
|
-
spec.license = "
|
13
|
+
spec.license = "BSD 3-Clause"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -18,5 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rake", ">= 0.0"
|
22
|
+
spec.add_development_dependency "pry", ">= 0.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "thor", "~> 0.19"
|
22
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wdi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Philip Hughes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,18 +30,47 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.19'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.19'
|
41
69
|
description:
|
42
70
|
email:
|
43
|
-
-
|
44
|
-
executables:
|
71
|
+
- pj@ga.co
|
72
|
+
executables:
|
73
|
+
- wdi
|
45
74
|
extensions: []
|
46
75
|
extra_rdoc_files: []
|
47
76
|
files:
|
@@ -50,12 +79,17 @@ files:
|
|
50
79
|
- LICENSE.txt
|
51
80
|
- README.md
|
52
81
|
- Rakefile
|
82
|
+
- bin/wdi
|
83
|
+
- data/default-config.json
|
53
84
|
- lib/wdi.rb
|
85
|
+
- lib/wdi/cli.rb
|
86
|
+
- lib/wdi/config.rb
|
87
|
+
- lib/wdi/folder.rb
|
54
88
|
- lib/wdi/version.rb
|
55
89
|
- wdi.gemspec
|
56
90
|
homepage: https://github.com/ga-instructors/wdi-gem
|
57
91
|
licenses:
|
58
|
-
-
|
92
|
+
- BSD 3-Clause
|
59
93
|
metadata: {}
|
60
94
|
post_install_message:
|
61
95
|
rdoc_options: []
|
@@ -76,5 +110,6 @@ rubyforge_project:
|
|
76
110
|
rubygems_version: 2.2.2
|
77
111
|
signing_key:
|
78
112
|
specification_version: 4
|
79
|
-
summary: A utility
|
113
|
+
summary: A utility for dealing with and configuring the WDI folder and command line
|
114
|
+
tools.
|
80
115
|
test_files: []
|