Class: Worked::CLI
- Inherits:
-
Object
- Object
- Worked::CLI
- Defined in:
- lib/worked/cli.rb
Class Method Summary collapse
- .execute(stdout, arguments, file) ⇒ Object
- .graph(stdout, file, path) ⇒ Object
- .parse_options(stdout, arguments, file) ⇒ Object
- .try_to_parse(file, string) ⇒ Object
Class Method Details
.execute(stdout, arguments, file) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/worked/cli.rb', line 7 def self.execute(stdout, arguments, file) if arguments.empty? (stdout, ["--help"], file) end begin try_to_parse(file, arguments.join(" ")) rescue CannotParse = (stdout, arguments, file) if [:graph_path] graph(stdout, file, [:graph_path]) end end end |
.graph(stdout, file, path) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/worked/cli.rb', line 34 def self.graph stdout, file, path Graph::create_weekly(Reader::by_week(file.readlines), path) stdout.puts "Graph saved to #{path}." end |
.parse_options(stdout, arguments, file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/worked/cli.rb', line 41 def self.(stdout, arguments, file) = {} parser = OptionParser.new do |opts| opts. = <<-BANNER.gsub(/^ /,'') This application is wonderful! Usage: #{File.basename($0)} [options] #{File.basename($0)} work time specification Options are: BANNER opts.separator "" opts.on("-g", "--graph=PATH", String, "Prints a graph to the specified file.") { |arg| [:graph_path] = arg } opts.on("-h", "--help", "Show this help message.") { stdout.puts opts; exit } opts.parse!(arguments) end end |