Class: R2do::Commands::InitCommand

Inherits:
R2do::Command show all
Defined in:
lib/r2do/commands/init_command.rb

Constant Summary collapse

YES =
"Y"

Instance Attribute Summary

Attributes inherited from R2do::Command

#description, #extended, #short

Instance Method Summary collapse

Methods inherited from R2do::Command

#to_s

Constructor Details

#initialize(state) ⇒ InitCommand

Returns a new instance of InitCommand.



23
24
25
26
27
# File 'lib/r2do/commands/init_command.rb', line 23

def initialize(state)
  super('i', 'init', 'Initializes a new clean session.')

  @state = state
end

Instance Method Details

#execute(args) ⇒ void

This method returns an undefined value.

Initializes the applications and resets the datafile

Parameters:

  • args (Array)

    the arguments passed to the app by the user



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/r2do/commands/init_command.rb', line 33

def execute(args)
  UI.status("Initialize new session?")
  UI.new_line()
  value = UI.input("Any previous session will be lost. Continue? [Yn]")
  if value == YES
    @state.reset()
    @state.modified = true
    UI.status("Initialized a new session of r2do.")
  else
    UI.status("Continuing with current session.")
  end
end

#helpObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/r2do/commands/init_command.rb', line 46

def help()
  help = <<-EOF
NAME
 r2do #{@extended}

SYNOPSIS
 'r2do #{@extended}' or 'r2do #{@short}' are equivalent

DESCRIPTION

The #{@extended} command initializes a new session of the application. Any previously saved data is permanently lost.

usage: r2do #{@extended}

  EOF
end