Class: UpcGen::Shell
- Inherits:
-
Object
- Object
- UpcGen::Shell
- Defined in:
- lib/upc_gen/shell.rb
Constant Summary collapse
- BANNER =
<<~"MSG".freeze usage: #{$PROGRAM_NAME} <optional-number-string><optional-char> Prints a random UPC code If a number string is passed, the code before the check digit will end with those digits If the string of numbers is followed by a '.', the random code will start with those digits If the string of numbers is followed by a '-', a code will be found that ends with those digits, including check digit MSG
Class Method Summary collapse
- .gather_options(argv) ⇒ Object
-
.start(argv, out: $stdout, err: $stderr) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- .usage(err: $stderr) ⇒ Object
Class Method Details
.gather_options(argv) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/upc_gen/shell.rb', line 20 def self.(argv) = { show_version: false } OptionParser.new { |parser| parser. = BANNER parser.on("-v", "--version", "Show version") do |version| [:version] = version end }.parse! argv end |
.start(argv, out: $stdout, err: $stderr) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
35 36 37 38 39 40 41 |
# File 'lib/upc_gen/shell.rb', line 35 def self.start(argv, out: $stdout, err: $stderr) # rubocop:disable Lint/UnusedMethodArgument = (argv) out.puts "version: #{UpcGen::VERSION}" if .delete(:version) 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 |