Class: TimeTally::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/time_tally/shell.rb

Constant Summary collapse

<<~"MSG".freeze
  usage: #{$PROGRAM_NAME}

  Takes copied data from the report screen of toggle and formats a total amount of time per task
MSG

Class Method Summary collapse

Class Method Details

.gather_options(argv) ⇒ Object

rubocop:disable Metrics/MethodLength



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/time_tally/shell.rb', line 26

def self.gather_options(argv) # rubocop:disable Metrics/MethodLength
  options = {
    show_version: false
  }

  OptionParser.new { |parser|
    parser.banner = BANNER

    parser.on("-v", "--version", "Show version") do |version|
      options[:show_version] = version
    end

    parser.on("-h", "--help", "Prints this help") do
      puts parser
      exit
    end
  }.parse! argv

  options
end

.run(argv, out: $stdout, err: $stderr) {|options| ... } ⇒ Object

Yields:

  • (options)


16
17
18
19
20
21
22
23
24
# File 'lib/time_tally/shell.rb', line 16

def self.run(argv, out: $stdout, err: $stderr)
  options = gather_options(argv)

  out.puts "version: #{TimeTally::VERSION}" if options.delete(:show_version)

  usage(err: err) unless argv.size == 0

  yield(options)
end

.usage(err: $stderr) ⇒ Object



11
12
13
14
# File 'lib/time_tally/shell.rb', line 11

def self.usage(err: $stderr)
  err.puts BANNER
  exit 1
end