Class: UpcGen::Shell
- Inherits:
-
Object
- Object
- UpcGen::Shell
- Defined in:
- lib/upc_gen/shell.rb
Constant Summary collapse
- BANNER =
"usage: \#{$0} <optional-number-string><optional-char>\n\nPrints a random UPC code\n\nIf a number string is passed, the code before the check digit will end with those digits\nIf the string of numbers is followed by a '.', the random code will start with those digits\nIf the string of numbers is followed by a '-', a code will be found that ends with those digits, including check digit\n"
Class Method Summary collapse
Class Method Details
.start(argv, out: STDOUT, err: STDERR) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/upc_gen/shell.rb', line 20 def self.start(argv, out: STDOUT, err: STDERR) = { show_version: false } OptionParser.new do |parser| parser. = BANNER parser.on("-v", "--version", "Show version") do |version| [:version] = version end end.parse! argv if .delete(:version) out.puts "version: #{UpcGen::VERSION}" end out.puts UpcGenerator.new(argv[0]).generate end |
.usage(err: STDERR) ⇒ Object
15 16 17 18 |
# File 'lib/upc_gen/shell.rb', line 15 def self.usage(err: STDERR) err.puts BANNER exit 1 end |