cli-mastermind 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9078a8e331150ebe62b1ecf44270422c93855b869510f34d57e983895a3b7fcf
|
4
|
+
data.tar.gz: c7bb2f6a630aa6b62319e409f238b88a1a81a4baa3a8e76737b1290e15efd2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec54b9f8e61defa6dd76c40cdd6d46fbba1afb6e173e47f25e0042ed69b7ca4ae32d4dd75ca924af55c22f4a10e2f4f22d2ab907f71abac789e9b08248ed7f9
|
7
|
+
data.tar.gz: ef03260db00aa0062ed9514ae5bd6e201274d89778dccafa1f74b94c1bf2566665513e4ae4fd638b1c717e1586990275d3c4786a3952b721d6bd74849c3a4554
|
data/lib/cli/mastermind.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require 'forwardable'
|
2
3
|
require 'cli/ui'
|
3
4
|
require 'cli/mastermind/arg_parse'
|
4
5
|
require 'cli/mastermind/configuration'
|
@@ -104,34 +105,44 @@ module CLI
|
|
104
105
|
|
105
106
|
unless @plans.empty?
|
106
107
|
frame('Plans') do
|
107
|
-
|
108
|
+
puts build_display_string
|
108
109
|
end
|
109
110
|
else
|
110
111
|
puts stylize("{{x}} No plans match #{@arguments.pattern.source}")
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
|
-
def
|
115
|
+
def build_display_string(plans=@plans, prefix='')
|
115
116
|
fade_code = CLI::UI::Color.new(90, '').code
|
117
|
+
reset = CLI::UI::Color::RESET.code
|
118
|
+
|
119
|
+
display_string = ''
|
116
120
|
|
117
121
|
plans.each do |(name, plan)|
|
118
122
|
next unless plan.has_children? or plan.description
|
119
123
|
|
120
|
-
|
121
|
-
|
124
|
+
display_string += prefix + '• '
|
125
|
+
display_string += stylize("{{yellow:#{titleize(name)} #{fade_code}(#{name})#{reset}\n")
|
122
126
|
|
123
127
|
if plan.aliases.any?
|
124
|
-
|
128
|
+
display_string += prefix + " - #{fade_code}aliases: #{plan.aliases.to_a.join(', ')}#{reset}\n"
|
125
129
|
end
|
126
130
|
|
127
131
|
if plan.description
|
128
|
-
|
129
|
-
|
132
|
+
display_string += prefix + ' - '
|
133
|
+
display_string += stylize("{{blue:#{plan.description}}}\n")
|
130
134
|
end
|
131
135
|
|
132
|
-
|
133
|
-
|
136
|
+
if plan.has_children?
|
137
|
+
display_string += "\n"
|
138
|
+
display_string += build_display_string(plan.children, " " + prefix)
|
139
|
+
end
|
140
|
+
|
141
|
+
display_string += "\n"
|
134
142
|
end
|
143
|
+
|
144
|
+
# Collapse any run of three or more newlines into just two
|
145
|
+
display_string.gsub(/\n{3,}/, "\n\n")
|
135
146
|
end
|
136
147
|
|
137
148
|
def filter_plans(pattern, plans=@plans)
|
@@ -15,6 +15,8 @@ module CLI
|
|
15
15
|
# _last_. You can use this to specify plans you want accessible everywhere
|
16
16
|
# or global configuration that should apply everywhere (unless overridden by
|
17
17
|
# more specific masterplans).
|
18
|
+
#
|
19
|
+
# @see Configuration::DSL
|
18
20
|
class Configuration
|
19
21
|
# Filename of masterplan files
|
20
22
|
PLANFILE = '.masterplan'
|
@@ -144,6 +146,10 @@ module CLI
|
|
144
146
|
end
|
145
147
|
end
|
146
148
|
|
149
|
+
# Describes the DSL used in masterplan files.
|
150
|
+
#
|
151
|
+
# See the .masterplan file in the root of this repo for a full example of
|
152
|
+
# the available options.
|
147
153
|
class DSL
|
148
154
|
def initialize(config, filename)
|
149
155
|
@config = config
|
@@ -154,26 +160,48 @@ module CLI
|
|
154
160
|
# Specifies that another masterplan should also be loaded when loading
|
155
161
|
# this masterplan. NOTE: This _immediately_ loads the other masterplan.
|
156
162
|
def see_also(filename)
|
157
|
-
@config.load_masterplan(filename)
|
163
|
+
@config.load_masterplan(File.expand_path(filename))
|
158
164
|
end
|
159
165
|
|
160
|
-
#
|
161
|
-
#
|
162
|
-
|
163
|
-
|
166
|
+
# Specifies the root of the project.
|
167
|
+
# +root+ must be a directory.
|
168
|
+
def project_root(root)
|
169
|
+
unless Dir.exist? root
|
170
|
+
raise InvalidDirectoryError.new('Invalid project root', root)
|
171
|
+
end
|
172
|
+
|
164
173
|
@config.project_root = root
|
165
174
|
end
|
166
|
-
alias_method :at_project_root, :project_root
|
167
175
|
|
168
|
-
#
|
169
|
-
#
|
170
|
-
def
|
171
|
-
|
176
|
+
# Syntactic sugar on top of `project_root` to specify that the current
|
177
|
+
# masterplan resides in the root of the project.
|
178
|
+
def at_project_root
|
179
|
+
project_root File.dirname(@filename)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Specify that plans exist in the given +directory+.
|
183
|
+
# Must be a valid directory
|
184
|
+
def plan_files(directory)
|
185
|
+
unless Dir.exist? directory
|
186
|
+
raise InvalidDirectoryError.new('Invalid plan file directory', directory)
|
187
|
+
end
|
188
|
+
|
189
|
+
planfiles = Dir.glob(File.join(directory, '**', "*{#{supported_extensions}}"))
|
190
|
+
planfiles.map! { |file| File.expand_path(file) }
|
191
|
+
|
192
|
+
@config.add_plans(planfiles)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Syntactic sugar on top of `plan_files` to specify that plans exist in
|
196
|
+
# a +plans/+ directory in the current directory.
|
197
|
+
def has_plan_files
|
198
|
+
plan_files File.join(File.dirname(@filename), 'plans')
|
172
199
|
end
|
173
|
-
alias_method :has_plan_files, :plan_files
|
174
200
|
|
175
201
|
# Specifies that a specific plan file exists at the given +filename+.
|
176
202
|
def plan_file(*files)
|
203
|
+
files = files.map { |file| File.expand_path file }
|
204
|
+
|
177
205
|
@config.add_plans(files)
|
178
206
|
end
|
179
207
|
|
@@ -13,6 +13,8 @@ module CLI::Mastermind
|
|
13
13
|
private
|
14
14
|
|
15
15
|
class DSL
|
16
|
+
extend Forwardable
|
17
|
+
|
16
18
|
attr_reader :plans
|
17
19
|
|
18
20
|
def initialize(filename=nil, &block)
|
@@ -50,6 +52,12 @@ module CLI::Mastermind
|
|
50
52
|
def set_alias(alias_to)
|
51
53
|
@plans.last.add_alias(alias_to)
|
52
54
|
end
|
55
|
+
|
56
|
+
# Delegate configuration to the top-level configuration object
|
57
|
+
# Planfile loading happens well after configuration has been loaded. So,
|
58
|
+
# we can safely rely on it being setup at this point.
|
59
|
+
def_delegator :'CLI::Mastermind', :configuration
|
60
|
+
alias_method :config, :configuration
|
53
61
|
end
|
54
62
|
end
|
55
63
|
end
|
data/lib/cli/mastermind/plan.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-mastermind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cli-ui
|