Class: AocCli::Interface::Args

Inherits:
Object
  • Object
show all
Defined in:
lib/aoc_cli/interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgs

Returns a new instance of Args.



24
25
26
# File 'lib/aoc_cli/interface.rb', line 24

def initialize
	@args = {}
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



23
24
25
# File 'lib/aoc_cli/interface.rb', line 23

def args
  @args
end

#cmdObject (readonly)

Returns the value of attribute cmd.



23
24
25
# File 'lib/aoc_cli/interface.rb', line 23

def cmd
  @cmd
end

Instance Method Details

#parseObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
67
68
69
70
71
72
73
74
75
76
# File 'lib/aoc_cli/interface.rb', line 27

def parse
	while ARGV.size > 0
		case ARGV.shift
		when "-a", "--attempts"
			@cmd = :AttemptsTable
		when "-B", "--browser"
			@cmd = :OpenReddit
			args[:browser] = true
		when "-c", "--simple-cal"
			@cmd = :CalendarTable
		when "-C", "--fancy-cal"
			@cmd = :PrintCal
		when "-d", "--init-day"
			@cmd = :DayInit
			args[:day]  = Validate.day(ARGV.shift.to_i)
		when "-D", "--day"
			args[:day]  = ARGV.shift.to_i
		when "-G", "--gen-config"
			@cmd = :GenerateConfig
		when "-h", "--help"
			exit Help.print
		when "-k", "--key"
			@cmd = :KeyStore
			args[:key]  = Validate.set_key(ARGV.shift)
		when "-p", "--part"
			args[:part] = ARGV.shift.to_i
		when "-r", "--refresh"
			@cmd = :Refresh
		when "-R", "--reddit"
			@cmd = :OpenReddit
		when "-s", "--solve"
			@cmd = :DaySolve
			args[:ans]  = ARGV.shift
		when "-S", "--stats"
			@cmd = :StatsTable
		when "-u", "--user"
			args[:user] = ARGV.shift
		when "-U", "--default"
			@cmd = :DefaultAlias
			args[:user] = ARGV.shift
		when "-y", "--init-year"
			@cmd = :YearInit
			args[:year] = Validate.year(ARGV.shift.to_i)
		when "-Y", "--year"
			args[:year] = ARGV.shift.to_i
		else raise Errors::FlagInv
		end 
	end
	self
end