Sha256: 22c518caf434a0561b21b5dfddcccac8b4cb13faea363d50ae2e221c8b32572c

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module KStarter
  module Commands
    # Submenu for project
    class ProjectMenu < KStarter::Commands::Command
      def initialize(subcommand, options)
        @subcommand = (subcommand || '').to_sym

        @options = options
        super()
      end

      def execute(input: $stdin, output: $stdout)
        command = nil

        loop do
          case @subcommand
          when :new
            command = KStarter::Commands::SelectNewProjectType.new(:menu)
          when :edit
            command = KStarter::Commands::EditProject.new
          when :bootstrap
            command = KStarter::Commands::BootstrapProject.new
          end
          command&.execute(input: input, output: output) if command
          break if menu.nil?
        end
      end

      private

      def menu
        display_exiting_projects

        choices = [
          { name: 'New project settings', value: :new },
          { name: 'Edit project settings', value: :edit },
          { name: 'Bootstrap a project', value: :bootstrap }
        ]

        subcommand = prompt.select('Select your subcommand?', choices, per_page: 15, cycle: true)

        command = KStarter::Commands::ProjectMenu.new(subcommand, {})
        command.execute(input: @input, output: @output)
      rescue KStarter::EscapePressed
        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
k_starter-0.1.4 lib/k_starter/commands/project/project_menu.rb
k_starter-0.1.3 lib/k_starter/commands/project/project_menu.rb
k_starter-0.1.2 lib/k_starter/commands/project/project_menu.rb
k_starter-0.1.1 lib/k_starter/commands/project/project_menu.rb