Class: Tlog::Command::Create

Inherits:
Tlog::Command show all
Defined in:
lib/tlog/command/create.rb

Instance Attribute Summary

Attributes inherited from Tlog::Command

#date_time_format, #seconds_format, #storage

Instance Method Summary collapse

Instance Method Details

#execute(input, output) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/tlog/command/create.rb', line 8

def execute(input, output)
  raise Tlog::Error::CommandInvalid, "Must specify log name" unless input.args[0]

  log = Tlog::Entity::Log.new
  log.name = input.args[0];
  log.goal = ChronicDuration.parse(input.options[:goal]) if input.options[:goal]
  raise Tlog::Error::CommandNotFound, "Could create log: Log already exists" unless create_log(log)
end

#nameObject



4
5
6
# File 'lib/tlog/command/create.rb', line 4

def name
  "create"
end

#options(parser, options) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/tlog/command/create.rb', line 17

def options(parser, options)
  parser.banner = "usage: tlog create <log_name>"

  parser.on("-g", "--goal <goal_length>") do |goal|
    options[:goal] = goal
  end
end