Sha256: bc563ba817dd07ec857555f998c18fffee2776c76b7ea6e9f2a2e431390bb6da

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 KB

Contents

#encoding: utf-8

require 'claide'
require 'colored'
require 'yaml'

# Don’t worry, this makes no sense, just an example
# command which modifies the file system.
class CoffeeMaker < CLAide::Command
  self.description = 'Make delicious coffee from the comfort of your terminal.'

  def self.options
    [
      ['--no-milk', 'Don’t add milk'],
      ['--sweetner=[sugar|honey]', 'Use one of the available sweetners'],
    ].concat(super)
  end

  def initialize(argv)
    @add_milk = argv.flag?('milk', true)
    @sweetner = argv.option('sweetner')
    @config_file = ENV['COFFEE_MAKER_FILE'] || 'Coffeemakerfile'
    super
  end

  def validate!
    super
    if @sweetner && !%w(sugar honey).include?(@sweetner)
      help! "'#{@sweetner}' is not a valid sweetner."
    end
  end

  def brew(recipe)
    File.open recipe+'.brewed-coffee', 'w' do |f|
      f.write "class #{recipe} < BrewedCoffee\n"
      if @add_milk
        f.write "  @milk = true\n"
      end
      if @sweetner
        f.write "  @sweetner = #{@sweetner}\n"
      end
    end
  end

  def run
    @config = YAML.load_file @config_file
    if @config['recipes'] == nil
      help! "Didn’t found any `recipes` in the Coffeemakerfile.yml."
    end
    @config['recipes'].each do |recipe|
      puts "* Brewing #{recipe}"
      brew(recipe)
    end
    puts '* Enjoy!'
  end
end

CoffeeMaker.run(ARGV)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
clintegracon-0.8.1 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.8.0 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.7.0 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.6.1 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.6.0 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.5.3 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.5.2 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.5.1 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.5.0 spec/fixtures/bin/coffeemaker.rb
clintegracon-0.4.1 spec/fixtures/bin/coffeemaker.rb