Class: KStarter::Commands::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
TtyHelpers
Defined in:
lib/k_starter/commands/command.rb

Overview

Base command class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TtyHelpers

#command, #config, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Instance Attribute Details

#escape_pressedObject (readonly)

Returns the value of attribute escape_pressed.



14
15
16
# File 'lib/k_starter/commands/command.rb', line 14

def escape_pressed
  @escape_pressed
end

Instance Method Details

#ask_questions(form_type, form_variant = nil, **data) ⇒ Object



26
27
28
# File 'lib/k_starter/commands/command.rb', line 26

def ask_questions(form_type, form_variant = nil, **data)
  KStarter::Questions::AskQuestions.for(form_type, form_variant, **data)
end

#display_exiting_projectsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/k_starter/commands/command.rb', line 30

def display_exiting_projects
  columns = %w[Name Type Path Description]
  rows = App.project.project_list.map do |project|
    [
      project.name,
      project.type,
      project.variant,
      project.root_path,
      project.description
    ]
  end

  table = TTY::Table.new(columns, rows)
  puts table.render(:unicode)
  prompt.warn('-' * 100)
end

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


19
20
21
22
23
24
# File 'lib/k_starter/commands/command.rb', line 19

def execute(*)
  raise(
    NotImplementedError,
    "#{self.class}##{__method__} must be implemented"
  )
end

#select_projectObject



47
48
49
50
51
# File 'lib/k_starter/commands/command.rb', line 47

def select_project
  choices = App.project.project_list.map(&:name)
  name = prompt.select('Select a project?', choices, cycle: true)
  App.project.find_project(name)
end