File: speak

package info (click to toggle)
ruby-clamp 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 364 kB
  • sloc: ruby: 2,851; makefile: 4
file content (30 lines) | stat: -rwxr-xr-x 517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env ruby
# frozen_string_literal: true

# A simple Clamp command, with options and parameters

require "clamp"

Clamp do

  banner %(
    Say something.
  )

  option "--loud", :flag, "say it loud"
  option ["-n", "--iterations"], "N", "say it N times", default: 1 do |s|
    Integer(s)
  end

  parameter "WORDS ...", "the thing to say", attribute_name: :words

  def execute
    the_truth = words.join(" ")
    the_truth.upcase! if loud?

    iterations.times do
      puts the_truth
    end
  end

end