yap-shell 0.7.1 → 0.7.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/.gitignore +9 -24
- data/Gemfile +1 -5
- data/LICENSE.txt +17 -18
- data/README.md +28 -14
- data/Rakefile +4 -1
- data/bin/yap +1 -3
- data/lib/.gitkeep +0 -0
- data/yap-shell.gemspec +12 -11
- metadata +19 -184
- data/.rspec +0 -2
- data/.travis.yml +0 -11
- data/DESIGN.md +0 -87
- data/Gemfile.travis +0 -8
- data/Gemfile.travis.lock +0 -104
- data/WISHLIST.md +0 -54
- data/bin/yap-dev +0 -45
- data/lib/tasks/gem.rake +0 -62
- data/lib/yap.rb +0 -52
- data/lib/yap/addon.rb +0 -24
- data/lib/yap/addon/base.rb +0 -52
- data/lib/yap/addon/export_as.rb +0 -12
- data/lib/yap/addon/loader.rb +0 -84
- data/lib/yap/addon/path.rb +0 -56
- data/lib/yap/addon/rc_file.rb +0 -21
- data/lib/yap/addon/reference.rb +0 -22
- data/lib/yap/cli.rb +0 -4
- data/lib/yap/cli/commands.rb +0 -6
- data/lib/yap/cli/commands/addon.rb +0 -14
- data/lib/yap/cli/commands/addon/disable.rb +0 -35
- data/lib/yap/cli/commands/addon/enable.rb +0 -35
- data/lib/yap/cli/commands/addon/list.rb +0 -37
- data/lib/yap/cli/commands/addon/search.rb +0 -99
- data/lib/yap/cli/commands/generate.rb +0 -13
- data/lib/yap/cli/commands/generate/addon.rb +0 -258
- data/lib/yap/cli/commands/generate/addonrb.template +0 -22
- data/lib/yap/cli/commands/generate/gemspec.template +0 -25
- data/lib/yap/cli/commands/generate/license.template +0 -21
- data/lib/yap/cli/commands/generate/rakefile.template +0 -6
- data/lib/yap/cli/commands/generate/readme.template +0 -40
- data/lib/yap/cli/options.rb +0 -162
- data/lib/yap/cli/options/addon.rb +0 -64
- data/lib/yap/cli/options/addon/disable.rb +0 -62
- data/lib/yap/cli/options/addon/enable.rb +0 -63
- data/lib/yap/cli/options/addon/list.rb +0 -65
- data/lib/yap/cli/options/addon/search.rb +0 -76
- data/lib/yap/cli/options/generate.rb +0 -59
- data/lib/yap/cli/options/generate/addon.rb +0 -63
- data/lib/yap/configuration.rb +0 -74
- data/lib/yap/gem_helper.rb +0 -195
- data/lib/yap/gem_tasks.rb +0 -6
- data/lib/yap/shell.rb +0 -116
- data/lib/yap/shell/aliases.rb +0 -58
- data/lib/yap/shell/builtins.rb +0 -18
- data/lib/yap/shell/builtins/alias.rb +0 -42
- data/lib/yap/shell/builtins/cd.rb +0 -57
- data/lib/yap/shell/builtins/env.rb +0 -11
- data/lib/yap/shell/commands.rb +0 -163
- data/lib/yap/shell/evaluation.rb +0 -439
- data/lib/yap/shell/evaluation/shell_expansions.rb +0 -99
- data/lib/yap/shell/event_emitter.rb +0 -18
- data/lib/yap/shell/execution.rb +0 -16
- data/lib/yap/shell/execution/builtin_command_execution.rb +0 -20
- data/lib/yap/shell/execution/command_execution.rb +0 -30
- data/lib/yap/shell/execution/context.rb +0 -128
- data/lib/yap/shell/execution/file_system_command_execution.rb +0 -137
- data/lib/yap/shell/execution/result.rb +0 -18
- data/lib/yap/shell/execution/ruby_command_execution.rb +0 -80
- data/lib/yap/shell/execution/shell_command_execution.rb +0 -30
- data/lib/yap/shell/prompt.rb +0 -21
- data/lib/yap/shell/repl.rb +0 -237
- data/lib/yap/shell/version.rb +0 -5
- data/lib/yap/world.rb +0 -286
- data/rcfiles/yaprc +0 -390
- data/scripts/4 +0 -8
- data/scripts/bg-vim +0 -4
- data/scripts/fail +0 -3
- data/scripts/letters +0 -8
- data/scripts/lots-of-output +0 -6
- data/scripts/pass +0 -3
- data/scripts/simulate-long-running +0 -4
- data/scripts/write-to-stderr.rb +0 -3
- data/scripts/write-to-stdout.rb +0 -3
- data/spec/features/addons/generating_an_addon_spec.rb +0 -55
- data/spec/features/addons/using_an_addon_spec.rb +0 -182
- data/spec/features/aliases_spec.rb +0 -78
- data/spec/features/environment_variables_spec.rb +0 -69
- data/spec/features/filesystem_commands_spec.rb +0 -61
- data/spec/features/first_time_spec.rb +0 -45
- data/spec/features/grouping_spec.rb +0 -81
- data/spec/features/line_editing_spec.rb +0 -174
- data/spec/features/range_spec.rb +0 -35
- data/spec/features/redirection_spec.rb +0 -234
- data/spec/features/repetition_spec.rb +0 -118
- data/spec/features/shell_expansions_spec.rb +0 -127
- data/spec/spec_helper.rb +0 -172
- data/spec/support/matchers/have_not_printed.rb +0 -30
- data/spec/support/matchers/have_printed.rb +0 -68
- data/spec/support/very_soon.rb +0 -9
- data/spec/support/yap_spec_dsl.rb +0 -258
- data/test.rb +0 -206
- data/update-rawline.sh +0 -6
@@ -1,258 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'term/ansicolor'
|
3
|
-
|
4
|
-
module Yap
|
5
|
-
module Cli
|
6
|
-
module Commands
|
7
|
-
class Generate::Addon
|
8
|
-
attr_accessor :addon_name, :version, :use_git
|
9
|
-
|
10
|
-
def initialize(addon_name)
|
11
|
-
@addon_name = addon_name.gsub(/[^\w\-_]+/, '-').downcase
|
12
|
-
@version = '0.1.0'
|
13
|
-
@use_git = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def doing(text, &block)
|
17
|
-
print "#{text}"
|
18
|
-
block.call
|
19
|
-
puts " #{Term::ANSIColor.green('done')}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def process
|
23
|
-
puts "Creating addon #{Term::ANSIColor.yellow(addon_name)} in #{addon_dir}/"
|
24
|
-
puts
|
25
|
-
|
26
|
-
mkdir addon_dir
|
27
|
-
Dir.chdir addon_dir do
|
28
|
-
mkdir lib_path
|
29
|
-
write_file 'Gemfile', gemfile_contents
|
30
|
-
write_file gemspec_name, gemspec_contents
|
31
|
-
write_file 'LICENSE.txt', license_contents
|
32
|
-
write_file 'Rakefile', rakefile_contents
|
33
|
-
write_file 'README.md', readme_contents
|
34
|
-
write_file addonrb_path, addonrb_contents
|
35
|
-
mkdir lib_addon_path
|
36
|
-
write_file version_path, version_contents
|
37
|
-
|
38
|
-
puts
|
39
|
-
if use_git && `which git` && $?.exitstatus == 0
|
40
|
-
write_file '.gitignore', gitignore_contents
|
41
|
-
doing "git init . && git add . && git commit -m 'initial commit of #{addon_name}'" do
|
42
|
-
`git init . && git add . && git commit -m 'initial commit of #{addon_name} addon for yap'`
|
43
|
-
end
|
44
|
-
else
|
45
|
-
puts "Git initialization #{Term::ANSIColor.cyan('skipped')}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
puts
|
50
|
-
puts "Yap addon generated! A few helpful things to note:"
|
51
|
-
puts
|
52
|
-
puts <<-TEXT.gsub(/^\s*\|/, '')
|
53
|
-
| * The #{Term::ANSIColor.yellow(addon_name)} addon has been generated in #{addon_dir}/
|
54
|
-
| * It is a standard rubygem, has its own gemspec, and is named #{Term::ANSIColor.yellow(gem_safe_addon_name)}
|
55
|
-
| * Yap loads the #{Term::ANSIColor.yellow(constant_name)}, found in #{addonrb_path} (start there)
|
56
|
-
| * Share your addon with others by building a gem and pushing it to rubygems
|
57
|
-
|
|
58
|
-
|For more information see https://github.com/zdennis/yap-shell/wiki/Addons
|
59
|
-
|
|
60
|
-
|Now, to get started:
|
61
|
-
|
|
62
|
-
| cd #{gem_safe_addon_name}
|
63
|
-
TEXT
|
64
|
-
puts
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def mkdir(path)
|
70
|
-
doing("Create directory: #{path}"){ FileUtils.mkdir_p path }
|
71
|
-
end
|
72
|
-
|
73
|
-
def write_file(path, contents)
|
74
|
-
doing "Creating file: #{path}" do
|
75
|
-
File.write path, contents
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def addon_dir
|
80
|
-
gem_safe_addon_name
|
81
|
-
end
|
82
|
-
|
83
|
-
def addonrb_path
|
84
|
-
File.join(lib_path, gem_safe_addon_name + '.rb')
|
85
|
-
end
|
86
|
-
|
87
|
-
def addonrb_contents
|
88
|
-
contents = File.read(File.dirname(__FILE__) + '/addonrb.template')
|
89
|
-
contents % addonrb_template_variables
|
90
|
-
end
|
91
|
-
|
92
|
-
def addonrb_template_variables
|
93
|
-
export_as = addon_name
|
94
|
-
export_as = "'#{addon_name}'" if addon_name =~ /-/
|
95
|
-
{
|
96
|
-
addon_dir: addon_dir,
|
97
|
-
constant_name: constant_name,
|
98
|
-
export_as: export_as
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def bundler_version
|
103
|
-
require 'bundler/version'
|
104
|
-
Bundler::VERSION.scan(/\d+\.\d+/).first ||
|
105
|
-
fail('Cannot determine bundler version')
|
106
|
-
end
|
107
|
-
|
108
|
-
def constant_name
|
109
|
-
gem_safe_addon_name.split(/\W+/).map(&:capitalize).join
|
110
|
-
end
|
111
|
-
|
112
|
-
def gemfile_contents
|
113
|
-
<<-GEMFILE.gsub(/^\s*\|/, '')
|
114
|
-
|source 'https://rubygems.org'
|
115
|
-
|
|
116
|
-
|# Specify your gem's dependencies in #{gemspec_name}
|
117
|
-
|gemspec
|
118
|
-
GEMFILE
|
119
|
-
end
|
120
|
-
|
121
|
-
def gem_safe_addon_name
|
122
|
-
"yap-shell-addon-#{addon_name}"
|
123
|
-
end
|
124
|
-
|
125
|
-
def gemspec_name
|
126
|
-
"#{gem_safe_addon_name}.gemspec"
|
127
|
-
end
|
128
|
-
|
129
|
-
def gemspec_contents
|
130
|
-
contents = File.read(File.dirname(__FILE__) + '/gemspec.template')
|
131
|
-
contents % gemspec_template_variables
|
132
|
-
end
|
133
|
-
|
134
|
-
def gemspec_template_variables
|
135
|
-
{
|
136
|
-
addon_dir: addon_dir,
|
137
|
-
constant_name: constant_name,
|
138
|
-
summary: "#{addon_name} summary goes here.",
|
139
|
-
description: "#{addon_name} description goes here.",
|
140
|
-
license: 'MIT',
|
141
|
-
authors: [],
|
142
|
-
email: 'you@example.com',
|
143
|
-
homepage: '',
|
144
|
-
bundler_version: bundler_version,
|
145
|
-
rake_version: rake_version,
|
146
|
-
rspec_version: rspec_version,
|
147
|
-
yap_version: yap_version
|
148
|
-
}
|
149
|
-
end
|
150
|
-
|
151
|
-
def gitignore_contents
|
152
|
-
<<-TEXT.gsub(/^\s*/, '')
|
153
|
-
*.gem
|
154
|
-
*.rbc
|
155
|
-
.bundle
|
156
|
-
.config
|
157
|
-
.yardoc
|
158
|
-
Gemfile.lock
|
159
|
-
InstalledFiles
|
160
|
-
_yardoc
|
161
|
-
coverage
|
162
|
-
doc/
|
163
|
-
lib/bundler/man
|
164
|
-
pkg
|
165
|
-
rdoc
|
166
|
-
spec/reports
|
167
|
-
test/tmp
|
168
|
-
test/version_tmp
|
169
|
-
tmp
|
170
|
-
*.bundle
|
171
|
-
*.so
|
172
|
-
*.o
|
173
|
-
*.a
|
174
|
-
mkmf.log
|
175
|
-
wiki/
|
176
|
-
TEXT
|
177
|
-
end
|
178
|
-
|
179
|
-
def lib_path
|
180
|
-
File.join('lib')
|
181
|
-
end
|
182
|
-
|
183
|
-
def lib_addon_path
|
184
|
-
File.join(lib_path, addon_dir)
|
185
|
-
end
|
186
|
-
|
187
|
-
def license_contents
|
188
|
-
contents = File.read(File.dirname(__FILE__) + '/license.template')
|
189
|
-
contents % license_template_variables
|
190
|
-
end
|
191
|
-
|
192
|
-
def license_template_variables
|
193
|
-
username = (`git config user.name` rescue 'YOUR_NAME')
|
194
|
-
{ username: username }
|
195
|
-
end
|
196
|
-
|
197
|
-
def rake_version
|
198
|
-
require 'rake/version'
|
199
|
-
version_string = if Rake.const_defined?(:VERSION)
|
200
|
-
Rake::VERSION
|
201
|
-
else
|
202
|
-
Rake::Version::NUMBERS.join('.')
|
203
|
-
end
|
204
|
-
version_string.scan(/\d+\.\d+/).first ||
|
205
|
-
fail('Cannot determine rake version')
|
206
|
-
end
|
207
|
-
|
208
|
-
def rakefile_contents
|
209
|
-
File.read(File.dirname(__FILE__) + '/rakefile.template')
|
210
|
-
end
|
211
|
-
|
212
|
-
def readme_contents
|
213
|
-
contents = File.read(File.dirname(__FILE__) + '/readme.template')
|
214
|
-
contents % readme_template_variables
|
215
|
-
end
|
216
|
-
|
217
|
-
def readme_template_variables
|
218
|
-
{
|
219
|
-
addon_name: addon_name,
|
220
|
-
gem_safe_addon_name: gem_safe_addon_name,
|
221
|
-
lib_addon_path: lib_addon_path,
|
222
|
-
addon_dir: addon_dir,
|
223
|
-
constant_name: constant_name,
|
224
|
-
summary: "#{addon_name} summary goes here.",
|
225
|
-
description: "#{addon_name} description goes here.",
|
226
|
-
license: 'MIT',
|
227
|
-
authors: [],
|
228
|
-
email: 'you@example.com',
|
229
|
-
homepage: ''
|
230
|
-
}
|
231
|
-
end
|
232
|
-
|
233
|
-
def rspec_version
|
234
|
-
require 'rspec/version'
|
235
|
-
RSpec::Version::STRING.scan(/\d+\.\d+/).first ||
|
236
|
-
fail('Cannot determine rspec version')
|
237
|
-
end
|
238
|
-
|
239
|
-
def version_path
|
240
|
-
File.join(lib_addon_path, 'version.rb')
|
241
|
-
end
|
242
|
-
|
243
|
-
def version_contents
|
244
|
-
<<-RUBY.gsub(/^\s*\|/, '')
|
245
|
-
|module #{constant_name}
|
246
|
-
| VERSION = '#{version}'
|
247
|
-
|end
|
248
|
-
RUBY
|
249
|
-
end
|
250
|
-
|
251
|
-
def yap_version
|
252
|
-
Yap::Shell::VERSION.scan(/\d+\.\d+/).first ||
|
253
|
-
fail('Cannot determine yap version')
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'yap/addon'
|
2
|
-
require '%{addon_dir}/version'
|
3
|
-
|
4
|
-
module %{constant_name}
|
5
|
-
class Addon < ::Yap::Addon::Base
|
6
|
-
self.export_as :%{export_as}
|
7
|
-
|
8
|
-
def initialize_world(world)
|
9
|
-
@world = world
|
10
|
-
|
11
|
-
# Initialize your addon here. A few helpful things:
|
12
|
-
#
|
13
|
-
# @world is an Yap::World instance and it brings together
|
14
|
-
# all the things you may want to interact with. E.g.
|
15
|
-
# aliases, builtins, env, shell_commands, key bindings,
|
16
|
-
# editor, prompt, etc.
|
17
|
-
#
|
18
|
-
# For more information see:
|
19
|
-
# https://github.com/zdennis/yap-shell/wiki/Addons
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/lib/%{addon_dir}/version'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = '%{addon_dir}'
|
5
|
-
spec.version = %{constant_name}::VERSION
|
6
|
-
spec.authors = ['Your name']
|
7
|
-
spec.email = '%{email}'
|
8
|
-
spec.date = Date.today.to_s
|
9
|
-
|
10
|
-
spec.summary = '%{summary}'
|
11
|
-
spec.description = '%{description}'
|
12
|
-
spec.homepage = '%{homepage}'
|
13
|
-
spec.license = '%{license}'
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
|
16
|
-
spec.bindir = "exe"
|
17
|
-
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_dependency "yap-shell", "~> %{yap_version}"
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> %{bundler_version}"
|
23
|
-
spec.add_development_dependency "rake", "~> %{rake_version}"
|
24
|
-
spec.add_development_dependency "rspec", "~> %{rspec_version}"
|
25
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 %{username}
|
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.
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# %{addon_name} for yap-shell
|
2
|
-
|
3
|
-
Welcome to your new yap addon! In this directory, you'll find the files you need to be able to package up your addon into a gem. Put your Ruby code in the file `%{lib_addon_path}`.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem '%{gem_safe_addon_name}'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install %{gem_safe_addon_name}
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/%{gem_safe_addon_name}.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/yap/cli/options.rb
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'yap/cli/options'
|
3
|
-
|
4
|
-
module Yap
|
5
|
-
module Cli
|
6
|
-
module OptionsLoader
|
7
|
-
|
8
|
-
def load_command(path)
|
9
|
-
load_constant_from_path Pathname.new('yap/cli/commands').join(path)
|
10
|
-
end
|
11
|
-
|
12
|
-
def load_constant_from_path(path)
|
13
|
-
requiring_parts = []
|
14
|
-
path_parts = path.to_s.split('/')
|
15
|
-
requiring_path = nil
|
16
|
-
constant = path_parts.reduce(Object) do |constant, path_part|
|
17
|
-
requiring_parts << path_part
|
18
|
-
file2load = Yap.root.join('lib', requiring_parts.join('/') + "*.rb")
|
19
|
-
requiring_path = Dir[ file2load ].sort.first
|
20
|
-
if requiring_path
|
21
|
-
require requiring_path
|
22
|
-
path_part = File.basename(requiring_path).sub(/\.rb$/, '')
|
23
|
-
requiring_parts.pop
|
24
|
-
requiring_parts.push path_part
|
25
|
-
constant_name = path_part.capitalize
|
26
|
-
if constant.const_defined?(constant_name)
|
27
|
-
constant = constant.const_get(constant_name)
|
28
|
-
else
|
29
|
-
fail "Couldn't find #{path_part} in #{constant}"
|
30
|
-
end
|
31
|
-
else
|
32
|
-
fail LoadError, "Couldn't load any file for #{file2load}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
Treefell['shell'].puts "#{inspect} loaded: #{constant}"
|
36
|
-
constant
|
37
|
-
end
|
38
|
-
|
39
|
-
def load_relative_constant(path_str)
|
40
|
-
base_path = self.class.name.downcase.gsub(/::/, '/')
|
41
|
-
require_path = Pathname.new(base_path)
|
42
|
-
load_constant_from_path require_path.join(path_str).to_s
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Options
|
47
|
-
include OptionsLoader
|
48
|
-
|
49
|
-
attr_reader :options
|
50
|
-
|
51
|
-
def initialize(options: {})
|
52
|
-
@options = options
|
53
|
-
@commands = []
|
54
|
-
end
|
55
|
-
|
56
|
-
def [](key)
|
57
|
-
@options[key]
|
58
|
-
end
|
59
|
-
|
60
|
-
def commands
|
61
|
-
@commands.dup.freeze
|
62
|
-
end
|
63
|
-
|
64
|
-
def parse(args)
|
65
|
-
option_parser.order!(args)
|
66
|
-
options_instance = self
|
67
|
-
|
68
|
-
Yap.configuration.run_shell = false if args.any?
|
69
|
-
|
70
|
-
scope = []
|
71
|
-
require_path = Pathname.new("yap/cli/options")
|
72
|
-
args_processed = []
|
73
|
-
|
74
|
-
while args.any?
|
75
|
-
if args_processed == args
|
76
|
-
puts "Unknown option(s*): #{scope.concat([args.first]).join(' ')}"
|
77
|
-
exit 1
|
78
|
-
end
|
79
|
-
args_processed = args.dup
|
80
|
-
|
81
|
-
option_str = args.shift
|
82
|
-
current_scope = scope + [option_str]
|
83
|
-
|
84
|
-
|
85
|
-
begin
|
86
|
-
options_class = load_relative_constant current_scope.join('/')
|
87
|
-
options_instance = options_class.new(options: options)
|
88
|
-
options[:option] = options_instance
|
89
|
-
options_instance.parse(args)
|
90
|
-
@commands << options_instance.command
|
91
|
-
|
92
|
-
scope << option_str
|
93
|
-
rescue LoadError => ex
|
94
|
-
puts "Unknown option: #{option_str}"
|
95
|
-
puts
|
96
|
-
puts options_instance.help_message
|
97
|
-
exit 1
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def help_message
|
103
|
-
option_parse.to_s
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def option_parser
|
109
|
-
OptionParser.new do |opts|
|
110
|
-
opts.banner = <<-TEXT.gsub(/^\s*\|/, '')
|
111
|
-
|Usage: #{opts.program_name} [option|command]
|
112
|
-
|
|
113
|
-
|When a command is omitted the yap shell starts an interactive
|
114
|
-
|session. Otherwise, the command is executed.
|
115
|
-
|
|
116
|
-
|Shell options:
|
117
|
-
TEXT
|
118
|
-
opts.on('-h', '--help', 'Prints this help') do
|
119
|
-
puts opts
|
120
|
-
commands = Dir[ File.dirname(__FILE__) + '/commands/*.rb' ].map do |path|
|
121
|
-
command = File.basename(path).sub(/\.rb$/, '')
|
122
|
-
"#{command}: #{Term::ANSIColor.cyan(opts.program_name + ' ' + command + ' --help')}"
|
123
|
-
end
|
124
|
-
commands = %| #{commands.join("\n ")}|
|
125
|
-
puts <<-TEXT.gsub(/^\s*\|/, '')
|
126
|
-
|
|
127
|
-
|Commands:
|
128
|
-
|
|
129
|
-
|#{commands}
|
130
|
-
|
|
131
|
-
TEXT
|
132
|
-
exit 0
|
133
|
-
end
|
134
|
-
|
135
|
-
opts.on('--skip-first-time', 'Disables creating ~/.yap directory on shell startup') do
|
136
|
-
Yap.configuration.skip_first_time = true
|
137
|
-
end
|
138
|
-
|
139
|
-
opts.on('--addon-paths=PATHS', 'Paths to directories containing addons (comma-separated). This overwrites the default addon paths.') do |paths|
|
140
|
-
Yap.configuration.addon_paths = paths.split(',').map(&:strip)
|
141
|
-
end
|
142
|
-
|
143
|
-
opts.on('--no-addons', 'Disables auto-loading addons on shell startup') do
|
144
|
-
Yap.configuration.use_addons = false
|
145
|
-
end
|
146
|
-
|
147
|
-
opts.on('--no-history', 'Disables auto-loading or saving history') do
|
148
|
-
Yap.configuration.use_history = false
|
149
|
-
end
|
150
|
-
|
151
|
-
opts.on('--rcfiles=PATHS', 'Paths to Yap rcfiles in the order they should load (comma-separated). This overwrites the default rcfiles.') do |paths|
|
152
|
-
Yap.configuration.rcfiles = paths.split(',').map(&:strip)
|
153
|
-
end
|
154
|
-
|
155
|
-
opts.on('--no-rcfiles', 'Disables auto-loading rcfiles on shell startup') do
|
156
|
-
Yap.configuration.use_rcfiles = false
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|