Class: Tlog::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/tlog/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ Application

Returns a new instance of Application.



4
5
6
7
# File 'lib/tlog/application.rb', line 4

def initialize(input, output)
	@input = input
	@output = output
end

Instance Method Details

#all_commandsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tlog/application.rb', line 31

def all_commands
	storage = working_dir_storage
	commands = [
		Tlog::Command::Init.new,
		Tlog::Command::Start.new,
		Tlog::Command::Stop.new,
		Tlog::Command::Active.new,
		Tlog::Command::Delete.new,
		Tlog::Command::Display.new,
		Tlog::Command::Create.new,
	]
	commands.each do |command|
		command.storage = storage
		command.seconds_format = Tlog::Format::Seconds
		command.date_time_format = Tlog::Format::DateTime
	end
	return commands
end

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tlog/application.rb', line 9

def run
	command_name = ""
	outcome = false
	begin
		command_name = @input.args.shift
		command = find(command_name)
		prepare_command(command)
		outcome = run_command(command)
	rescue OptionParser::InvalidOption, OptionParser::MissingArgument
		@output.error($!)
		@output.error(@optparse.to_s)
	rescue Tlog::Error::CommandInvalid
		@output.error(command_name + " syntax invalid: " + $!.message)
		@output.error(@optparse.to_s)
	rescue Tlog::Error::CommandNotFound
		@output.error(command_name +": " + $!.message) # format class?
	rescue
		@output.error($!)
	end
	return outcome
end