Class: Tabry::OptionsFinder
- Inherits:
-
Object
- Object
- Tabry::OptionsFinder
- Defined in:
- lib/tabry/options_finder.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.options(result, token, params) ⇒ Object
Returns an array of options.
Instance Method Summary collapse
-
#initialize(result, params) ⇒ OptionsFinder
constructor
A new instance of OptionsFinder.
- #options(token) ⇒ Object
-
#summary_descriptions ⇒ Object
Descriptions of what is expected; particularly, argument names and descriptions returns an array, each can be one of three things: symbol :flag or :subcommand array [name, description] array [:flagarg, flag_description].
- #summary_descriptions_flagarg ⇒ Object
- #summary_descriptions_subcommand ⇒ Object
Constructor Details
#initialize(result, params) ⇒ OptionsFinder
Returns a new instance of OptionsFinder.
14 15 16 17 |
# File 'lib/tabry/options_finder.rb', line 14 def initialize(result, params) @result = result @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/tabry/options_finder.rb', line 7 def params @params end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/tabry/options_finder.rb', line 7 def result @result end |
Class Method Details
.options(result, token, params) ⇒ Object
Returns an array of options
10 11 12 |
# File 'lib/tabry/options_finder.rb', line 10 def self.(result, token, params) new(result, params).(token) end |
Instance Method Details
#options(token) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tabry/options_finder.rb', line 19 def (token) # Bit of a hack: send this down to autocomplete shell commands # TODO: set this only in ShellOption -- would require passing state down on thru before_env = ENV.fetch("TABRY_AUTOCOMPLETE_STATE", nil) ENV["TABRY_AUTOCOMPLETE_STATE"] = { cmd: result.config.cmd, flags: result.state.flags, args: result.state.args, current_token: token, current_flag: result.state.current_flag }.to_json send( { subcommand: :options_subcommand, flagarg: :options_flagarg }[state.mode], token || "" ) ensure ENV["TABRY_AUTOCOMPLETE_STATE"] = before_env end |
#summary_descriptions ⇒ Object
Descriptions of what is expected; particularly, argument names and descriptions returns an array, each can be one of three things:
symbol :flag or :subcommand
array [name, description]
array [:flagarg, flag_description]
44 45 46 47 48 49 |
# File 'lib/tabry/options_finder.rb', line 44 def summary_descriptions send({ subcommand: :summary_descriptions_subcommand, flagarg: :summary_descriptions_flagarg }[state.mode]) end |
#summary_descriptions_flagarg ⇒ Object
51 52 53 54 55 |
# File 'lib/tabry/options_finder.rb', line 51 def summary_descriptions_flagarg result.current_flags_for_flagargs.map do |flag| [:flagarg, flag.description] end.compact end |
#summary_descriptions_subcommand ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tabry/options_finder.rb', line 57 def summary_descriptions_subcommand descriptions = [] if result.expected_arg descriptions << [ result.expected_arg.title || result.expected_arg.name, result.expected_arg.description ] end descriptions << :subcommand if ("").any? descriptions << :flag if ("").any? descriptions end |