Class: Harnex::Recipes

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/recipes.rb

Constant Summary collapse

RECIPES_DIR =
File.expand_path("../../../../recipes", __FILE__)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Recipes

Returns a new instance of Recipes.



23
24
25
# File 'lib/harnex/commands/recipes.rb', line 23

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.usageObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/harnex/commands/recipes.rb', line 7

def self.usage
  <<~TEXT
    Usage: harnex recipes [list|show <name>]

    Subcommands:
      list          List available recipes (default)
      show <name>   Print a recipe by name or number

    Examples:
      harnex recipes
      harnex recipes list
      harnex recipes show 01
      harnex recipes show fire_and_watch
  TEXT
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/harnex/commands/recipes.rb', line 27

def run
  subcommand = @argv.shift
  case subcommand
  when nil, "list"
    list_recipes
  when "show"
    show_recipe(@argv.first)
  when "-h", "--help"
    puts self.class.usage
    0
  else
    # Treat bare arg as show
    show_recipe(subcommand)
  end
end