Module: Potassium::CLI

Extended by:
GLI::App, CliOptions
Defined in:
lib/potassium/cli.rb,
lib/potassium/cli/commands/create.rb,
lib/potassium/cli/commands/install.rb

Constant Summary

Constants included from CliOptions

Potassium::CliOptions::CREATE_OPTIONS

Class Method Summary collapse

Methods included from CliOptions

create_arguments, create_options, option_names

Class Method Details

.find_closest_recipe(recipe_list, possible_recipe) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/potassium/cli/commands/install.rb', line 58

def self.find_closest_recipe(recipe_list, possible_recipe)
  return nil unless possible_recipe
  highest_distance = 100
  closest_match = nil
  recipe_list.each do |recipe|
    distance = Levenshtein.distance(recipe, possible_recipe)
    if distance < highest_distance
      highest_distance = distance
      closest_match = recipe
    end
  end
  closest_match
end

.guess_recipe_name(args) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/potassium/cli/commands/install.rb', line 34

def self.guess_recipe_name(args)
  if recipe_exists?(args)
    args.first
  else
    find_closest_recipe(recipe_name_list, args.first)
  end
end

.recipe_exists?(args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/potassium/cli/commands/install.rb', line 30

def self.recipe_exists?(args)
  recipe_name_list.include?(args.first)
end

.recipe_name_listObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/potassium/cli/commands/install.rb', line 42

def self.recipe_name_list
  list = []

  source_root = File.expand_path('../../../recipes', __FILE__)
  Dir.entries(source_root).each do |file_name|
    if file_name.end_with?('.rb')
      recipe_name = file_name.gsub('.rb', '')
      require "potassium/recipes/#{recipe_name}"
      recipe_class = Recipes.const_get(recipe_name.camelize)
      list << recipe_name if recipe_class.method_defined?(:install)
    end
  end

  list
end