Class: KStarter::Commands::EditProject

Inherits:
Command
  • Object
show all
Defined in:
lib/k_starter/commands/project/edit_project.rb

Overview

Submenu for new

Instance Attribute Summary

Attributes inherited from Command

#escape_pressed

Instance Method Summary collapse

Methods inherited from Command

#ask_questions, #display_exiting_projects, #select_project

Methods included from TtyHelpers

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

Constructor Details

#initialize(**options) ⇒ EditProject

Returns a new instance of EditProject.



7
8
9
10
# File 'lib/k_starter/commands/project/edit_project.rb', line 7

def initialize(**options)
  @options = options
  super()
end

Instance Method Details

#edit_project(project) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/k_starter/commands/project/edit_project.rb', line 20

def edit_project(project)
  form_type = project.type.to_sym
  form_variant = project.variant&.to_sym

  questions = ask_questions(form_type, form_variant, **project.to_h)
  questions.ask_questions

  puts JSON.pretty_generate(questions.to_h)
  App.project.save_project(questions)
rescue KStarter::EscapePressed
  prompt.warn 'Exiting without saving'
end

#execute(input: $stdin, output: $stdout) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/k_starter/commands/project/edit_project.rb', line 12

def execute(input: $stdin, output: $stdout)
  display_exiting_projects
  project = select_project

  # Is the if project even relevant at the moment?
  edit_project(project) if project
end