Class: Vimpack::Commands::Search

Inherits:
Command
  • Object
show all
Defined in:
lib/vimpack/commands/search.rb

Instance Attribute Summary

Attributes included from Utils::File

#bundle_path, #home_path, #pack_path, #script_path, #vim_path

Instance Method Summary collapse

Methods inherited from Command

#initialize, #initialize_environment, #initialize_global_options, run

Methods included from Utils::Process

#run_process!, #run_process_and_wait!, #run_process_or_die!, #wait_for_child, #within_dir

Methods included from Utils::Io

#die!, #exit_with_error!, #say, #scream

Methods included from Utils::Git

#add_submodule, #init_repo, #init_submodule, #remove_submodule, #replace_contents, #repo_add_dot, #repo_add_remote, #repo_clone, #repo_commit, #repo_exec, #repo_pull, #repo_push, #repo_remote?, #sanitize_commands, #update_submodule

Methods included from Utils::File

#create_link, #directory_exists?, #file_exists?, #make_dir, #move_path, #remove_directory, #remove_link, #setup_paths, #symlink_exists?, #template, #template_path

Constructor Details

This class inherits a constructor from Vimpack::Commands::Command

Instance Method Details

#initialize_commandsObject



12
13
14
15
# File 'lib/vimpack/commands/search.rb', line 12

def initialize_commands
  die!("search requires a single argument") unless (@commands.size == 1 || !@conditions.empty?)
  @pattern = @commands[0] if @commands.size >= 1
end

#initialize_optionsObject



5
6
7
8
9
10
# File 'lib/vimpack/commands/search.rb', line 5

def initialize_options
  @conditions = Vimpack::Models::Script::SCRIPT_TYPES.map.inject([]) do |conditions, script_type|
    conditions << script_type if @options[script_type.gsub(' ', '_').to_sym]
    conditions
  end
end

#runObject



17
18
19
20
21
# File 'lib/vimpack/commands/search.rb', line 17

def run
  scripts = Vimpack::Models::Script.search(@pattern, @conditions)
  return exit_with_error!('No scripts found!', 0) if scripts.empty?
  say_justified_script_names(scripts)
end