Module: SnippetCli::WizardHelpers::MatchFileSelector
- Includes:
- PromptHelpers
- Included in:
- Commands::Check, Commands::Conflict, Commands::Vars, NewWorkflow
- Defined in:
- lib/snippet_cli/wizard_helpers/match_file_selector.rb
Overview
Selects an Espanso match file for saving. Auto-selects when only one file exists; otherwise prompts via Gum.filter.
Instance Method Summary collapse
-
#pick_match_file ⇒ Object
Returns [basename, full_path] of the chosen match file.
Methods included from PromptHelpers
#collect_search_terms, #confirm!, #list_confirm!, #optional_prompt, #prompt!
Instance Method Details
#pick_match_file ⇒ Object
Returns [basename, full_path] of the chosen match file. Raises NoMatchFilesError when no files exist.
15 16 17 18 19 20 21 22 23 |
# File 'lib/snippet_cli/wizard_helpers/match_file_selector.rb', line 15 def pick_match_file files = EspansoConfig.match_files abort_no_match_files if files.empty? return [File.basename(files.first), files.first] if files.size == 1 basenames = files.map { |f| File.basename(f) } chosen = prompt!(Gum.filter(*basenames, header: 'Save to which match file?')) [chosen, files.find { |f| File.basename(f) == chosen }] end |