Class: Alvalaxia::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/alvalaxia/runner.rb

Constant Summary collapse

CONFIG_FILE =
File.expand_path('~/.alvalaxiarc')

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



11
12
13
14
15
16
17
# File 'lib/alvalaxia/runner.rb', line 11

def initialize
  @cmd = CmdParse::CommandParser.new(true, true)
  @cmd.program_name = 'alvalaxia'
  @cmd.program_version = VERSION

  generate_commands
end

Instance Method Details

#generate_commandsObject

create all the cli options



25
26
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
# File 'lib/alvalaxia/runner.rb', line 25

def generate_commands

  # creating the setup command
  setup = CmdParse::Command.new('setup', false)
  setup.short_desc = 'Creates the config file needed to place the events in a google calendar.'
  setup.description = 'This command creates the ~/.alvalaxiarc file with empty credentials. '
  setup.description << 'User needs to fill in the google calendar credentials.'

  setup.set_execution_block do
    if has_config_file?
      puts 'The config file already exists. If you need to change it, edit it ( ~/.alvalaxiarc )'
    else
      create_config_file
      puts 'Config file created at ~/.alvalaxiarc, edit it with your credentials.'
    end
  end

  # creating the run command
  run = CmdParse::Command.new('run', false)
  run.short_desc = 'Runs the program.'
  run.description = 'Gets the SCP home games and places them as events on a given google calendar.'
  
  run.set_execution_block do
    if has_config_file?
      main
    else
      puts 'You first need to run the "setup" option to generate a config file.'
    end
  end

  @cmd.add_command(setup)
  @cmd.add_command(run)
  @cmd.add_command(CmdParse::HelpCommand.new, true)
  @cmd.add_command(CmdParse::VersionCommand.new, false)
end

#startObject

start the cli args parsing



20
21
22
# File 'lib/alvalaxia/runner.rb', line 20

def start
  @cmd.parse
end