Class: StarterGem::Shell
- Inherits:
-
Object
- Object
- StarterGem::Shell
- Defined in:
- lib/starter_gem/shell.rb
Constant Summary collapse
- BANNER =
<<~"MSG".freeze usage: #{$PROGRAM_NAME} color Simple demo that prints color in the color if it knows about the color MSG
Class Method Summary collapse
-
.gather_options(argv) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .run(argv, out: $stdout, err: $stderr) {|options| ... } ⇒ Object
- .usage(err: $stderr) ⇒ Object
Class Method Details
.gather_options(argv) ⇒ Object
rubocop:disable Metrics/MethodLength
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/starter_gem/shell.rb', line 28 def self.(argv) # rubocop:disable Metrics/MethodLength = { show_version: false } OptionParser.new { |parser| parser. = BANNER parser.on("-v", "--version", "Show version") do |version| [:show_version] = version end parser.on("-h", "--help", "Prints this help") do puts parser exit end }.parse! argv end |
.run(argv, out: $stdout, err: $stderr) {|options| ... } ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/starter_gem/shell.rb', line 16 def self.run(argv, out: $stdout, err: $stderr) = (argv) out.puts "version: #{StarterGem::VERSION}" if .delete(:show_version) usage(err: err) unless argv.size == 1 [:color] = argv[0] yield() end |
.usage(err: $stderr) ⇒ Object
11 12 13 14 |
# File 'lib/starter_gem/shell.rb', line 11 def self.usage(err: $stderr) err.puts BANNER exit 1 end |