Class: TabTab::Completions::External
- Inherits:
-
Object
- Object
- TabTab::Completions::External
- Defined in:
- lib/tabtab/completions/external.rb
Instance Attribute Summary collapse
-
#global_config ⇒ Object
readonly
Returns the value of attribute global_config.
Instance Method Summary collapse
-
#extract(_options_str = nil) ⇒ Object
Returns list of long and short options for an application’s –help display which was passed into initializer.
- #hide_short_flags? ⇒ Boolean
-
#initialize(app_name, options_flag = '-h', global_config = {}) ⇒ External
constructor
A new instance of External.
- #options_str ⇒ Object
-
#starts_with(prefix) ⇒ Object
Returns the sub-list of all options filtered by a common prefix e.g.
Constructor Details
#initialize(app_name, options_flag = '-h', global_config = {}) ⇒ External
Returns a new instance of External.
4 5 6 7 8 |
# File 'lib/tabtab/completions/external.rb', line 4 def initialize(app_name, = '-h', global_config = {}) @app_name = app_name @options_flag = @global_config = global_config end |
Instance Attribute Details
#global_config ⇒ Object (readonly)
Returns the value of attribute global_config.
2 3 4 |
# File 'lib/tabtab/completions/external.rb', line 2 def global_config @global_config end |
Instance Method Details
#extract(_options_str = nil) ⇒ Object
Returns list of long and short options for an application’s –help display which was passed into initializer
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tabtab/completions/external.rb', line 16 def extract( = nil) @options_str = if # hook for testing @extract ||= begin = .split(/\n/).grep(/^[\s\t]+-/) = .inject([]) do |list, line| list + line.scan(/(?:^\s+|,\s)(-[\w-]+)/).flatten end = .grep(/^--/).sort = hide_short_flags? ? [] : ( - ).sort + end end |
#hide_short_flags? ⇒ Boolean
36 37 38 |
# File 'lib/tabtab/completions/external.rb', line 36 def hide_short_flags? global_config[:shortflags] == 'disable' end |
#options_str ⇒ Object
10 11 12 |
# File 'lib/tabtab/completions/external.rb', line 10 def @options_str ||= `#{@app_name} #{@options_flag}` end |
#starts_with(prefix) ⇒ Object
Returns the sub-list of all options filtered by a common prefix e.g. if current extract
list is [‘–help’, ‘–extra’, ‘-h’, ‘-x’] then starts_with(‘–’) returns [‘–help’, ‘–extra’]
32 33 34 |
# File 'lib/tabtab/completions/external.rb', line 32 def starts_with(prefix) extract.grep(/^#{prefix}/) end |